Definition
GraphRAG is retrieval-augmented generation over a knowledge graph that an LLM builds from the corpus itself. The reference design is Edge et al., "From Local to Global: A Graph RAG Approach to Query-Focused Summarization" (Microsoft Research, 2024). An LLM extracts entities, relationships and claims from every chunk. The resulting graph is partitioned into a hierarchy of communities with the Leiden algorithm (Traag, Waltman and van Eck, 2019), and the LLM writes a report for each community. Queries are answered from those reports (global search) or from the neighbourhood of matched entities (local search).
Vector RAG answers questions whose answer sits in a few chunks (see RAG architecture). It fails on sensemaking questions over a whole corpus, such as "What are the main themes in these 2,000 news articles?". No top- set of chunks contains that answer: it is spread thinly across everything, and the chunks most similar to the question are not the most representative. The paper frames this as query-focused summarisation, and GraphRAG does the summarising in advance, at indexing time.
The second gain is multi-hop structure. An edge such as "Water Board orders rationing" joins facts that appear in different chunks, so a question about an entity can follow relationships instead of hoping each hop is in the top . Graph-learning methods for such graphs are covered in Knowledge graph embeddings; GraphRAG uses the graph for retrieval and summarisation, with no trained graph model.
Indexing
From documents to community reports
- 1Text units. Split documents into chunks; the paper used 600-token chunks with 100-token overlap.
- 2Extraction. For each chunk an LLM lists entities (name, type, description), relationships (source, target, description, strength) and optionally claims. Extra "gleaning" rounds ask the model whether it missed any, which recovers more entities from long chunks.
- 3Graph. Entities with the same name are merged and their descriptions summarised; relationship counts become edge weights.
- 4Communities. Leiden is run recursively, giving levels C0 (root, few large communities) down to leaf communities.
- 5Reports. For each community an LLM writes a report (title, summary, key findings, an impact rating) from its entities, edges and claims; higher levels can summarise their sub-communities' reports.
Communities and modularity
- total edge weight inside community , and the sum of its nodes' weighted degrees
- total edge weight of the graph (here, co-mention counts)
- resolution: larger γ penalises big communities and gives more, smaller ones
- gain (up to the factor ) of moving node with degree into ; is its edge weight to , the degree sum of
Louvain (Blondel et al., 2008) moves each node to the neighbouring community with the largest , then merges each community into one node and repeats; every pass is one level of the hierarchy. Leiden adds a refinement step that guarantees every community is internally connected, which Louvain does not. The figure below runs Louvain, which shows the same mechanics on a small graph.
Querying
Global search takes the reports at one level, shuffles them into batches that fit the context window and runs a map step in parallel: each batch yields a partial answer and a helpfulness score from 0 to 100. Answers scored 0 are dropped; the rest are sorted by score and packed into a final reduce prompt. Cost scales with the number of reports read, not with the question. Root-level C0 reports are the cheapest; leaf levels are more detailed and more expensive.
Local search, added in the open-source graphrag library, embeds the question, matches entity descriptions, and gathers the entities' neighbours, relationships, claims, community reports and the raw chunks that mention them into one ranked context. It is closer to ordinary RAG, with the graph deciding which chunks are related.
From the paper (Edge et al., 2024)
- Datasets
- two corpora of about 1M tokens each: podcast transcripts and news articles; 600-token chunks, 100-token overlap
- Questions
- global sensemaking questions generated by an LLM from descriptions of likely users and tasks, 125 per dataset
- Judging
- head-to-head comparisons by an LLM judge on comprehensiveness, diversity, empowerment and directness
- Result
- all global GraphRAG variants beat vector RAG on comprehensiveness and diversity; vector RAG was more direct. Root-level (C0) reports needed far fewer tokens per query than summarising the source text
- Follow-ups
- LightRAG (Guo et al., 2024) retrieves over entity and relation keys at two levels; HippoRAG (Gutiérrez et al., NeurIPS 2024) runs Personalized PageRank from query entities over an extracted graph
Worked example: why Strike joins the schools
At the graph has , so . Strike has degree : weight 2 to TransitCo, 2 to Union and 1 to Nurses. With the other nodes in their final communities:
| Community | w (Strike → c) | Σ_c (degree sum) | γΣ_c k / 2m | Δ |
|---|---|---|---|---|
| schools (Union, Teachers, …) | 2 | 28 | 28 · 5 / 174 = 0.8046 | 1.1954 |
| transit (TransitCo, Metro, …) | 2 | 31 | 31 · 5 / 174 = 0.8908 | 1.1092 |
| health (Nurses, …) | 1 | 27 | 27 · 5 / 174 = 0.7759 | 0.2241 |
The edge weights tie at 2, so the smaller community wins: the null model expects fewer edges into it by chance. Moving Strike to transit would lower from to . The bridge entity therefore lands in the schools report, and a question about the transit strike must rely on local search or a lower level. In a real corpus the fix is better extraction: separate entities for a teachers' strike and a transit strike.
| Community | Entities | L_c | d_c | L_c/m − (d_c/2m)² |
|---|---|---|---|---|
| water | 7 | 20 | 43 | 0.2299 − 0.0611 = 0.1688 |
| transit | 5 | 14 | 31 | 0.1609 − 0.0317 = 0.1292 |
| schools + Strike | 6 | 14 | 33 | 0.1609 − 0.0360 = 0.1250 |
| election + Budget | 7 | 17 | 40 | 0.1954 − 0.0528 = 0.1426 |
| health | 5 | 12 | 27 | 0.1379 − 0.0241 = 0.1139 |
1import json23MAP = ("Answer the question using only these community reports. "4 'Return JSON: {"points": [{"text": str, "score": 0-100}]}. '5 "Score 0 if the reports are irrelevant.")67def global_search(question, reports, batch_tokens=8000, budget_tokens=12000):8 batches, cur, size = [], [], 09 for rep in reports: # C0 reports, shuffled10 if size + rep["tokens"] > batch_tokens and cur:11 batches.append(cur); cur, size = [], 012 cur.append(rep); size += rep["tokens"]13 batches.append(cur)1415 points = []16 for b in batches: # map: run in parallel in practice17 ctx = "\n\n".join(f"[{r['id']}] {r['title']}\n{r['summary']}" for r in b)18 out = json.loads(llm(system=MAP, user=f"{ctx}\n\nQ: {question}"))19 points += [p for p in out["points"] if p["score"] > 0]2021 points.sort(key=lambda p: -p["score"]) # reduce: best first, until budget22 ctx, used = [], 023 for p in points:24 n = len(p["text"]) // 4 # rough token count25 if used + n > budget_tokens: break26 ctx.append(p["text"]); used += n27 return llm(system="Combine these analyst points into one answer.",28 user="\n".join(ctx) + f"\n\nQ: {question}")Use when
- +Answers global, sensemaking questions over a whole corpus with a bounded context
- +Relationships make multi-hop links explicit and inspectable
- +Community reports are reusable artefacts: browsable summaries of the corpus
Avoid when
- −Expensive, slow indexing: LLM calls over every chunk and every community
- −Extraction errors (missed entities, unmerged duplicates, ambiguous names) propagate into communities and reports
- −Global search costs many map calls per question; less direct than vector RAG for simple lookups
Check yourself
Why does vector top-k retrieval do poorly on "What are the main themes in this corpus?"
Check yourself
In the figure, raising γ from 1 to 2.5 at the top level gives 7 communities instead of 5. What happens to the global search cost under the figure's token model?
Remember
- ✓Index: chunk, LLM-extract entities and relationships, merge into a graph, cluster with Leiden into a hierarchy, write a report per community.
- ✓Communities maximise modularity ; γ sets their size.
- ✓Global search: map over community reports with 0–100 scores, reduce the best into one answer; for corpus-wide questions.
- ✓Local search: match entities, fan out to neighbours, relationships, reports and source chunks; for entity questions.
- ✓Costly to build and refresh; route point lookups to plain hybrid RAG.