GraphRAG
GraphRAG builds a knowledge graph from documents, then retrieves entities, relationships, and community summaries to answer multi-hop and global questions.
GraphRAG (graph retrieval-augmented generation) is a form of retrieval-augmented generation (RAG) that retrieves from a knowledge graph instead of, or alongside, text chunks found by vector search. A large language model (LLM) first extracts the entities in a document collection, such as people, companies, parts, and places, along with the relationships between them. At question time, the system retrieves connected entities, relationship paths, or summaries of whole clusters of the graph and gives them to the LLM as context. The name is most closely tied to Microsoft Research's GraphRAG approach to query-focused summarization, published in 2024 with an open-source implementation, and is also used for any RAG system that retrieves over a graph.
Why Vector RAG Needs a Graph#
Standard RAG embeds document chunks as embeddings, stores them in a vector database, and retrieves the few chunks most similar to the question. That works for questions answered by one passage and struggles with two other kinds:
- Multi-hop questions: The answer depends on facts spread across documents that are linked only through shared entities, such as which factories depend on a supplier near a port that a storm closed. No single chunk is similar to the whole question.
- Global questions: Questions about a whole corpus, such as "What are the main themes across these 5,000 incident reports?", need information from every document, while vector retrieval returns only the top few chunks.
A graph stores the links between facts explicitly, so retrieval can follow them, and summaries of graph communities cover the entire corpus.
How GraphRAG Works#
Microsoft's GraphRAG builds its index in four steps. It splits the documents into text units and asks an LLM to extract entities, relationships, and claims from each unit, an LLM-driven form of named entity recognition and relation extraction. It merges the descriptions of entities that appear in many units into one node each. It then runs hierarchical Leiden community detection, which groups densely connected entities into nested communities, and has the LLM write a summary report for every community at every level.
Queries then take one of two paths:
- Local search: Starts from the entities named in the question and gathers their neighbors, relationships, community reports, and the original text units that mention them.
- Global search: Works map-reduce style over community reports: each report produces a partial answer with a relevance score, and the most relevant partial answers are combined into the final response.
On datasets of around one million tokens, the paper reported that global search produced substantially more comprehensive and diverse answers to corpus-wide questions than a conventional RAG baseline.
The core of local search is graph traversal. This Python example, using NetworkX, stores triples that an LLM might extract from separate documents and follows relationships outward from the entity in the question:
import networkx as nx
# Entity-relationship triples that an LLM extracted from separate documents
triples = [
("Typhoon", "closed", "Kaohsiung port"),
("Kaohsiung port", "ships parts for", "Supplier A"),
("Supplier A", "makes", "bearing B-17"),
("bearing B-17", "is used at", "Ohio plant"),
("Texas plant", "uses", "motor M-4"),
]
graph = nx.DiGraph()
for head, relation, tail in triples:
graph.add_edge(head, tail, relation=relation)
# Question: "Which plants could the typhoon disrupt?"
# Local search: follow relationships outward from the entity named in the question
edges = nx.bfs_edges(graph, "Typhoon")
context = [f"{head} {graph[head][tail]['relation']} {tail}" for head, tail in edges]
print("\n".join(context))It prints the four-hop chain from "Typhoon closed Kaohsiung port" to "bearing B-17 is used at Ohio plant", a connection no single source document states, and leaves out the unrelated Texas plant. The LLM receives these lines as grounding context and can answer that the Ohio plant is at risk.
GraphRAG vs. Related Approaches#
- Knowledge graphs: The data structure of entities and typed relationships. GraphRAG builds or reuses one specifically to retrieve context for an LLM.
- Hybrid search: Combines keyword and vector retrieval over text chunks. Many production GraphRAG systems run graph traversal alongside hybrid search.
- Agentic RAG: An agent decides what to retrieve and when, over several steps. Graph queries can be one of its tools.
- Graph neural networks (GNNs): Learn from graph structure through training, for tasks such as link prediction. GraphRAG uses the graph at retrieval time with no training.
Real-World Applications#
- Drug discovery: Graphs that link genes, proteins, compounds, and diseases let researchers ask questions that cross thousands of papers, such as which approved drugs target proteins in a disease pathway.
- Financial investigations: Analysts trace ownership chains through shell companies and shared directors and ask an LLM to summarize the network behind a suspicious transaction.
- Supply-chain risk: Linking suppliers, parts, sites, and shipping routes answers questions such as which products depend on a single factory.
- Enterprise knowledge: Large collections of reports, tickets, and meeting notes become searchable by theme, with community summaries answering questions about the whole collection.
Graphs can also hold what cameras see, the basis of multimodal RAG over video. Entity resolution, deciding that two mentions refer to the same thing, is the step object tracking performs for video: Ultralytics YOLO26 tracking assigns each person or vehicle a persistent ID across frames, so a video graph can store one node per tracked object with edges for where and when it appeared next to others, instead of one node per frame.
Costs and Trade-Offs#
Indexing is the main expense, since the LLM reads every text unit to extract entities and then writes every community report, so large corpora cost far more to index than to embed. Extraction errors, such as merging two different people with the same name, propagate into every answer that touches them, and changing documents means re-extracting and re-summarizing the affected parts of the graph. Microsoft's LazyGraphRAG addresses the cost by building its concept graph with noun-phrase extraction and graph statistics and deferring all LLM use to query time, which makes its indexing cost identical to vector RAG and 0.1% of full GraphRAG.










