GraphRAG Explained: Principles and Practice of Graph-Enhanced Retrieval-Augmented Generation

    This article explains why plain vector retrieval falls short for questions that span an entire document, and how GraphRAG addresses the gap. It breaks down the two retrieval modes—local and global—then walks through the full local retrieval pipeline, the key designs behind global retrieval, and the engineering concerns that matter in production: cost control, incremental updates, storage choices, observability, evaluation, and security. It closes with common pitfalls and the practices that help avoid them.

    1. Why Vector Retrieval Alone Is Not Enough

    Retrieval-augmented generation has become the standard approach in enterprise knowledge bases, long-document question answering, and regulatory or research-report analysis. The typical flow is to chunk documents, embed them, retrieve a handful of similar passages when a user asks a question, and hand those passages to a large language model to summarize. This works well for factual, localized questions, but the weaknesses show up as soon as a question spans the whole document.

    The core tension comes down to two points. First, vector similarity reflects semantic closeness, not structural relationships. Asking “what is this character’s personality like” requires aggregating descriptions scattered across different chapters; asking “what is the central conflict of the whole text” requires first summarizing the entire document and then reasoning over that summary. Second, chunking severs coreference and causal chains, leaving retrieved passages isolated from one another, so the model can only stitch them together superficially and cannot perform multi-hop reasoning.

    The idea behind GraphRAG is this: first use an LLM to extract entities and relationships from the corpus, build a knowledge graph, and generate hierarchical summaries on top of community detection. At retrieval time, instead of querying only passages, you pull context along multiple paths—entity, relationship, community summary, and source text. This preserves traceability to the original text while also providing a global view.

    2. How the Two Retrieval Modes Divide the Work

    Local Retrieval: Answering “Point” Questions

    Local retrieval targets a single object or a narrow topic, such as a particular character, event, or clause. Its defining trait is that the information needed for the answer is sparsely distributed in the corpus but clearly directed, so the retrieval strategy emphasizes “locate the anchor first, then expand outward.”

    Global Retrieval: Answering “Surface” Questions

    Global retrieval targets questions that require reading the whole document, such as topic summarization, central conflicts, overall trends, and cross-chapter comparison. The key here is not finding similar passages but using the precomputed community-level summaries: aggregate bottom-up, then distribute attention top-down, so the full picture is covered within a limited context budget.

    The two modes are not mutually exclusive. A common practice is to first classify the question type and pick a mode, or to narrow the scope with global summaries first and then fill in detailed evidence with local retrieval.

    3. Breaking Down the Full Local Retrieval Pipeline

    Local retrieval can be summarized as “one vector lookup + four expansion paths + one generation step.”

    Step 1: Vectorize the query. Encode the user’s question into a dense vector used to match against the description vectors of entities in the graph.

    Step 2: Retrieve entities. Similarity search returns a candidate entity set. A recall limit is usually set, and an oversampling factor is introduced to widen the candidate pool, followed by filtering via a name whitelist or blacklist to avoid same-name ambiguity and noisy entities.

    The illustrative code below expresses the skeleton of the recall logic rather than any specific interface:

    1. def map_query_to_entities(query, embedder, entity_store, k=10, oversample=2):
    2. q_vec = embedder.encode(query)
    3. candidates = entity_store.search(q_vec, top_k=k * oversample)
    4. return [c for c in candidates if not c.is_noise][:k]

    Step 3: Pull in conversation history. In multi-turn dialogue, coreference resolution depends on context, so recent question-answer pairs need to be included to correctly bind expressions like “he” or “that clause.”

    Step 4: Expand to community reports along entities. Entities belong to communities at different levels, and a community report is a summarizing description of that topic cluster. It offers a meso-level view and compensates for the fragmentation of individual entity descriptions.

    Step 5: Expand relationships and claims. Relationship edges provide the connective semantics between entities, while claim-type information carries assertions with subject, object, and time attributes. Together they support multi-hop reasoning and fact verification.

    Step 6: Retrieve the original text passages. All expansion results must ultimately map back to the original text chunks—both to give the model details and to provide citable sources for the answer.

    The core of the generation stage is not “stuffing in as much material as possible” but structured assembly: arrange content in the order “global overview → community summaries → relationships and claims → source-text evidence,” clearly label the source level, and instruct the model in the prompt to distinguish “evidence-backed conclusions” from “speculation.” When the context budget is limited, set quotas for each path—for example, source-text passages should be fewest in number but highest in priority, while community reports can be compressed moderately.

    4. Key Design Choices for Global Retrieval

    The feasibility of global retrieval depends entirely on the quality of the offline indexing stage. Index construction typically includes document chunking, entity and relationship extraction, merging of entity descriptions, community detection, and community report generation. Community detection determines the granularity of summaries: too shallow loses detail, while too deep raises the cost of aggregation.

    A common online approach is hierarchical traversal: start from high-level community summaries to judge relevance, drill down layer by layer to finer granularity, and finally supplement evidence with local retrieval at the leaf level. To make an answer cover multiple facets of a topic, you can generate several variant queries for the same question, retrieve for each, then merge and deduplicate, selecting context by “coverage” rather than “similarity.”

    5. Engineering Implementation Notes

    • Cost control: The extraction and summarization stages involve heavy call volume. A tiered strategy can use a small model for extraction and a large model for summarization, and incremental documents can undergo partial rather than full rebuilding.
    • Incremental updates: After a document changes, the affected entities, communities, and summaries must be recomputed. It is advisable to record dependencies with the document as the smallest invalidation unit.
    • Storage choices: Vector retrieval, graph structure storage, and source text with metadata can live in a vector database, a graph database, and object storage respectively, linked through a unified identifier.
    • Observability: Log retrieved entities, matched communities, context quotas, and citation sources so you can pinpoint whether an inaccurate answer is a retrieval problem or a generation problem.
    • Evaluation: Build separate evaluation sets for local factual questions and global summarization questions, focusing on citation accuracy, coverage, and the reasonableness of refusals, and avoid letting a single metric mask a mode mismatch.
    • Security and compliance: The graph may accumulate sensitive entities, so permission filtering and redaction must be applied consistently on both the indexing and retrieval sides.

    6. Common Pitfalls

    The first is treating the graph as the sole source of truth while neglecting source-text retrieval, which leaves answers unverifiable. The second is designing community summary levels carelessly, producing vague answers to global questions. The third is having no quota management for context, letting long material crowd out key evidence. The fourth is ignoring incremental maintenance, leaving answers stale after the corpus is updated. The key to avoiding these problems is to treat “traceable to the source text” as a hard constraint and to move retrieval-quality evaluation forward into the index design stage.