AI Engineering
GraphRAG: Knowledge Graph Instead of Vector Search
Цели урока
- Understand where vector RAG breaks and which question types require a graph
- Learn how Microsoft GraphRAG builds its graph: entity extraction, Leiden, community summaries
- Compare LightRAG and HippoRAG against full GraphRAG on trade-offs
- Build a hybrid architecture that routes queries between vector and graph engines
A corpus of 10,000 documents, 50,000 entities, 200,000 relationships. Question: 'Which employees of company X worked on projects mentioned in contract Y?' Naive RAG returns chunks about company X and chunks about contract Y. The link between them is missing. The LLM hallucinates. Microsoft GraphRAG gives the precise answer through the graph in 3 seconds. Is this an edge case? No. 40% of questions in enterprise Q&A systems require multi-hop reasoning.
- Microsoft uses GraphRAG internally for corporate document analysis and M&A due diligence
- Notion AI integrated an entity graph for cross-page linking - finding connections between notes
- Neo4j + GraphRAG is a production pattern in pharma (connections between molecules, diseases, studies)
- LightRAG reached 10K+ GitHub stars in 3 months (2024) - the fastest-growing RAG framework
From Knowledge Graphs to GraphRAG
**2012 - Google Knowledge Graph**: first large-scale production knowledge graph, powering search knowledge panels. **2019 - KGQA (Knowledge Graph Question Answering)**: academic work on graph-based QA, without LLMs. **2023 - G-RAG, KG-RAG**: first attempts to combine LLMs with graphs for RAG. **February 2024 - Microsoft GraphRAG paper** (Edge et al.): complete system with entity extraction -> Leiden community detection -> hierarchical summaries -> global/local search. **September 2024 - LightRAG** (Guo et al.): a lighter alternative with dual-level retrieval and incremental indexing. **November 2024 - HippoRAG v2**: Personalized PageRank on entity graph as a replacement for exhaustive traversal.
Предварительные знания
Where Ordinary RAG Breaks
Vector search finds semantically similar fragments. This works when the question and answer live in the same text. But real questions often require connections across documents - and vectors can't do that.
| Question Type | RAG Problem | Example |
|---|---|---|
| Multi-hop | Answer requires chaining facts across multiple documents | 'Who led the team that wrote protocol X referenced in contract Y?' |
| Global summary | No single chunk contains the needed synthesis | 'What were the main themes discussed across all Q3 meetings?' |
| Relationship query | Vector proximity does not imply a semantic link | 'Which companies competed for contract Z?' |
| Entity-centric | Information about an entity is scattered across documents | 'List all projects involving Alex Johnson' |
Vector search finds **similar text**. A knowledge graph stores **connected facts**. These are fundamentally different structures. Searching document A ('Alex worked at Microsoft') and document B ('Microsoft acquired GitHub') returns two disconnected chunks. A graph immediately reveals the path: Alex -> worked at -> Microsoft -> acquired -> GitHub.
Edge et al. (Microsoft Research, 2024) showed that on 'global sensemaking' questions (synthesizing across an entire corpus) GraphRAG outperforms naive RAG by 40-60% on comprehensiveness and diversity scores. For precise factual lookups the gap is smaller - vector RAG is sufficient.
Why does vector RAG fail on multi-hop questions?
GraphRAG: Entity Extraction and Graph Construction
Microsoft GraphRAG (Edge et al., 2024) is a two-phase process. Indexing phase: an LLM reads the entire corpus, extracts entities and relationships, builds a graph, and applies community detection. Query phase: routes questions through the graph to relevant communities.
**Phase 1 - Indexing** (expensive, done once):
The **Leiden algorithm** is an improved Louvain that optimizes modularity. It discovers hierarchical communities: large (entire tech sector) -> medium (ML companies) -> small (specific product team). This enables GraphRAG to answer both local and global questions.
GraphRAG indexing is expensive. For a 1-million-token corpus: 3-5 LLM passes over the entire corpus = approximately USD 5-15 on gpt-4o-mini. For 100M tokens - USD 500-1500 just for indexing. GraphRAG is justified for stable corpora that change infrequently.
Why does GraphRAG apply Community Detection (Leiden algorithm) after building the graph?
LightRAG and HippoRAG: Lighter Alternatives
Microsoft GraphRAG is powerful but heavy. Community detection and hierarchical summaries require full reindexing when documents are added. LightRAG and HippoRAG offer different trade-offs.
LightRAG (Guo et al., 2024)
**Dual-level retrieval**: low-level (specific entities) plus high-level (abstract concepts). The graph is built incrementally - new documents are added without full reindexing. Retrieval runs through the graph and vector search simultaneously.
HippoRAG (Gutierrez et al., 2024)
Inspired by the hippocampal memory model. **Two components**: the Parahippocampal Cortex (PHC) encodes documents through named entity extraction; Hippocampal Indexing Theory builds a graph of relationships between named entities with Personalized PageRank for multi-hop traversal.
| System | Indexing | Incremental Updates | Multi-hop | Cost |
|---|---|---|---|---|
| Microsoft GraphRAG | Full LLM pass over corpus | Full reindexing | Excellent (community summaries) | High |
| LightRAG | LLM entity extraction | Incremental | Good (dual-level) | Medium |
| HippoRAG | NER + entity graph | Fast addition | Good (PageRank) | Low |
| Naive RAG | Embedding only | Instant | Poor | Minimal |
The main practical advantage of LightRAG over Microsoft GraphRAG is...
When to Use Graph, Vector, or Hybrid
GraphRAG is not a replacement for RAG. It is a specialized tool for specialized tasks. Production architectures often run both approaches in parallel, routing queries to the appropriate engine.
For a first Graph RAG system, start with LightRAG. Easier setup, incremental updates, decent quality. Use Microsoft GraphRAG when the corpus is stable (changes at most weekly) and global summaries across the entire corpus are needed.
The query 'What topics were discussed across all Q3 meetings?' - which approach fits best?
GraphRAG replaces vector RAG - building a graph is always better
GraphRAG complements vector RAG for specific tasks; for most questions vector RAG is sufficient and cheaper
GraphRAG indexing costs 10-100x more than embedding. For simple factual Q&A it is overengineering. 80% of questions in a typical enterprise chatbot are point facts where vector RAG works well.
GraphRAG is faster than ordinary RAG - graphs are traversed quickly
GraphRAG is slower at query time: graph traversal + community summary generation + multiple LLM calls
GraphRAG global search uses map-reduce: a separate LLM call for each community summary, then a final reduce. This can be 10-50 LLM calls per user query. Latency of 5-30 seconds and a cost of USD 0.01-0.10 per request.
Key Takeaways
- Vector RAG breaks on multi-hop, global summaries, and relationship queries - roughly 40% of enterprise questions
- GraphRAG builds a graph: entity extraction -> Leiden community detection -> hierarchical summaries
- Microsoft GraphRAG: best quality on global questions, expensive indexing, no incremental updates
- LightRAG: dual-level retrieval, incremental addition - the best starting point for production
- Hybrid architecture: route queries between vector and graph based on question type
Вопросы для размышления
- What types of questions do users ask in the current project - mostly point facts or relationship queries?
- If the corpus is updated daily, what does that imply for the choice between GraphRAG and LightRAG?
- GraphRAG indexing costs roughly USD 10 per 1M tokens. At what scale does this cost become justified?
Related Topics
GraphRAG builds a graph over documents. Knowledge Graphs are the broader topic of structured knowledge.
- Knowledge Graphs — Theoretical foundation: how knowledge graphs and ontologies are structured
- Advanced RAG — GraphRAG extends Advanced RAG for relational queries
- AI System Design — How to integrate GraphRAG into a production architecture