TL;DR
GraphRAG is a way to answer questions about a whole document collection, such as "what are the main themes here?", that ordinary retrieval cannot answer. An LLM first reads the collection in chunks and builds a knowledge graph of entities and the relationships between them. The graph is split into communities of closely related entities, and the LLM writes a summary of each community. A question is then answered by writing partial answers from the summaries and combining them. On two corpora of about one million tokens each, the authors report that GraphRAG beats a standard vector retrieval baseline on comprehensiveness and diversity, as judged by an LLM.
Builds on: Retrieval-Augmented Generation, Knowledge Graph, Community Detection · Leads to: hybrid retrieval that mixes embedding search with community reports, which the paper lists as future work and has no lesson yet
Why it mattered
The paper named a gap that the usual RAG pipeline has. Vector RAG retrieves a handful of text chunks that are close to the question, then asks the model to answer from them. That works when the answer sits in a few chunks, such as a date or a named person. It fails when the question needs the whole corpus, because no small set of chunks contains the answer. The paper's open-source release at github.com/microsoft/graphrag, and versions of the approach offered as extensions to LangChain, LlamaIndex, NebulaGraph and Neo4j, made it available to others. The paper's own example of a corpus-wide question is "What are the main themes in the dataset?", and the approach is aimed at that kind of question.
The problem
The authors call the hard questions sensemaking queries. They need an understanding of the whole dataset, not a fact from one passage. Their example is "What are the main themes in the dataset?" No single chunk answers this, and a model with a context window of limited size cannot read a million tokens at once.
Two families of method existed before the paper. Retrieval methods are cheap but local. Query-focused summarisation (QFS) methods can summarise a whole text, but they do not scale to the amount of text a RAG system indexes. The paper wants both properties: the whole corpus in view, and cost that grows with the corpus in a manageable way.
Evaluation was a second problem. Global questions have no gold-standard answer, so the authors could not score them against a key. They needed a comparison method that a judge can apply to two answers.
How it works
The method has two phases. The indexing phase runs once and builds the graph and its summaries. The query phase runs for each question. Here is the pipeline in order.
- Split the corpus into chunks. The documents are cut into text chunks. In the experiments each chunk is 600 tokens, with a 100-token overlap between neighbouring chunks. Chunk size is a trade-off. Larger chunks need fewer LLM calls, which lowers cost, but the LLM extracts fewer entities from them. The paper's example is HotPotQA, where GPT-4 extracted almost twice as many entity references from 600-token chunks as from 2,400-token ones.
- Extract entities, relationships and claims. For each chunk, an LLM is prompted to list entities such as people, places and organisations, the relationships between them, and short factual claims. Each item comes with a short description. The prompts include few-shot examples that set the domain.
- Build the knowledge graph. Each entity becomes a node and each relationship becomes an edge. The same entity is often extracted from several chunks, so the paper merges duplicates by exact string matching. The number of times a relationship is found becomes its edge weight, and the descriptions are summarised.
- Detect communities. The graph is partitioned into a hierarchy of communities with the Leiden algorithm, a Community Detection method that finds groups of densely connected nodes. Each level of the hierarchy is a partition that covers every node once. The levels run from coarse, with few large communities, to fine, with many small ones.
- Summarise the communities. The LLM writes a report for each community, starting from the lowest level. A leaf community's report uses the descriptions of its entities, relationships and claims, added in order of prominence until a token limit is reached. A higher-level report uses the summaries of its sub-communities where the full element descriptions do not fit.
- Answer a question with map-reduce. For a query, the community summaries at one chosen level are shuffled and divided into batches that fit the context window. In the map step, the LLM writes a partial answer for each batch and gives it a helpfulness score. In the reduce step, the partial answers are sorted by that score and added to a new context until it is full, and the LLM writes the final answer.
flowchart LR A[Corpus] --> B[Chunks of 600 tokens] B --> C[LLM extracts entities, relationships, claims] C --> D[Knowledge graph] D --> E[Leiden communities, hierarchy] E --> F[Community summaries] F --> G[Map: partial answers] G --> H[Reduce: global answer]
A tiny case shows the logic. Suppose a corpus has three articles about a city's transport plans, and the graph has two communities: one about buses and one about cycling. A question about the city's main transport themes gets a partial answer from each community summary. Each partial answer is short, and the reduce step merges them into one answer that covers both themes. A vector retriever given the same question would return the chunks whose embeddings are most similar to the words of the question, which may all come from the bus articles.
The math
Let the corpus be split into chunks . The LLM extraction step produces a set of entity instances and relationship instances from each chunk. After merging duplicates, the result is a Graph , where is the set of entities and the set of relationships. Each edge has a weight , the number of times the relationship was extracted.
Step 2 in symbols: extraction as summarisation
For a chunk , the extraction is a function that returns entities, relationships and claims. The paper describes this as abstractive summarisation: the output is a summary of concepts, and some relationships are not stated in the text.
Step 4 in symbols: the community hierarchy
The Leiden algorithm partitions into communities at each level . Let be the partition at level . Each partition covers the nodes in a mutually exclusive, collectively exhaustive way:
Level 0 has the fewest communities, which are the roots. Level has the most, which are the leaves. The paper calls the roots C0, and the finer levels C1, C2 and C3 in the experiments.
Step 5 in symbols: summaries
Let be the summary of community . For a leaf, is generated from the element descriptions in , subject to a token budget of 8,000 tokens in the experiments. For a community whose element descriptions exceed the budget, the summaries of its sub-communities are used instead, so each level can be written with fewer tokens than the level below.
Step 6 in symbols: map-reduce
For a query and a chosen level, the map step produces a partial answer and a helpfulness score for each summary . The reduce step sorts the partial answers by in descending order, and fills a context window with them until the token budget is reached. The final answer is then
where is the sorted order and the list stops when the budget is used up.
Token cost
The cost of a query is roughly the number of tokens that pass through the model. The paper's Table 2 gives this for the Podcast corpus. The root level C0 has 34 community summaries and 26,657 tokens in total, which is 2.6 percent of the maximum that the paper uses. The text-summarisation baseline TS, which runs the same map-reduce on the source chunks, has 1,669 units and 1,014,611 tokens, which is 100 percent. The ratio explains the paper's claim that root-level summaries cost far less per query.
Worked examples
A corpus has four entities, A, B, C and D. Edges are A-B with weight 3, B-C with weight 1, and C-D with weight 2.
This picture uses a simplified rule: take the strongest ties first. Leiden optimises a quality score over whole partitions, but the grouping it finds on this graph is the same.
- The strongest tie is A-B, with weight 3. Put A and B in one group.
- The next strongest tie is C-D, with weight 2. Put C and D in one group.
- The remaining tie, B-C, has weight 1 and joins two different groups, so it stays between them.
- The partition at the top level is {A, B} and {C, D}.
- Each community gets one summary, which is generated from its own entities and edges.
Interpretation: the graph index turns a set of small facts into groups of related facts, and each group has its own summary.
Take the root level C0, which has 34 community summaries. Assume each summary is about 784 tokens on average, which is the paper's total of 26,657 tokens divided by 34.
- The 34 summaries together contain 26,657 tokens.
- The map step works on batches of summaries that each fit one 8,000-token window.
- The 26,657 tokens need about 4 windows of 8,000 tokens, since .
- Each batch produces a partial answer, and the reduce step merges the four partial answers into one final answer.
- The same question over the source text TS needs 1,014,611 tokens, which is about 127 windows of 8,000 tokens.
Interpretation: the map-reduce pattern lets a question about a million-token corpus be answered with a few windows of model input, because the summaries have already compressed the corpus. The average-size assumption is an illustration; the paper reports the total, not per-summary sizes.
Figure 2 of the paper reports head-to-head win rates. Each comparison ran 125 questions, and each question was run five times and averaged. For the Podcast corpus, the global approaches beat vector RAG on comprehensiveness with win rates between 72 and 83 percent, and on diversity with win rates between 75 and 82 percent. Both results are significant at p less than .001.
- A win rate of 50 percent means neither answer was preferred on average. Above 50 means the row method was preferred.
- A win rate of 72 percent means the global answer was preferred in about 72 of every 100 comparisons. A tie counts as half a win for each side, as the paper's Table 6 scores it.
- Comprehensiveness is the criterion for "how much detail covers all aspects and details of the question".
- So for the Podcast corpus, the lowest global comprehensiveness win rate of 72 percent is well above 50, and the difference is not small.
- The paper's directness criterion is a control. It asks how specifically and clearly an answer addresses the question, and the paper expects it to pull against comprehensiveness and diversity. Vector RAG wins on directness, which shows the judge is not simply rewarding longer answers.
Interpretation: on this evaluation, the judge consistently preferred the global answers on the qualities the task is about, and the control shows the win is not just style. The paper also checks the judge against claim-based measures in Experiment 2, so the result is not resting on the judge alone.
Try it: the paper reports the Podcast comprehensiveness range as 72 to 83 percent for global approaches. If a method's win rate is 60 percent, is it preferred more often than not? What share of 125 questions, times five repetitions, would it win? Answer: yes, 60 percent is above 50 percent, so it is preferred more often. Over 125 questions repeated five times there are 625 comparisons, and 60 percent of 625 is 375 wins.
Results
The results come from two experiments. Experiment 1 uses an LLM judge for pairwise comparisons, and the win rates are reported with p-values.
Experiment 1, global sensemaking. The corpora are a set of podcast transcripts from the program Behind the Tech with Kevin Scott, about 1 million tokens split into 1,669 chunks of 600 tokens, and a set of news articles from September 2013 to December 2023, about 1.7 million tokens split into 3,197 chunks. The indexing run on the Podcast corpus took 281 minutes with gpt-4-turbo.
The graph has 8,564 nodes and 20,691 edges for the Podcast corpus, and 15,754 nodes and 19,520 edges for the News corpus. The paper compares six conditions: four GraphRAG levels C0 to C3, the text-summarisation baseline TS, and the vector RAG baseline SS.
The main findings are these.
- Global approaches beat vector RAG on comprehensiveness and diversity. For comprehensiveness the win rates are 72 to 83 percent on Podcast and 72 to 80 percent on News. For diversity they are 75 to 82 percent on Podcast and 62 to 71 percent on News.
- Vector RAG gave the most direct answers in the comparisons, which is expected for a method that returns short, specific passages.
- Community summaries are a small but consistent improvement over source-text summarisation, except at the root level. The intermediate level on Podcast gets a comprehensiveness win rate of 57 percent, and the low level on News gets 64 percent.
- Scale: the low level C3 needs 26 to 33 percent fewer tokens than TS per query, and the root level C0 needs more than 97 percent fewer.
- Empowerment, the criterion of how well an answer helps a reader make informed judgments, gave mixed results.
Experiment 2, claim-based measures. To check the LLM judge, the authors counted extracted factual claims as a measure of comprehensiveness, and counted clusters of claims as a measure of diversity. On both corpora, all global conditions and TS had significantly more claims than vector RAG (p below .05). For diversity, on the Podcast corpus all global conditions significantly beat SS across the distance thresholds tested (p below .05). On the News corpus only C0 did so across all thresholds. There were no significant differences among the global conditions, or between global search and TS, on either measure.
Limits. The paper states its own limits. The evaluation covers two corpora of about one million tokens each, so the authors caution that generalisation to other domains is unknown. The comparison of hallucination or fabrication rates is left to future work. The judge is an LLM, and the authors used a claim-based check to support it but not replace it. The root level is cheap but not the best on every measure.
Reading guide
The paper is short, but the method section is dense. Read it in this order.
- Abstract and Section 1, Introduction. The problem is global questions over a corpus, and the answer is a graph index with map-reduce over community summaries. Prerequisites: Retrieval-Augmented Generation and Language Model.
- Section 2, Background. Covers RAG approaches, knowledge graphs with LLMs, adaptive benchmarking, and the RAG evaluation criteria. Prerequisites: Knowledge Graph and LLM-as-a-Judge.
- Section 3.1, GraphRAG workflow. Chunking, extraction, graph construction, community detection, summaries and answers. Prerequisites: Community Detection and Hierarchical Clustering for the hierarchy idea, and In-Context Learning for the prompts.
- Section 3.2 and 3.3, questions and criteria. How the 125 test questions were generated and what the judge compares. Prerequisite: LLM-as-a-Judge.
- Section 4, Analysis. The datasets, the six conditions and the configuration, including the 8,000-token window. Prerequisite: Approximate Nearest Neighbor Search for the vector baseline.
- Section 5, Results. Tables 2 and 3 and Figure 2. Read these with the numbers in this lesson.
- Section 6, Discussion, and Section 7, Conclusion. The limits and the future work on hybrid retrieval.
Check yourself
QuestionWhy does vector RAG fail on a question such as what the main themes of a corpus are?Show answer
Vector RAG retrieves the chunks most similar to the question. A theme spans the whole corpus, so no small set of chunks contains it. The method cannot gather the global view in a few chunks, so the answer is weak in comprehensiveness.
QuestionIn the paper, the root level C0 has 34 community summaries and 26,657 tokens, while TS has 1,014,611 tokens. What share of TS's tokens does C0 use?Show answer
, which is about 2.6 percent. This matches the paper's 2.6 percent of maximum tokens, so C0 uses roughly 97 percent fewer tokens than TS.
QuestionWhy does the method use a community hierarchy rather than a single flat set of communities?Show answer
A hierarchy gives summaries at several levels of detail. Coarse levels have few summaries and cost little per query, while fine levels have more detail and cost more. The user, or the experiment, can pick the level that gives the best balance of cost and answer quality.
QuestionA method has a win rate of 60 percent against a baseline across 125 questions, each run five times. How many comparisons does it win, and is that evidence it is preferred?Show answer
There are comparisons, and 60 percent of them is 375 wins. A win rate above 50 percent means the method is preferred more often than not. Whether the preference is reliable also depends on the significance test, which the paper reports for its own comparisons.