GraphRAG & knowledge graphs

In one sentence

An LLM turns the corpus into an entity–relation graph, clusters it into communities and pre-writes a summary of each, so you can answer corpus-wide questions that top-k chunk retrieval can't.

Analogy: Chunk RAG is searching a library's index cards. GraphRAG hires an analyst to read everything first, map who connects to whom and write a briefing per topic: expensive upfront, instant overviews later.

Indexing spends LLM calls once per chunk and per community; each query then maps over summaries (global) or walks an entity's neighborhood (local).

How it works

  • Chunk RAG fails on global questions: no single chunk holds "the main themes", so top-k returns arbitrary fragments.
  • At index time an LLM extracts entities and relations, Leiden clusters them, and an LLM summarizes each community.
  • Global search map-reduces over community reports for themes and overviews, at many LLM calls per query.
  • Local search matches query entities and pulls their neighbors, relations and source chunks, for multi-hop questions.
  • Indexing takes at least one LLM call per chunk plus one per community; keep simple lookups on hybrid search.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your chunk RAG over 5,000 customer interviews answers "What themes recur across all interviews?" with a few anecdotes. Raising top-k from 5 to 20 barely changes it. What's the real cause and fix?

Go deeper

Full explanation

GraphRAG uses an LLM to build a knowledge graph from your documents, then retrieves over the graph and its summaries, not only over raw chunks.

Chunk RAG fails on global questions — "What are the main themes across these 5,000 interviews?" — because no single chunk holds the answer and top-k returns 5 arbitrary fragments. Microsoft's GraphRAG (Edge et al., 2024) fixes that at index time:

  1. Extract — an LLM reads every chunk and emits entities, relations and claims.
  2. Graph — merge them into one graph; repeated entity names collapse into one node.
  3. Cluster — hierarchical Leiden community detection groups densely connected entities at several levels.
  4. Summarize — an LLM writes a community report per cluster, bottom-up.

At query time you pick a mode:

  • Global search — map-reduce over community reports: each batch of reports yields a scored partial answer, and the best are reduced into one. For themes and overviews; many LLM calls per query.
  • Local search — match the query to entities, then pull their neighbors, relations, source chunks and reports. For multi-hop questions like "how is X related to Y?".

The price is indexing: one or more LLM calls per chunk plus one per community, repeated as the corpus changes. LightRAG skips community reports and supports incremental inserts; Microsoft's LazyGraphRAG swaps LLM extraction for cheap NLP and defers summarization to query time.

Code The GraphRAG mechanism in miniature
pythonThe GraphRAG mechanism in miniature
import networkx as nx
from networkx.algorithms.community import louvain_communities

# --- Indexing: cost scales with corpus size (LLM call per chunk + per community)
G = nx.Graph()
for chunk in chunks:
    # LLM returns [(head, relation, tail), ...]: the expensive step
    for h, rel, t in llm_extract_triples(chunk.text):
        G.add_edge(h.lower(), t.lower(), relation=rel, source=chunk.id)

# GraphRAG uses hierarchical Leiden; Louvain shows the same idea
communities = louvain_communities(G, seed=42)
reports = [llm_summarize(G.subgraph(c).edges(data=True)) for c in communities]

# --- Global search: map-reduce over reports, not over raw chunks
def global_search(question: str) -> str:
    partials = [llm_partial_answer(question, r) for r in reports]  # map
    useful = [p for p in partials if p.score > 0]                   # drop "no info"
    useful.sort(key=lambda p: p.score, reverse=True)
    return llm_reduce(question, [p.text for p in useful[:20]])      # reduce
Real example

A drug-safety team has ~3,000 adverse-event reports (~2M tokens). Asked "What recurring safety themes appear across all reports?", chunk RAG returns 8 chunks about whichever drug sits closest to the query embedding, and the answer is anecdotal. GraphRAG costs thousands of LLM calls to index once, but global search maps the question over every community report (e.g. "liver toxicity: drugs A, C, F, 140 reports") and reduces them into ranked themes that point back to source reports. For "What's the max dose of drug C?" the team still routes to plain hybrid search: faster, cheaper and sufficient.

Trade-offs +3 · −4

+ You gain

  • Answers global "themes across the corpus" questions that top-k retrieval structurally cannot.
  • Multi-hop entity questions follow explicit edges instead of hoping two chunks get co-retrieved.
  • The graph and community reports are inspectable artifacts you can browse, audit and reuse.

− You pay

  • Indexing is LLM-heavy: at least one call per chunk plus one per community, far above embedding cost.
  • Updates hurt: new documents can reshuffle communities and leave reports stale.
  • Extraction errors (missed or duplicated entities) silently corrupt the graph.
  • Global search is slow and costly per query: one LLM call per batch of community reports, on every question.

Use it when

Sensemaking over a mostly static, high-value corpus (research, investigations, due diligence) where users ask about themes, trends or how entities connect, and you can pay a large one-off indexing bill.

Avoid it when

Fact lookups, fast-changing corpora or tight budgets. Try good Chunking strategies, Hybrid search & RRF and Reranking (cross-encoders) first: most "we need GraphRAG" requests are really retrieval-quality problems.

Numbers to know 4
  • Indexing cost ≈ one extraction call per chunk (plus optional "gleaning" retries) + one report per community.
  • The GraphRAG paper evaluated on ~1–2M-token corpora (podcast transcripts, news articles).
  • In the paper, 600-token chunks extracted ~2× the entity references of 2,400-token chunks.
  • LazyGraphRAG: indexing cost on par with vector RAG, ~0.1% of full GraphRAG (Microsoft Research, 2024).
Common pitfalls 4
  • Adopting GraphRAG for a lookup workload: you pay the indexing bill and barely beat hybrid search.
  • Skipping entity resolution: "AWS", "Amazon Web Services" and "Amazon" become three nodes and communities fragment.
  • Re-indexing everything per new document instead of batching updates or using an incremental variant.
  • No baseline: compare against chunk RAG + reranker on the same questions, including global ones.
Interview questions 2

Answer out loud first, then reveal.

When would you choose GraphRAG over a standard vector RAG pipeline?Show answer

When the questions are global or relational, not lookups. For "what are the main risks across all 4,000 contracts", no top-k set of chunks contains the answer; GraphRAG pre-computes community summaries so global search can map-reduce over them. First I'd check the query mix in logs: if 90% are fact lookups, I'd invest in hybrid search and reranking instead. If I adopt it, I'd scope it to a static, high-value corpus, budget the indexing bill explicitly, and keep vector search as the default with a router sending only global questions to the graph.

GraphRAG indexing is too expensive for us. What are your options?Show answer

Three levers. Scope: index only the corpus where global questions actually occur. Cheaper models: extraction is a structured task a small or fine-tuned model can handle, but I'd validate entity recall on a sample before switching. Lighter variants: LightRAG skips community reports and supports incremental inserts; LazyGraphRAG uses cheap NLP extraction and defers LLM work to query time, with indexing cost close to vector RAG. The trade-off is moving cost from index time to query time, which pays off when the corpus changes often or is rarely queried.