Skip to main content

GraphRAG SDK

The most accurate Graph RAG framework. Built on FalkorDB.

Python 3.10+ License: Apache 2.0 Version: 1.7.0 Tests: 3000+

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", dimensions=256),
    ) as rag:
        result = await rag.ingest("my_document.txt")
        print(f"Created {result.nodes_created} nodes, {result.relationships_created} edges")
        await rag.finalize()  # dedup, embeddings and indexes, before querying

        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]           # Common providers, PDF and the MCP server

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 with FalkorDBVersionError)
  • 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", dimensions=256),
    ) as rag:
        await rag.ingest("report.pdf")                              # PDF
        await rag.ingest(text="Alice works at Acme.", document_id="source_id")  # 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.

Ontology Definition

from graphrag_sdk import ConnectionConfig, GraphRAG, LiteLLM, LiteLLMEmbedder, Ontology, Entity, Relation

ontology = Ontology(
    entities=[
        Entity(label="Person", description="A human being"),
        Entity(label="Organization", description="A company or institution"),
    ],
    relations=[
        Relation(
            label="WORKS_AT",
            description="Is employed by",
            patterns=[("Person", "Organization")],
        ),
    ],
)

conn = ConnectionConfig(host="localhost", graph_name="my_graph")
llm = LiteLLM(model="openai/gpt-4o")
embedder = LiteLLMEmbedder(model="openai/text-embedding-3-small", dimensions=256)
rag = GraphRAG(connection=conn, llm=llm, embedder=embedder, ontology=ontology)

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, MarkdownLoader Auto-detect by extension
Chunking ChunkingStrategy FixedSizeChunking, SentenceTokenCapChunking, ContextualChunking, CallableChunking SentenceTokenCapChunking (384 tokens)
Extraction ExtractionStrategy GraphExtraction (GLiNER + 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

License

Apache License 2.0

Metadata

Release files for graphrag-sdk 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphrag-sdk 1.7.0
File Size Uploaded Provenance Actions
graphrag_sdk-1.7.0.tar.gz 1.1 MB With provenance Details for graphrag_sdk-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graphrag-sdk 1.7.0
File Interpreter ABI Platform Actions
graphrag_sdk-1.7.0-py3-none-any.whl Python 3 none any Details for graphrag_sdk-1.7.0-py3-none-any.whl

Total release size: 1.8 MB

Release files / graphrag_sdk-1.7.0.tar.gz

Download URL graphrag_sdk-1.7.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
32dc36d76e3ada4b404f9f1d10bc95f76fe49455e3adc8d2eb11525c568e3c51
BLAKE2b-256 checksum
How to use checksums
da2bd0e0b9b27932d5fb337f44e704f4560e6edb21357f4005b77f49fd1de5f6
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 23, 2026.

Transparency log

Release files / graphrag_sdk-1.7.0-py3-none-any.whl

Download URL graphrag_sdk-1.7.0-py3-none-any.whl
Size 655.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1be5b52f8e3c230fc1e4c7be71ab55a6e3f728439f2e297a2d29abb3305e6246
BLAKE2b-256 checksum
How to use checksums
953f6048d47c037a6d684e42b41b54489b456ba99497e5da2aabc86f2029912d
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 23, 2026.

Transparency log

Security for graphrag-sdk 1.7.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.

Select from 2 files

Attestation for graphrag_sdk-1.7.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 23, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page