run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
33.3k stars 4.66k forks source link

[Feature Request]: Integrate graph databases as LlamaIndex Graph Stores #12517

Open ztor2 opened 3 months ago

ztor2 commented 3 months ago

Feature Description

Our company developed and is a main contributor to 'Apache AGE', an open source graph database based on PostgreSQL. We would like to make our graph database available as a Graph Store in LlamaIndex's RAG framework. Apache AGE is available as an extension to PostgreSQL and can be integrated into the Graph RAG framework as a Graph Store, storing and retrieving graph data based on OpenCypher.

We've already read the provided 'Contribution Guideline', but we didn't find any clear integration guidelines for the Graph Store. If you can provide more detailed guidelines for the integration, we'd be happy to provide more detailed information and test results in line with those guidelines.

Reason

LlamaIndex has a few different kinds of Graph Stores, but most appear to be native (or single-model) graph database products. Also, some Graph Stores are commercial products, which makes them inaccessible to the average user.

Value of Feature

Apache AGE is an extension to PostgreSQL, which means that it can be integrated with many other PostgreSQL extensions while still using a traditional RDB. It's also an open source graph database, making it easy to use for the average user. As the structure of LLM applications grows more complex, modules that are highly interoperable and extensible are becoming more favorable to use. Apache AGE is a product that fits this trend because it is based on PostgreSQL, has excellent integration and scalability, and has a large community. Apache AGE is also a validated project that has been named a Top-Level Project (TLP) by the Apache Software Foundation.

dosubot[bot] commented 3 months ago

Hey there, @ztor2! Long time no type 😄 Great to see your innovative ideas popping up here again. How've you been?

Thank you for your interest in integrating Apache AGE into the LlamaIndex's RAG framework. Your suggestion to include Apache AGE as a Graph Store is indeed valuable, and it could certainly enhance the capabilities of LlamaIndex.

To integrate Apache AGE as a Graph Store, you would need to create a new class for Apache AGE similar to the existing graph store classes. Here's a step-by-step guide:

  1. Create a New Graph Store Class for Apache AGE: You'll need to create a new Python class for Apache AGE. This class should inherit from the GraphStore protocol defined in the types.py file of the graph_stores module.

  2. Implement Required Methods: Implement all the necessary methods that allow the new class to interact with Apache AGE. This typically includes methods for connecting to the database, executing queries, and possibly translating between the graph model used by Apache AGE and the model expected by LlamaIndex.

  3. Register the New Graph Store: Once the new class is created and tested, you need to register it in the __init__.py file of the graph_stores module, similar to how other graph stores are registered.

Here's an example of how you might start this process:

# In file: llama_index/core/graph_stores/apache_age.py

from llama_index.core.graph_stores.types import GraphStore  # Assuming there's a base class

class ApacheAGEGraphStore(GraphStore):
    def __init__(self, connection_params):
        # Initialize connection to Apache AGE
        pass

    def query(self, query_text):
        # Method to execute a query against Apache AGE
        pass

    # Implement other required methods...

Then, register your new ApacheAGEGraphStore in the __init__.py file:

# Modify the existing __init__.py file to include the ApacheAGEGraphStore

from llama_index.core.graph_stores.apache_age import ApacheAGEGraphStore

__all__ = [
    "SimpleGraphStore",
    "NebulaGraphStore",
    "KuzuGraphStore",
    "Neo4jGraphStore",
    "FalkorDBGraphStore",
    "ApacheAGEGraphStore",  # Add this line
]

Note: This is a simplified example. The actual implementation will depend on the specific methods and interfaces required by LlamaIndex and the capabilities of Apache AGE. You'll need to refer to the documentation for both LlamaIndex and Apache AGE to correctly implement all necessary functionality.

For more details, you can refer to the types.py file in the graph_stores module of the LlamaIndex codebase, which outlines the interface for a graph store. The key components of this interface include methods for querying, updating, deleting, and persisting graph data. You can find the file here.

I hope this helps! If you have any further questions or need more clarification, feel free to ask.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.