Boost Answer Accuracy: Detailed GraphRAG Retrieval Steps with Knowledge Graphs

This article walks through GraphRAG’s retrieval phase, showing how knowledge‑graph entities, relationships, and community reports are assembled into a query context, comparing local and global modes with traditional RAG, and illustrating the process with a concrete “Age of Big Data” example.

Fun with Large Models
Fun with Large Models
Fun with Large Models
Boost Answer Accuracy: Detailed GraphRAG Retrieval Steps with Knowledge Graphs

GraphRAG Retrieval Overview

After constructing a knowledge graph from source documents, GraphRAG enters the retrieval stage. It leverages all entities, relationships, and community reports stored in the graph to build a query‑specific context, which is then fed to a large language model (LLM) for answer generation.

Detailed Retrieval Steps

User Query : The user submits a natural‑language question.

Build Query Context : GraphRAG extracts from the knowledge graph the items most relevant to the query, including:

TextUnits – document fragments related to the query.

Entities – e.g., "Victor Mayer‑Schönberger", "Data Science".

Relationships – e.g., author‑of relationships between entities.

Community Reports – optional summaries that help understand entity clusters.

Text Embedding : Each TextUnit, Entity, and Relationship is encoded with a pre‑trained embedding model (e.g., the model used in the author’s earlier RAG primer).

Build Local Context : Based on configurable parameters (such as the proportion of TextUnits vs. Community Reports), GraphRAG assembles the selected items into a "context window".

Retrieve Relevant Information : A similarity search over the embeddings identifies the most relevant pieces for the query.

Answer Generation by LLM : The retrieved context is passed to an LLM (GPT, DeepSeek, Qwen3, etc.) which generates either a brief answer or a detailed report, depending on the query complexity.

Return Results : The final answer is returned to the user; if return_candidate_context=True, the system also returns the candidate TextUnits, Entities, and Relationships.

Case Study: "The Age of Big Data"

The source text is the book "The Age of Big Data". After text splitting, three TextUnits are created:

t1 : "The Age of Big Data" is a book co‑authored by Victor Mayer‑Schönberger and Kenneth Cukier that discusses extracting value from massive data sets. (50 tokens)

t2 : The book delves into data‑science applications and explains the impact of data analysis and prediction across industries. (50 tokens)

t3 : It provides numerous real‑world examples showing how big data transforms lives and predicts future trends. (50 tokens)

Entity recognition yields entities such as "Victor Mayer‑Schönberger", "Data Science", and the relationship "author‑of" linking the author to the book. Two community reports are also generated:

Community 1 (core) : Title "Impact of The Age of Big Data" – summarises the book’s discussion of data science, data analysis, and their broad influence.

Community 2 (peripheral) : Title "Authors and Theories Behind The Age of Big Data" – describes the authors and related academic fields.

Local Mode Example

Query: "What is the core of 'The Age of Big Data'?"

GraphRAG identifies the entity "The Age of Big Data".

It looks up related entities (author, "Data Science") and the author‑of relationship.

Using the Entity and Relationship tables, it retrieves the three TextUnits because each mentions the book or its core concepts.

Embeddings are computed for the selected items and similarity with the query is calculated.

The LLM generates an answer such as: "The core idea of 'The Age of Big Data' is the value of data and its influence on various domains, especially future‑trend prediction."

The result is returned to the user.

Global Mode Example

GraphRAG starts from the core community report (Community 1).

It extracts the central entities "The Age of Big Data" and "Data Science".

From the Entity and Relationship tables it finds additional related entities and their associated TextUnits.

Embeddings are computed and similarity search selects the most relevant pieces.

The LLM produces an answer similar to the local mode but benefits from the richer contextual signal of the community report, often yielding a more precise response.

Traditional RAG Comparison

Traditional RAG skips the knowledge‑graph step and directly searches the split TextUnits. In this example only TextUnit 1 contains the phrase "The Age of Big Data", so the model would base its answer solely on that fragment, missing the broader context provided by the other units, entities, and relationships.

Conclusion

GraphRAG’s retrieval phase enriches the LLM’s context by integrating knowledge‑graph entities, relationships, and community reports. The dual local and global modes allow flexible context construction, and the approach consistently outperforms traditional RAG, which relies only on raw text similarity.

LLMKnowledge GraphGraphRAGlocal moderetrieval-augmented generationglobal modetraditional RAG
Fun with Large Models
Written by

Fun with Large Models

Master's graduate from Beijing Institute of Technology, published four top‑journal papers, previously worked as a developer at ByteDance and Alibaba. Currently researching large models at a major state‑owned enterprise. Committed to sharing concise, practical AI large‑model development experience, believing that AI large models will become as essential as PCs in the future. Let's start experimenting now!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.