FalkorDB’s GraphRAG-SDK is a dependency for this notebook, which can be installed with ag2 via pip:
Note: If you have been usingFor more information, please refer to the installation guide.autogen
orag2
, all you need to do is upgrade it using:orasautogen
, andag2
are aliases for the same PyPI package.
Set Configuration and OpenAI API Key
By default, in order to use FalkorDB you need to have an OpenAI key in your environment variableOPENAI_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 anOntology
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.