1. Prerequisites
- Python 3.10+
- FalkorDB (easiest via Docker — see below)
- An LLM API key from one of the supported providers:
- Azure OpenAI
- OpenAI
- Anthropic
2. Installation
Install the SDK with all optional dependencies:3. Start FalkorDB
Run FalkorDB as a Docker container:4. Configure Environment
Set the environment variables for your LLM provider. The example below uses Azure OpenAI:.env file, load it yourself before importing the SDK (e.g., via python-dotenv or export commands). The SDK reads environment variables but does not auto-load .env files.
5. Define a Schema
AGraphSchema tells the extraction pipeline which entity and relationship types to look for in your documents.
6. Initialize GraphRAG
Create aGraphRAG instance by providing a connection, LLM, embedder, and schema:
256 (matched-Matryoshka dimensions of text-embedding-3-large). If your embedding model produces a different dimensionality (e.g., 1024, 1536, or 3072), set embedding_dimension accordingly.
ConnectionConfig accepts additional parameters such as port, username, password, and query_timeout_ms. See Configuration for the full list.
Alternative providers: The SDK also exportsOpenRouterLLMandOpenRouterEmbedderfor use with OpenRouter. See Configuration for details.
7. Ingest a Document
From a file path
From raw text
8. Query the Knowledge Graph
Retrieve context only
Useretrieve() when you want to inspect the context or use your own LLM:
Generate an answer
Usecompletion() for the full RAG pipeline — retrieval + answer generation:
With context inspection
Passreturn_context=True to see which chunks and entities the retriever used to build the answer:
Multi-turn conversations
completion() supports native multi-turn conversations. Messages are passed directly to the LLM’s chat API as structured messages:
"system", "user", "assistant". Invalid roles raise ValueError.
9. Inspect Graph Contents
Useget_statistics() to see a summary of what the graph contains:
10. Finalize
After all documents have been ingested, runfinalize() to deduplicate entities, backfill embeddings, and create indexes:
11. Next Steps
- Configuration — Tuning connection settings, chunking parameters, and retrieval options.
- Strategies — Custom extraction and resolution strategies.
- Benchmark — Reproducing benchmark results on the GraphRAG-Bench Novel corpus (20 novels, 2,010 questions).
Synchronous API
If you are not in an async context, use the synchronous convenience methods:asyncio.run() and are useful for scripts and notebooks.