graph rag
**Graph RAG (Graph-based Retrieval Augmented Generation)** is the **advanced retrieval paradigm that organizes external knowledge as a graph structure rather than flat document chunks** — enabling LLMs to answer complex multi-hop questions by traversing relationships between entities, performing community detection for summarization, and leveraging structured knowledge connections that traditional vector-similarity RAG misses, with systems like Microsoft's GraphRAG demonstrating significant improvements on questions requiring synthesis across multiple documents.
**Traditional RAG vs. Graph RAG**
```
Traditional RAG:
[Query] → [Embed query] → [Vector similarity search in chunks]
→ [Retrieve top-k chunks] → [LLM generates answer]
Problem: Each chunk is independent — misses cross-document connections
Graph RAG:
[Documents] → [Extract entities + relationships] → [Build knowledge graph]
[Query] → [Identify relevant entities] → [Traverse graph]
→ [Gather connected context] → [LLM generates answer]
Advantage: Captures relationships, enables multi-hop reasoning
```
**Graph RAG Pipeline**
```
Indexing Phase:
1. Chunk documents
2. LLM extracts entities and relationships from each chunk
"Apple released the M3 chip" → (Apple, released, M3 chip)
3. Build knowledge graph from extracted triples
4. Detect communities (clusters of related entities)
5. Generate community summaries using LLM
6. Store: Graph + community summaries + original chunks
Query Phase:
Local search: Entity-focused traversal for specific questions
Global search: Community summaries for broad questions
```
**Microsoft GraphRAG Architecture**
| Component | Purpose | Method |
|-----------|---------|--------|
| Entity extraction | Identify people, places, concepts | LLM (GPT-4) few-shot |
| Relationship extraction | Connections between entities | LLM co-extraction |
| Community detection | Group related entities | Leiden algorithm |
| Community summarization | High-level topic summaries | LLM hierarchical summarization |
| Local search | Specific entity-centric queries | Graph traversal + vector search |
| Global search | Broad thematic queries | Community summary aggregation |
**When Graph RAG Excels**
| Question Type | Traditional RAG | Graph RAG |
|-------------|----------------|----------|
| "What is X?" (factual) | Good | Good |
| "How are X and Y related?" (relational) | Poor | Excellent |
| "Summarize the main themes" (global) | Poor | Excellent |
| "What events led to X?" (causal chain) | Moderate | Good |
| "Compare entities across documents" | Poor | Good |
**Entity and Relationship Extraction**
```python
extraction_prompt = """Extract entities and relationships from the text.
Entities: (name, type, description)
Relationships: (source, target, description, strength)
Text: "NVIDIA's H100 GPU uses TSMC's 4nm process and features
80 billion transistors with HBM3 memory."
Entities:
- (H100, GPU, NVIDIA flagship data center GPU)
- (NVIDIA, Company, GPU manufacturer)
- (TSMC, Company, Semiconductor foundry)
- (HBM3, Memory, High bandwidth memory technology)
Relationships:
- (NVIDIA, manufactures, H100, strength=10)
- (H100, fabricated_by, TSMC 4nm, strength=9)
- (H100, features, HBM3, strength=8)
"""
```
**Graph RAG vs. Traditional RAG Performance**
| Metric | Traditional RAG | Graph RAG | Improvement |
|--------|----------------|----------|------------|
| Multi-hop accuracy | 45-55% | 65-75% | +20% |
| Global question quality | 40-50% (poor) | 70-80% | +30% |
| Single-fact retrieval | 80-90% | 80-85% | Similar |
| Indexing cost | Low | 5-10× higher | Trade-off |
| Query latency | 200 ms | 500 ms-2s | Slower |
**Challenges**
| Challenge | Issue | Mitigation |
|-----------|-------|------------|
| Extraction cost | LLM extraction for every chunk is expensive | Use smaller models, cache |
| Extraction errors | LLM may hallucinate entities/relations | Verification, confidence scores |
| Graph maintenance | Updating graph as documents change | Incremental updates |
| Scale | Large graphs become expensive to query | Hierarchical communities |
Graph RAG is **the next evolution of retrieval-augmented generation for complex knowledge tasks** — by organizing information as interconnected entities and relationships rather than isolated text chunks, Graph RAG enables LLMs to perform the multi-hop reasoning and global synthesis that traditional vector-search RAG fundamentally cannot, making it essential for enterprise knowledge management, research synthesis, and any application where understanding connections between pieces of information is as important as finding individual facts.