Skip to main content
GraphRAG SDK follows a strategy-based pipeline architecture. Every algorithmic concern is an abstract base class (ABC) with swappable implementations. The system has three main flows: ingestion (document or table to knowledge graph), finalization (cross-document deduplication, embeddings and indexes), and retrieval (question to answer).

Design Principles

  • Strategy Modularity — Every pipeline step is an ABC. Swap any implementation without touching other code.
  • Zero-Loss Data — Full provenance chain from raw text to graph nodes (Document -> Chunk -> Entity).
  • Production Latency — Async-first, connection pooling, batched writes, parallel pipeline steps.
  • Simplicity — Single entry point (GraphRAG), flat package structure, no meta-programming.

Ingestion Pipeline

ingest() takes one of two paths, chosen by the source:
  • Prose (text, Markdown, PDF and any other file): the 9-step extraction pipeline below.
  • Tables (.csv, .tsv, .psv, .tab): the structured path, with no model in the write.
The prose pipeline transforms documents into a knowledge graph in 9 steps. Steps 1-7 run sequentially (each depends on the previous), steps 8-9 run in parallel.

Step-by-Step

After step 9 the Document’s content_hash is written, but only when every write completed. If an extraction failed or an edge write came up short, the hash is withheld and IngestionResult.metadata["incomplete_writes"] says why, so the next ingest repairs the document instead of skipping it.

Data Flow

Structured Ingestion

A table is declared on the ontology with a TableMapping and read by a RecordLoaderStrategy (CsvRecordLoader by default). Its path skips chunking, extraction and resolution:
  1. Map — find the table’s mapping in the ontology by filename (or propose one, with one model call for the whole table, when none is declared).
  2. Validate — check the mapping against the file’s header and every cell against its declared type, before any row is written. A changed mapping is registered first, so a property it no longer declares is already removed from the nodes when a MappingError is raised (see Structured Ingestion).
  3. Write — one Document named for the table, one record Chunk per row with a key (a row with a blank key is skipped and counted in rows_skipped), one entity per row (its id derived from its name, exactly as for a prose mention, or from its key when the row has no name; rows that derive the same id write one node), placeholders for foreign keys, and RELATES edges for each Link. Every declared property is signed with the table’s name (employees__age).
  4. Re-sync — a later load of the same table replaces it as a snapshot through the same crash-safe cutover update() uses.
A RelationshipMapping table takes a shorter path: each accepted row writes a RELATES edge between entities that already exist (rows naming the same two entities write one edge; a row whose endpoint is not found raises by default, or is counted and skipped with missing_endpoint="skip"), with no Document, record Chunk or entity; refresh it with ingest() and remove it with drop_table() (see Relationship-only tables). Because the id comes from the name, a row and a prose mention of the same thing are one node from the first write, whichever source arrives first. See Structured Ingestion.

Finalization

Ingest resolves duplicates only within one document; it never sees two documents at once. Cross-document deduplication happens in finalize(), called once after a batch of ingests:
  1. Remove legacy NULL-name stubs.
  2. Deduplicate, incrementally: only the pending entities (ingested since the last run, or left pending by it) are checked, against the whole graph through the __Entity__ vector index.
    • The exact phase groups them by (canonical name, label), so Person “Paris” and Location “Paris” remain separate. A group holding a table row merges by rule.
    • One rule does merge across types: when a name exists under exactly one custom label a table mapping declared and under labels nothing declared, the declared entity absorbs the others (an extracted Concept “Carbon Farming” joins the declared MitigationPractice), with no judge. It never applies to a built-in label such as Organization, which the extractor always had, nor to a name two rows of the declared label share.
    • Everything else goes to the judge, a pluggable DedupJudge (LLMJudge by default; every run has one), which partitions small candidate sets of nearest names.
    • Every merge is decided first, written as a sealed plan, and applied one atomic query per merge, so an interrupted run is finished by the next.
    • Then every entity whose description holds more than 5 pieces gets one LLM summary (FinalizeResult.descriptions_summarised).
  3. Embed RELATES facts.
  4. Ensure every index exists, waiting up to 10 minutes for builds to finish.
  5. Give unnamed chunks a readable name, "<document id> · chunk <index>" (table-row chunks and the <id>__pending__<hex> copy an unfinished update() is writing are skipped; finalize(name_chunks=False) turns it off; counted in FinalizeResult.chunks_named).
  6. Report findings (probable duplicates, property conflicts, proposed table mappings) at WARNING and on FinalizeResult.
Dedup bookkeeping lives in SDK system nodes (__GraphRAGProcessing__) beside the __GraphRAGConfig__ node, with no edges; get_statistics() does not count them. See Storage.

Graph Schema

The knowledge graph contains these node types and edge types:

Node Labels

The ontology itself is stored in a separate graph, <graph_name>__ontology.

Edge Types

All extracted and table relationships use the single RELATES edge type. The original relationship type (e.g. WORKS_AT, LOCATED_IN) is preserved as the rel_type property on the edge, and a fact property stores a human-readable fact string for embedding. An edge is identified by its source, rel_type and target, so two relationships of different types between the same pair of entities are two edges, while two facts of the same type in the same direction merge into one. The one exception is backfill_relation_pattern() (see Ontology Evolution): it writes edges typed with the relation label itself (for example [:WORKS_AT]), with a description but no fact, embedding or source_chunk_ids, so RELATES vector search and relationship expansion do not see them. MENTIONED_IN edges are what let retrieval trace an entity mentioned in an answer back to its source chunk — see Reducing LLM Hallucinations for how to surface that provenance trail and define an abstention path when it’s missing. Full property reference: Graph Schema.

Retrieval Flow

The retrieval system answers questions by searching the knowledge graph through multiple paths, then generating an answer with the LLM.

MultiPathRetrieval Parameters

GraphRAG passes every ontology change to its retrieval strategy (RetrievalStrategy.set_ontology()), so generated Cypher sees a new label or a table’s typed columns as soon as they exist. See Retrieval.

Storage Layer

GraphStore

All graph writes go through GraphStore, which provides:
  • Batched UNWIND upserts — 500 nodes/relationships per batch; writes in one batch that share a key are merged first, as if written one at a time
  • Range indexes on id — created for every label the write path touches, so a large ingest is not quadratic
  • Label hints — relationship MATCH queries use label hints (e.g., MENTIONED_IN matches __Entity__ -> Chunk) for faster lookups
  • Per-item fallback — if a batch fails, retries individual items
  • None-id guard — filters out entities with None/empty IDs (bad LLM extraction)

VectorStore

Vector operations go through VectorStore:
  • Index creation — vector indexes on Chunk, __Entity__ and RELATES edge embeddings, and fulltext indexes on chunk text and entity name and description; ensure_indices() waits up to 10 minutes for them to be built, then returns anyway
  • Batched embedding — embeds texts in bulk, stores via UNWIND
  • Search — similarity scores, higher is closer; chunk and entity searches break ties by id, and relationship search by endpoint ids, type and text, so results do not depend on the engine’s row order

Connection

Every query goes through FalkorDBConnection: pooled connections, retries with backoff for transient failures, a circuit breaker, and a server-version check (FalkorDB 4.20 or later) before the first query. See Configuration.

Extending the SDK

To add a custom strategy, subclass the relevant ABC:
Then pass it to ingest():
The same pattern applies to every strategy ABC: LoaderStrategy, RecordLoaderStrategy, ChunkingStrategy, ExtractionStrategy, ResolutionStrategy, RetrievalStrategy, RerankingStrategy and DedupJudge. See Strategies.

Deep Dives

Each subsystem has a dedicated document with step-by-step explanations: