What is GraphRAG? Knowledge graph RAG, explained
GraphRAG builds a knowledge graph and community summaries from your documents so an LLM can answer whole-corpus questions. How it works, with a Python demo.

GraphRAG is a retrieval-augmented generation method from Microsoft Research that uses an LLM to turn your documents into a knowledge graph of entities and relationships, clusters that graph into communities, and writes a summary for each community before any question is asked. At query time it answers from those summaries and graph neighborhoods instead of only from the top few text chunks, which lets it handle questions about a whole corpus (“what are the main themes here?”) that plain vector RAG answers badly.
What problem does GraphRAG solve?
Plain RAG, which I cover in what is RAG, embeds the question, pulls the k most similar chunks and hands them to the model. That works when the answer sits in one or two passages. It fails when the answer is spread across the whole collection.
The GraphRAG paper (Edge et al., first posted 24 April 2024) names this directly: RAG fails on global questions about an entire corpus, such as “What are the main themes in the dataset?”, because no single chunk is similar to that question. The answer is a property of the collection, so top-k similarity search has nothing good to rank.
Microsoft’s launch post (13 February 2024) shows two failure modes on a news dataset. In its words, “Baseline RAG struggles to connect the dots” when an answer needs facts joined through shared entities, and it does poorly on whole-dataset questions like “top 5 themes”, where the baseline returned themes that had little to do with the data.
How does GraphRAG work?
The GraphRAG docs describe an indexing pipeline with four stages:
- Chunk the corpus into “TextUnits”. The paper used 600-token chunks with 100 tokens of overlap.
- Extract entities, relationships and key claims from every TextUnit with an LLM.
- Cluster the entity graph hierarchically with the Leiden algorithm.
- Summarize each community, bottom-up, again with an LLM.
The paper labels the hierarchy levels C0 (the few root communities) down to C3 (the many fine-grained ones). A question can be answered at any level.
At query time there are four modes in the current docs:
- Global search answers holistic questions from the community summaries. Each summary produces a partial answer (map), and the partials are combined into the final answer (reduce).
- Local search answers questions about a specific entity by fanning out to its neighbors and their source text.
- DRIFT search is local search with community context added.
- Basic search is ordinary top-k vector RAG, kept for the questions it already handles well.
The point to hold on to: GraphRAG moves LLM work from query time to index time. You pay up front to read and summarize everything once, so that a global question can be answered from a few hundred summaries instead of a million tokens of raw text.
What does GraphRAG look like in code?
Here is the indexing idea in about 60 lines of standard-library Python. Eight short notes about three teams, a regex instead of an LLM for entity extraction, a co-occurrence graph, and Louvain-style modularity moves for clustering. GraphRAG uses Leiden, which Traag, Waltman and van Eck (2018) designed to fix the fact that Louvain “may yield arbitrarily badly connected communities”. For eight notes the two behave the same.
# graphrag_toy.py: the GraphRAG indexing idea in miniature. Python 3, stdlib only.
# Entities come from a regex here; real GraphRAG asks an LLM to extract them.
import re
from collections import Counter, defaultdict
notes = [
"Asha leads Payments. Payments moved its ledger tables to Postgres in March.",
"Ravi joined Payments and owns the Postgres upgrade.",
"Postgres latency alerts paged Ravi twice in April.",
"Meera runs Search. Search moved its index to Qdrant.",
"Qdrant recall dropped after Meera swapped the embedding model.",
"Kiran owns Billing. Billing replays invoices from Kafka every night.",
"Kafka disk alerts woke Kiran in May.",
"Billing reads refunds from Payments through Kafka.",
]
NOT_ENTITIES = {"March", "April", "May"}
# 1. Extract entities per text unit, 2. build a co-occurrence graph.
units = [{w for w in re.findall(r"\b[A-Z][a-z]+\b", n) if w not in NOT_ENTITIES} for n in notes]
graph = defaultdict(Counter)
for ents in units:
for a in ents:
for b in ents - {a}:
graph[a][b] += 1
# 3. Cluster the graph: Louvain-style local moves that raise modularity.
# GraphRAG uses Leiden, a refinement of the same idea, applied hierarchically.
deg = {n: sum(graph[n].values()) for n in graph}
m2 = sum(deg.values()) # twice the total edge weight
label = {n: n for n in graph}
tot = dict(deg) # total degree inside each community
moved = True
while moved:
moved = False
for n in sorted(graph):
tot[label[n]] -= deg[n]
links = Counter()
for nb, w in graph[n].items():
links[label[nb]] += w
links[label[n]] += 0
best = max(sorted(links), key=lambda c: links[c] - tot[c] * deg[n] / m2)
if best != label[n]:
moved = True
label[n] = best
tot[best] += deg[n]
communities = defaultdict(set)
for node, l in label.items():
communities[l].add(node)
# 4. "Summarize" each community: its members and the notes that mention them.
print("Communities:")
for i, members in enumerate(sorted(communities.values(), key=lambda m: sorted(m))):
docs = [j for j, ents in enumerate(units) if ents & members]
print(f" C{i}: {', '.join(sorted(members)):<32} notes {docs}")
# Baseline: top-2 notes by word overlap with a global question.
q = "what are the main themes across these notes"
qw = set(q.split())
scores = sorted(((len(qw & set(n.lower().split())), i) for i, n in enumerate(notes)), reverse=True)
print("\nTop-2 retrieval for the global question:", [i for _, i in scores[:2]])
print("Edges that cross communities:",
sorted({tuple(sorted((a, b))) for a in graph for b in graph[a] if label[a] != label[b]}))
Output (Python 3.13.11):
Communities:
C0: Asha, Payments, Postgres, Ravi notes [0, 1, 2, 7]
C1: Billing, Kafka, Kiran notes [5, 6, 7]
C2: Meera, Qdrant, Search notes [3, 4]
Top-2 retrieval for the global question: [4, 1]
Edges that cross communities: [('Billing', 'Payments'), ('Kafka', 'Payments')]
Nobody told the script there were three teams. The graph found them from co-occurrence alone, and note 7 (“Billing reads refunds from Payments through Kafka”) shows up as the bridge between two communities, which is exactly the kind of cross-document link a chunk retriever never sees. The top-2 baseline, meanwhile, picked one Search note and one Payments note for a question about themes and missed Billing entirely. Give a model those two chunks and it will confidently describe a two-team organization.
In the real system, step 4 is an LLM writing a paragraph per community (“the Payments team migrated to Postgres; latency alerts followed”), and global search asks the model to answer the question from each of those paragraphs, then merges the partial answers.
Does GraphRAG actually beat vector RAG?
On the questions it was designed for, the paper says yes. It tested two datasets of roughly a million tokens each: podcast transcripts (about 1 million tokens, 1,669 chunks) and news articles (about 1.7 million tokens, 3,197 chunks). An LLM judge compared answers head to head. GraphRAG beat vector RAG on comprehensiveness with win rates of 72 to 83 percent on the podcasts and 72 to 80 percent on the news set, and on diversity with 75 to 82 percent and 62 to 71 percent.
The cost result is the one I find more useful. Answering from the root-level (C0) summaries took 26,657 tokens on the podcast set, against 1,014,611 tokens for summarizing the source text directly, which the paper describes as “over 97% fewer tokens”.
Two caveats. These are global sensemaking questions judged by an LLM, not exact-answer QA with a gold label. And the comparison is against plain semantic search, not the hybrid search plus reranking setup most production systems use by now.
What does GraphRAG cost?
Indexing is the bill. Every chunk goes through an LLM for extraction, and every community gets an LLM-written summary. The project’s own getting started page warns: “GraphRAG can consume a lot of LLM resources!” and suggests trying fast, inexpensive models first before committing to a big indexing job. The paper’s timing experiment ran indexing against a public gpt-4-turbo endpoint.
Microsoft’s answer to that bill is LazyGraphRAG (25 November 2024). It skips the up-front summaries, builds its index with noun-phrase extraction instead of an LLM, and defers LLM work to query time. Microsoft reports indexing costs equal to vector RAG and 0.1 percent of full GraphRAG, with global-query quality comparable to GraphRAG global search at more than 700 times lower query cost. Those numbers come from Microsoft’s own tests on 5,590 AP news articles and 100 synthetic queries.
Where does GraphRAG break?
Extraction errors compound. If the LLM misses an entity or merges two people with the same name, the graph is wrong, the communities are wrong, and the summaries confidently describe the wrong structure. I’d spot-check extracted entities on a sample before trusting any global answer.
Updates are expensive. New documents change the graph, which can change the communities, which invalidates summaries. The docs mention a migration notebook between major versions so you can “avoid re-indexing prior datasets”, which tells you how much re-indexing hurts. For data that changes daily, the full pipeline is a poor fit.
It does not help needle questions. “What is the refund window for plan B?” lives in one chunk. Basic or hybrid search answers it faster and cheaper, and GraphRAG’s own basic mode exists for that reason.
Summaries can drift from the source. Community summaries are generated text, so global answers inherit whatever the summarizer added or dropped. Keep the links from summary back to source TextUnits and show them as citations.
What I would do
From a data-platform seat, the line I would circle is that GraphRAG is a batch ETL job with an LLM in the middle. Treat it like one: version the index, track the cost per run, and rebuild on a schedule rather than on every write.
I’d use it when the users actually ask corpus-level questions: an analyst reading a quarter of incident reports, a researcher asking what themes run through a few thousand interviews, a compliance team mapping which entities connect across contracts. For a support bot answering lookup questions, I’d stay with chunking, hybrid search and a reranker, and maybe add an agentic RAG loop for multi-hop questions.
If I wanted graph benefits without the indexing bill, I’d try LazyGraphRAG-style indexing first, then measure with the methods in how to evaluate RAG before paying for full community summaries.
FAQ
Is GraphRAG the same as a knowledge graph?
No. A knowledge graph is the data structure. GraphRAG is a retrieval pipeline that builds one with an LLM, clusters it into communities, summarizes them and uses those summaries to answer questions.
What is the difference between GraphRAG local and global search?
Global search answers whole-corpus questions by mapping the question over community summaries and reducing the partial answers. Local search starts from the entities named in the question and fans out to their neighbors and source text.
Is GraphRAG open source?
Yes. Microsoft publishes it as the graphrag Python package (python -m pip install graphrag), with docs at microsoft.github.io/graphrag.
Is GraphRAG better than vector RAG?
For global sensemaking questions, the paper reports 72 to 83 percent comprehensiveness win rates over vector RAG. For single-fact lookups, plain or hybrid retrieval is cheaper and usually enough.
Sources
- Edge et al., From Local to Global: A Graph RAG Approach to Query-Focused Summarization, arXiv, 24 April 2024 (v2 19 February 2025)
- Microsoft Research, GraphRAG: Unlocking LLM discovery on narrative private data, 13 February 2024
- Microsoft Research, LazyGraphRAG: Setting a new standard for quality and cost, 25 November 2024
- Microsoft, GraphRAG documentation and Getting started (read 2026-10-31)
- Traag, Waltman and van Eck, From Louvain to Leiden: guaranteeing well-connected communities, arXiv, 19 October 2018