Phase 3: Agentic RAG · 70 min · Python · Anthropic SDK · NetworkX
GraphRAG — Knowledge Graphs for Complex Reasoning
Standard RAG finds relevant chunks. GraphRAG finds how entities are connected across your entire corpus — and that's a fundamentally different question.
Hiring signal: Microsoft, Google, and Amazon have each published internal work on knowledge graph-enhanced retrieval. GraphRAG is on the hiring checklist for AI engineers at enterprise software companies including SAP, Salesforce, and ServiceNow — knowing when to use it and being able to explain the tradeoffs accurately is a differentiating signal.
What you will learn
- Explain the GraphRAG architecture: entity extraction, graph construction, community detection, and indexed retrieval
- Implement a simplified GraphRAG pipeline using an LLM for entity extraction and NetworkX for graph construction
- Identify when GraphRAG outperforms standard vector RAG and when the extra cost is not justified
The Problem
"How did the 2021 policy change in our procurement department affect the vendor onboarding process, given the contracts we signed with our logistics partners in 2019?" This question cannot be answered from any single document chunk. The relationship between the 2021 policy, the onboarding process, and the 2019 contracts exists across five documents, each of which contains one piece of the picture. Standard RAG retrieves the five most semantically similar chunks — but "semantically similar" is the wrong criterion here. What you need is relational traversal: find the entities, find how they connect.
GraphRAG, published by Microsoft Research in April 2024, addresses exactly this gap. The insight is that a corpus of documents is not just a bag of text — it's a latent knowledge graph waiting to be made explicit. Every document mentions entities (people, organizations, concepts, policies, products) and the relationships between them ("the procurement policy governs vendor contracts," "vendor contracts were amended in 2021," "the GDPR team reviews all vendor contracts"). GraphRAG extracts this graph during indexing, enabling query-time reasoning that traverses entity relationships across document boundaries.
This is not a niche research contribution — Microsoft open-sourced the library in 2024 and it has since been adopted by enterprise knowledge management teams at large organizations. The pattern of building knowledge graphs from unstructured documents for downstream reasoning is now standard architecture knowledge for AI engineers working on complex enterprise search.
Global vs. Local Search
GraphRAG supports two retrieval modes that address different question types. Local search combines retrieved entity/relationship data with the original text chunks — best for specific entity questions ("What is the relationship between X and Y?"). Global search searches across community summaries — best for thematic questions about the entire corpus ("What are the main themes across all our documents?"). Standard vector RAG cannot do global search at all — it has no concept of the whole corpus.
The GraphRAG Architecture
Microsoft's GraphRAG pipeline has five phases. Understanding each phase is necessary to implement it and to debug it when it produces unexpected results.
Phase 1 — Entity extraction: For each document chunk, an LLM extracts a list of named entities and the relationships between them. Prompt: "Extract all entities (people, organizations, policies, concepts, products, locations) and the relationships between them. Return JSON: [{entity_1, entity_type, entity_2, relationship, description}]." This runs on every chunk — the most expensive phase, consuming most of the indexing token budget.
Phase 2 — Graph construction: Merge entity mentions across chunks into a property graph. Entity deduplication: "procurement policy" and "the 2021 procurement policy" are the same node. Build the graph: nodes = unique entities, edges = relationships extracted across all chunks, edge weight = frequency of the relationship appearing in the corpus.
Phase 3 — Community detection: Run the Leiden algorithm (a variant of Louvain with better modularity) on the entity graph to find clusters of strongly interconnected entities. A community might be: {GDPR compliance team, vendor contracts, legal review, onboarding process} — a cluster of entities that frequently appear together. Community detection is done once at indexing time.
Phase 4 — Community summaries: For each community detected, run an LLM summarization over all the text chunks containing entities in that community. This produces a dense paragraph that captures what the community is "about." These summaries are stored and indexed for global search.
Phase 5 — Retrieval: At query time, decide: local search (retrieve entities + relationships + original chunks) or global search (retrieve relevant community summaries). Combine and send to the LLM for final synthesis.
A user asks: "What is the relationship between the GDPR compliance team and the vendor onboarding process, based on our internal documents?" Standard RAG returns 5 chunks that each mention one or the other but not their connection. What does GraphRAG do differently?
This is GraphRAG's core advantage. The relationship between "GDPR compliance team" and "vendor onboarding" might be scattered across 6 documents — no single chunk says "GDPR team reviews all new vendor contracts before onboarding." GraphRAG extracted entity-relationship pairs from each chunk at indexing time, building graph edges like: GDPR team --reviews--> vendor contracts --required_for--> onboarding process. At query time, it traverses these edges to find the connection, rather than hoping semantic similarity retrieves the right chunks.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Implementing a Simplified GraphRAG Pipeline, Local vs. Global Search, When to Use GraphRAG vs. Standard RAG, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy