GraphRAG SDK
The most accurate Graph RAG framework. Built on FalkorDB.
GraphRAG SDK builds knowledge graphs from documents and answers questions over them using retrieval-augmented generation. Every algorithmic concern (chunking, extraction, resolution, retrieval, reranking) is a swappable strategy behind an abstract interface. The default pipeline scores ~85% accuracy on a 100-question benchmark using GPT-4.1.
It is designed to reduce LLM hallucinations: answers are grounded in context retrieved from the knowledge graph and remain traceable to their source chunks via MENTIONED_IN provenance edges, and your application can abstain when the graph holds no supporting evidence. See the Reducing LLM Hallucinations guide.
Quick Start
import asyncio
from graphrag_sdk import GraphRAG, ConnectionConfig, LiteLLM, LiteLLMEmbedder
async def main():
async with GraphRAG(
connection=ConnectionConfig(host="localhost", graph_name="my_graph"),
llm=LiteLLM(model="openai/gpt-4o"),
embedder=LiteLLMEmbedder(model="openai/text-embedding-3-small"),
) as rag:
result = await rag.ingest("my_document.txt")
print(f"Created {result.nodes_created} nodes, {result.relationships_created} edges")
answer = await rag.completion("What is the main theme?")
print(answer.answer)
asyncio.run(main())
Installation
pip install graphrag-sdk[litellm] # OpenAI, Azure, Anthropic, 100+ models
pip install graphrag-sdk[openrouter] # OpenRouter models
pip install graphrag-sdk[pdf] # PDF ingestion
pip install graphrag-sdk[all] # Everything
Prerequisites
- Python >= 3.10
- FalkorDB server 4.20 or later:
docker run -p 6379:6379 falkordb/falkordb:v4.22.2(an older server is refused withFalkorDBVersionError) - An LLM API key (OpenAI, Azure OpenAI, OpenRouter, etc.)
Usage
Ingest & Query
import asyncio
from graphrag_sdk import GraphRAG, ConnectionConfig, LiteLLM, LiteLLMEmbedder
async def main():
async with GraphRAG(
connection=ConnectionConfig(host="localhost", graph_name="my_graph"),
llm=LiteLLM(model="openai/gpt-4o"),
embedder=LiteLLMEmbedder(model="openai/text-embedding-3-small"),
) as rag:
await rag.ingest("report.pdf") # PDF
await rag.ingest("source_id", text="Alice works at Acme.") # Raw text
await rag.finalize() # Dedup + index
# Retrieve context only
context = await rag.retrieve("Where does Alice work?")
# Full RAG: retrieve + generate answer
result = await rag.completion("Where does Alice work?")
print(result.answer)
asyncio.run(main())
Multi-Turn Conversations
completion() supports multi-turn conversations. With the built-in providers (LiteLLM, OpenRouterLLM), messages are passed natively to the LLM's chat API. Custom providers that only implement invoke() get automatic fallback via message concatenation.
from graphrag_sdk import ChatMessage
answer = await rag.completion(
"What happened next?",
history=[
ChatMessage(role="user", content="Who is Alice?"),
ChatMessage(role="assistant", content="Alice is an engineer at Acme Corp."),
],
)
Supported roles: "system", "user", "assistant". Invalid roles raise ValueError.
Schema Definition
from graphrag_sdk import GraphSchema, EntityType, RelationType
schema = GraphSchema(
entities=[
EntityType(label="Person", description="A human being"),
EntityType(label="Organization", description="A company or institution"),
],
relations=[
RelationType(
label="WORKS_AT",
description="Is employed by",
patterns=[("Person", "Organization")],
),
],
)
rag = GraphRAG(connection=conn, llm=llm, embedder=embedder, schema=schema) # conn, llm, embedder from above
Strategy Customization
Override any pipeline step by passing a strategy:
from graphrag_sdk.ingestion.chunking_strategies.fixed_size import FixedSizeChunking
from graphrag_sdk import GraphExtraction, LLMExtractor
# Custom chunking
await rag.ingest("doc.txt", chunker=FixedSizeChunking(chunk_size=1500, chunk_overlap=200))
# LLM-based entity extraction instead of GLiNER
await rag.ingest("doc.txt", extractor=GraphExtraction(llm=llm, entity_extractor=LLMExtractor(llm)))
Strategy Reference
Every algorithmic concern is a swappable strategy behind an abstract base class:
| Concern | ABC | Built-in Options | Default |
|---|---|---|---|
| Loading | LoaderStrategy |
TextLoader, PdfLoader |
Auto-detect by extension |
| Chunking | ChunkingStrategy |
FixedSizeChunking, SentenceTokenCapChunking, ContextualChunking, CallableChunking |
FixedSizeChunking |
| Extraction | ExtractionStrategy |
GraphExtraction (GLiNER2 + LLM) |
GraphExtraction |
| Resolution | ResolutionStrategy |
ExactMatchResolution, LLMVerifiedResolution |
ExactMatch at ingest; incremental judged cross-document dedup in finalize() (LLMVerifiedResolution opt-in) |
| Retrieval | RetrievalStrategy |
LocalRetrieval, MultiPathRetrieval |
MultiPath (5-path) |
| Reranking | RerankingStrategy |
CosineReranker |
Cosine |
| Dedup judging | DedupJudge |
LLMJudge |
LLMJudge with the GraphRAG LLM, in finalize() |
LLM & Embedding Providers
| Provider | LLM Class | Embedder Class | Models |
|---|---|---|---|
| LiteLLM | LiteLLM |
LiteLLMEmbedder |
OpenAI, Azure, Anthropic, Cohere, 100+ |
| OpenRouter | OpenRouterLLM |
OpenRouterEmbedder |
All OpenRouter models |
| Custom | Subclass LLMInterface |
Subclass Embedder |
Anything |
Benchmark
#1 on GraphRAG-Bench Novel — 66.09 ACC, ahead of AutoPrunedRetriever (63.72), MS-GraphRAG (50.93) and LightRAG (45.09).
| Metric | Value |
|---|---|
| Novel ACC | 66.09 (#1) |
| Fact retrieval | 65.49 |
| Complex reasoning | 59.26 |
| Contextual summarization | 75.42 |
| Creative generation | 64.21 |
| Questions | 2,010 across 20 novels |
| Medical ACC | 76.87 (#1) |
See the benchmark page for methodology and reproduction.
Examples
| # | Example | Description |
|---|---|---|
| 1 | 01_quickstart.py |
Minimal ingest & query |
| 2 | 02_pdf_with_schema.py |
PDF with custom schema |
| 3 | 03_custom_strategies.py |
Composing ingestion strategies explicitly |
| 4 | 04_custom_provider.py |
Custom LLM/Embedder |
| 5 | 05_notebook_demo.ipynb |
Interactive notebook walkthrough |
| ★ | grounded_answers_with_abstention.py |
Cited answers, and abstention when evidence is insufficient |
Documentation
Full documentation: https://docs.falkordb.com/graphrag
- Getting Started -- Install to first query
- Architecture -- Pipeline design and graph schema
- Reducing LLM Hallucinations -- Grounded retrieval, provenance, and abstention
- Configuration -- Connection and provider reference
- Strategies -- All ABCs and built-in implementations
- Providers -- LLM & embedder configuration
- Reliability and Grounding -- Grounding and abstention mapped to the APIs that implement them
- Benchmark -- Methodology and reproduction
- Accuracy Benchmark: FalkorDB vs Vector RAG -- 71.48 vs 55.39, limitations, how to cite
- API Reference -- Full API documentation
License
Metadata
Release files for graphrag-sdk 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphrag_sdk-1.6.0.tar.gz | 1.1 MB | With provenance | Details for graphrag_sdk-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphrag_sdk-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for graphrag_sdk-1.6.0-py3-none-any.whl |
Total release size: 1.7 MB
Release files / graphrag_sdk-1.6.0.tar.gz
| Download URL | graphrag_sdk-1.6.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0836dcc3ba181b79e6247c218d94b8044562e394f2ba76cf22b3cc8ddbcfd424
|
|
BLAKE2b-256 checksum How to use checksums |
7578c4bf8cc7fbb734af5e8f8a5bcca686cb2e39df479fb8959684ae755544a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / graphrag_sdk-1.6.0-py3-none-any.whl
| Download URL | graphrag_sdk-1.6.0-py3-none-any.whl |
|---|---|
| Size | 616.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2699210a9968884e132743bdc2b3cf3cd0a98dde5a26446ed80d1e695fffa55c
|
|
BLAKE2b-256 checksum How to use checksums |
3d81a6bf48bb53d8a60008d46765268b03aea9e354c50c4a04ae0a72f6b082ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for graphrag-sdk 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for graphrag_sdk-1.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.