Using FalkorGraphRagCapability with agents for GraphRAG Question & Answering
Using FalkorGraphRagCapability with agents for GraphRAG Question & Answering
AG2 provides GraphRAG integration using agent capabilities. This is an example to integrate FalkorDB (a Knowledge Graph database).
FalkorDB’s GraphRAG-SDK is a dependency for this notebook, which can be installed with ag2 via pip:
or if you have already installed ag2/autogen/pyautogen
For more information, please refer to the installation guide.
Set Configuration and OpenAI API Key
By default, in order to use FalkorDB you need to have an OpenAI key in
your environment variable OPENAI_API_KEY
.
You can utilise an OAI_CONFIG_LIST file and extract the OpenAI API key and put it in the environment, as will be shown in the following cell.
Alternatively, you can load the environment variable yourself.
Learn more about configuring LLMs for agents here.
Create a Knowledge Graph with Your Own Data
Note: You need to have a FalkorDB graph database running. If you are running one in a Docker container, please ensure your Docker network is setup to allow access to it.
In this example, the FalkorDB endpoint is set to host=“172.18.0.3” and port=6379, please adjust accordingly. For how to set up FalkorDB, please refer to https://docs.falkordb.com/
Below, we have some sample data from IMDB on the movie ‘The Matrix’. See the contents of the file here.
We then initialise the database with that text document, creating the graph in FalkorDB.
A Simple Example
In this example, the graph ontology is auto-generated. This allows you to load data without specifying the specific types of entities and relationships that will make up the database (however, this may not be optimal and not cost efficient).
Revisit the example with self defined graph ontology
If you want to be more specific on the entities and attributes in the
graph database you can create an Ontology
before loading your data, in
the case below we define these entities (Actor
with name
and Movie
with title
) and relationships (Actors ACTED
in Movies). This allows
the RAG agent to answer questions about actors in the movie.
Add capability to a ConversableAgent and query them
With FalkorDB setup with an ontology and data, we can now associate the GraphRAG capability with a ConversableAgent and have a chat with it.
From the output we can see that: - We can ask about actors and movies because we defined the ontology (and they were also automatically created in the prior example) - There is inbuilt awareness of answers it has provided previously - It can’t answer any questions outside of the actors and movies entities as we didn’t include anything else in the ontology