Graph-Based Retrieval-Augmented Generation: Local and Global Search Mechanisms Explained
This article breaks down how graph-based retrieval-augmented generation (RAG) handles both local and global questions. It explains why conventional vector retrieval struggles with full-corpus coverage and traceable reasoning, then details the six-step local search pipeline for entity-anchored evidence assembly and the layered community-summary approach used for global search. Readers will learn how to choose between the two modes and which optimization practices improve retrieval quality and latency.
1. Why Traditional Retrieval-Augmented Generation Falls Short
For question answering over long documents, multiple documents, or cross-source corpora, the common approach is to split the text into chunks, vectorize them, retrieve a few segments by similarity, and let a large language model summarize the results. This pipeline works well for point questions, but it has two structural weaknesses.
First, it lacks a global view. When a question targets “the narrative arc of an entire work,” “the overall risk distribution of a contract,” or “the core module breakdown of a codebase,” the answer does not live in any single chunk. It is spread across the relationships between many chunks. Similarity retrieval can only pull back local pieces by nature and cannot cover the whole.
Second, it lacks an explainable reasoning chain. The returned chunks are isolated from one another, so the model has to stitch causality together on its own. This easily leads to mismatched attributions and makes it hard to explain to users where a conclusion came from.
The core idea of graph-based retrieval-augmented generation is to extract entities, relationships, claims, and community summaries in addition to chunking and vectorization, building a traversable layer of structured index. At retrieval time, the system no longer relies only on “how similar the text is.” Instead, it first locates the object and then expands evidence along the structure, balancing local precision with global summarization.
2. Two Distinct Retrieval-Generation Modes
The approach splits question answering into two categories. The deciding factor is the coverage scope of the answer, not the wording of the question.
- Local retrieval-generation: answers questions about one specific object in the dataset, such as a character’s personality traits, the responsibility of an API, or a supplier’s delivery performance. These questions close the loop by aggregating the entity attributes, relationship edges, and original sources tied to that object.
- Global retrieval-generation: answers questions that require reading the full dataset to generalize, such as the central conflict of a work, the overall technical debt distribution of a project, or the main sentiment trend of a year. These questions rely on a pre-built community summary system and form answers through hierarchical aggregation rather than chunk-by-chunk retrieval.
The engineering value of this split is aligning retrieval granularity with question granularity. It avoids forcing local retrieval to answer global questions, and it avoids paying the cost of a full scan for point questions.
3. Local Retrieval-Generation: Six-Step Evidence Assembly
The core idea of local search is “entity anchor plus multi-path expansion.” The process divides into a retrieval stage and a generation stage, and the retrieval stage has six ordered steps.
- Query vectorization: encode the user question into a dense vector as the baseline for subsequent similarity matching.
- Entity location: compare the query vector against the description vectors of entities in the graph, retrieve several candidate entities, usually cap the number of candidates, and keep an oversampling factor to mitigate insufficient recall.
- Historical context retrieval: read the history of the multi-turn conversation for coreference resolution and intent completion, so pronouns like “he” or “this” do not cause anchor drift.
- Community report association: map each entity to its community and retrieve community-level summaries to provide meso-level background for the answer.
- Relationship and claim expansion: follow the relationship edges from the entities to retrieve neighboring entities, relationship descriptions, and verifiable claim entries that form the reasoning skeleton.
- Source text backtracking: use the source identifiers carried by entities and relationships to retrieve the original text chunks, keeping conclusions traceable.
The illustrative code below only expresses the call order and data flow and is not bound to any specific API:
def local_search(query, history, graph, vector_index, embedder, top_k=10):q_vec = embedder.encode(query)# Steps 1-2: locate entity anchors via vector searchentities = vector_index.search(q_vec, k=top_k * 2)[:top_k]# Step 3: complete conversation context and resolve coreferencecontext = build_dialog_context(history, query)# Steps 4-6: expand evidence layer by layer along the structurecommunities = graph.communities_of(entities)relations, claims = graph.expand(entities, hops=1)chunks = graph.source_texts(entities, relations)return assemble_prompt(context, entities, communities,relations, claims, chunks)
The generation stage organizes these six evidence paths into a prompt context with section markers that clearly separate “entity attributes,” “community background,” “relationships and claims,” and “source citations.” The model is then asked to answer based on the given material and to mark citation sources. The section markers work like an evidence map for the model and significantly reduce the chance of cross-source confusion.
Three points need attention in engineering practice. First, the number of candidate entities and the expansion hops must be tuned to corpus density, since too many hops introduce noise. Second, source text backtracking should enforce a length budget to avoid context overflow. Third, claim-type information should retain confidence or source markers to support conflict resolution.
4. Global Retrieval-Generation: Layered Summaries and Hierarchical Aggregation
The difficulty with global questions is that they cannot be exhaustively enumerated. The workable path is to build multi-level community summaries offline: start from fine-grained entity clusters and aggregate upward layer by layer into a tree-structured summary. Online, the system does not retrieve source text. Instead, it traverses the summaries at each level, has the model produce a local judgment and score for each level, and then aggregates by level into the final answer.
Three designs are key:
- Layered granularity control: bottom-level summaries stay close to facts, while top-level summaries stay close to themes. The two cannot replace each other.
- Local-to-global merge strategy: merge in parallel within the same level first, then converge across levels to control context size and the number of calls.
- Coverage self-check: decompose the question to split a global question into several sub-questions, verify summary coverage for each sub-question, and fall back to a finer level for additional evidence when coverage is missing.
5. Mode Selection and Optimization Recommendations
Selection can rely on three criteria: whether the answer falls on a single object, whether cross-chunk generalization is required, and whether item-by-item traceability is required. When all three are no, lean toward global mode; when any one holds, prefer local mode. For complex questions, a two-stage strategy of “locate the topic domain globally first, then gather evidence locally” works well.
Optimization directions include governing entity description quality, since anchor quality sets the recall ceiling; validating the extraction consistency of relationships and claims to reduce synonym conflicts; jointly tuning the parameters of the vector index and the graph index; and caching the expansion results of high-frequency entities to reduce latency. If deployed in the cloud, object storage can hold the raw corpus, a message queue can decouple extraction from index building, a container platform can host the retrieval service, and a logging and monitoring alerting system can observe recall rate and response latency, forming a closed loop for continuous iteration.
Overall, the value of graph-based retrieval-augmented generation is not to replace vector retrieval but to add the missing dimension of “structure” to it. Local mode handles precise evidence gathering, global mode handles macro-level generalization, and only the combination covers the vast majority of real-world knowledge question answering needs.
