This chapter presents Microsoft’s GraphRAG as an end-to-end method that builds a knowledge graph with the help of an LLM and then uses layered natural-language summaries to make that graph directly useful for retrieval. The approach first extracts entities and relationships from unstructured text and then enriches them with concise, contextual summaries. Once the graph is formed, it detects communities of closely related entities and generates domain-specific reports for those clusters. Using a narrative corpus (e.g., The Odyssey) and a configurable set of entity types, the chapter demonstrates how fragmented mentions across many chunks can be transformed into a coherent representation that supports resilient, high-level question answering.
The indexing pipeline covers chunking strategy, prompt design, and graph construction. Text is segmented into semantically meaningful units and further split to manageable sizes; prompts guide the LLM to identify entities, classify them, and describe their relationships, with results stored in Neo4j. Because the same entity or pair of entities can be described multiple times across chunks, the chapter merges these descriptions into unified summaries to reduce redundancy and improve consistency. Next, it applies Louvain community detection to group densely connected entities and produces structured community reports. Practical guidance addresses scaling issues—such as “super nodes” and large communities—by ranking and filtering descriptions so that summaries remain concise and fit within model context limits.
On top of this graph index, the chapter implements two retrieval modes. Global search follows a map-reduce pattern that maps a user query over community reports to extract key points with importance scores and then reduces those points into a single, synthesized answer. Local search embeds entity summaries into a vector index, retrieves the most relevant entities for a query, and expands to connected chunks, summarized relationships, and community descriptions; ranked and limited context is then fed to an LLM with grounded, citation-style prompts that discourage speculation. Together, these retrievers show how community- and entity-level summaries enable efficient, faithful responses, and how the framework can be extended with additional ranking, hierarchy levels, and alternative retriever strategies.
Microsoft’s GraphRAG pipeline. Image from [Edge et al., 2024] licensed under CC BY 4.0.
Impact of Chunk Size and Self-Reflection Iterations on Entity Extraction. Image from [Edge et al., 2024] licensed under CC BY 4.0.
Example of community detection results
Global Search
Local Search
Summary
MS GraphRAG uses a two-stage process where entities and relationships are first extracted and summarized from source documents, followed by community detection and summarization to create a cohesive knowledge representation.
The extraction process uses LLMs to identify entities, classify them by predefined types (e.g., PERSON, GOD, LOCATION), and generate detailed descriptions of both entities and their relationships, including relationship strength scores.
Entity and relationship descriptions from multiple text chunks are consolidated through LLM-based summarization to create unified, non-redundant representations that preserve key information.
The system detects communities of densely connected entities using algorithms like Louvain method, then generates community-level summaries to capture higher-level themes and relationships.
Global search uses community summaries to answer broad, thematic queries through a map-reduce approach
Local search combines vector similarity search with graph traversal to answer entity-focused queries
The effectiveness of retrieval depends on factors like chunk size, entity type selection, and community detection parameters, with smaller chunks generally leading to more comprehensive entity extraction.
The system handles potential scaling challenges through ranking mechanisms for managing large numbers of entities, relationships, and communities while maintaining context relevance.
FAQ
What is Microsoft’s GraphRAG and how is it different from “classic” RAG?GraphRAG uses an LLM to first build a knowledge graph from unstructured text, then summarizes both entities/relationships and graph communities. Unlike classic RAG that retrieves raw text chunks by vector similarity, GraphRAG retrieves structured, LLM-written summaries (entity, relationship, and community reports) and uses them to answer questions via global or local graph-aware search.Which kinds of datasets work best, and how should I pick entity types?Choose unstructured corpora where key entities appear across multiple chunks (e.g., news, podcasts, literature, legal). Predefine entity types before extraction (people, organizations, locations) and add domain-specific types (e.g., genes, pathways, legal clauses). Let your target questions guide which types you include—this choice affects extraction, linking, and summary quality.How should I chunk documents and why do chunk sizes matter?- Smaller chunks generally yield more detected entities; larger chunks can miss details.
- Multiple self-reflection passes can increase entity coverage.
- A practical choice is ~1000-word chunks with overlap to preserve continuity, but you should tune for your model limits, latency, and cost.How does entity and relationship extraction work in GraphRAG?An LLM prompt identifies all entities of predefined types, generates rich descriptions for each, and extracts relationships between entity pairs with explanations and a strength score. The results are stored in a graph database (e.g., Neo4j) as nodes and edges, forming the backbone of the knowledge graph.Why summarize entities and relationships after extraction?Multiple mentions of the same entity/relationship are fragmented and sometimes redundant. LLM-based summarization merges all descriptions into a single coherent, third-person summary that preserves key details, resolves contradictions, and reduces duplication—improving clarity for downstream retrieval.What is community detection and why does GraphRAG use it?Community detection groups densely connected entities to reveal higher-level structure (themes, teams, story arcs). GraphRAG uses Louvain to assign community IDs, then generates a structured “community report” per group. These reports power global search and provide thematic context beyond individual nodes. Note: Louvain is non-deterministic and can yield slightly different partitions across runs. Hierarchical levels can be used on larger graphs; a single level often suffices for small graphs.How does global search work?Global search follows a map-reduce pattern:
- Map: Run the LLM on community reports to extract key points with importance scores and data references.
- Reduce: Aggregate the most important points from all communities and synthesize a final answer.
You can filter by a community “rating” threshold and choose the community hierarchy level to balance thoroughness vs. cost/latency.How does local search work?- Compute embeddings for entity summaries and build a vector index.
- Retrieve the most similar entities for a query, then expand to related items: connected entities, summarized relationships, community reports, and associated source chunks.
- Rank/limit each category (chunks, reports, relationships, entities) to fit the context window.
- Use a system prompt that requires explicit data references and discourages speculation.How do I handle super nodes and large communities within token limits?- Super nodes (e.g., very popular places/people) and large communities can overwhelm prompts.
- Apply ranking and filtering to select the most relevant descriptions, relationships, and chunks.
- Cap the number of record IDs per reference (e.g., top 5 + “+more”).
- Consider per-entity/per-community importance scores (rank, weight) and top-K limits per category.What are the key implementation details and tuning points?- Storage: Use a graph database (e.g., Neo4j) to store entities, relationships, summaries, and communities.
- Models: Use a capable LLM for extraction/summarization; use text-embedding models for vector search.
- Parameters to tune: chunk size/overlap, number of self-reflection passes, similarity k, top-K for chunks/reports/relationships, community rating thresholds, and hierarchy level.
- Gotchas: inconsistent entity typing, overlong prompts, non-deterministic community detection, and “super node” prompt bloat—mitigate with schema clarity, ranking, and filtering.
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!