Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 37/ 160
02. RAG

GraphRAG

Entity/relationship graphs that improve multi-hop questions beyond flat chunk retrieval.

AdvancedKnowledge Graph · Multi-hop3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

The system builds a map of who and what is connected to whom, then follows the connections to answer questions that need several pieces of information.

Think of it like…

A detective's evidence board: instead of a pile of separate witness statements (chunks), names and places are pinned and connected with string. To answer "who connects person A to the warehouse?", you follow the string rather than searching for a statement that mentions both.

Where you’ve seen it

An investigations team has 80,000 emails and filings. The question "Which intermediaries connect Company A's directors to the shipping contracts?" returns nothing useful from vector search: no passage mentions all of it. With an extracted graph (entities: people, companies, contracts; relations: director_of, party_to, owns), a two-hop traversal finds three intermediaries, and the answer cites the supporting documents. The extra cost: about 40 hours of LLM extraction for the corpus and a graph database to maintain.

Words you’ll hear

Knowledge graph
Nodes (entities) and edges (relationships), often with source passages attached.
Multi-hop question
A question needing several linked facts from different documents.
Community summary
An LLM-written summary of a cluster of related entities, used for global questions.
Local vs global search
Local: start from entities in the question and expand. Global: map-reduce over community summaries.

Visual diagram

Loading interactive diagram

Theory & deep dive

What GraphRAG adds over vector RAG

Indexing: split documents into chunks, ask an LLM to extract entities and relationships (with types, descriptions and the source chunk), merge duplicates through entity resolution ("Acme Ltd", "ACME Limited" and "Acme" become one node), and store the graph. Microsoft's GraphRAG then runs community detection (Leiden clustering) to group densely connected entities hierarchically and generates summaries for each community. Querying: local search identifies entities in the question, expands to neighbours and their text units, and gives the LLM those facts and passages; global search has the LLM answer from community summaries in a map-reduce fashion, which is how "what are the main themes?" gets answered across millions of tokens.

Lighter variants exist: build a graph over chunks linked by shared entities, use an existing knowledge graph or database (customers, products, org charts) and let an LLM write graph queries (Text-to-Cypher), or use graph traversal as an extra retriever fused with vector and keyword results.

A two-hop question as graph traversal

Question: which suppliers of the delayed Part X also supply Competitor Y? Cypher-style: MATCH (s:Supplier)-[:SUPPLIES]->(:Part {name:"X"}), (s)-[:SUPPLIES]->(:Company {name:"Y"}) RETURN s. Each edge carries source document ids for citation.

Key takeaway: Entities and relations enable multi-hop and corpus-level questions; summaries cover global ones.

Costs, risks and when to use it

Costs and risks: extraction is expensive (many LLM calls per chunk, often 10 to 100 times the cost of embedding alone); extraction errors create wrong or duplicate nodes and edges; schema and entity-resolution choices need design and tuning; graphs go stale as documents change and need incremental updates; and queries add latency. Evaluate against a strong baseline of hybrid search, reranking and parent-child retrieval first, because many apparent multi-hop failures are really retrieval or chunking problems.

Use GraphRAG when questions genuinely require connecting entities across documents, when users ask corpus-wide thematic questions, when relationships are first-class (supply chains, org structures, fraud rings, biomedical interactions) or when explainable reasoning paths matter. Skip it for straightforward lookup, FAQ or documentation questions. Measure with a labelled set that includes multi-hop and global questions, and compare answer quality, latency and indexing cost with the simpler baseline.

A decision check

Of 200 test questions, 150 are single-fact lookups (hybrid RAG scores 92%), 30 are multi-hop (hybrid 48%, graph-assisted 71%) and 20 are global (hybrid 25%, GraphRAG global 68%). The graph pays off for 25% of questions, so they route only those through it.

Key takeaway: Beat the baseline first; route only multi-hop and global questions through the graph.

How it works, step by step

Step 1 of 4
Evaluation

1. Check the baseline

Measure hybrid search plus reranking on single-hop, multi-hop and global questions to see what actually fails.

multi-hop 48% · global 25%
Key numbers at this step
Decide
if a graph is worth it

When to use it & trade-offs

What it is

GraphRAG augments retrieval with a knowledge graph: an LLM extracts entities (people, companies, products, policies) and relationships between them from the documents, and queries can then follow links across documents. Microsoft's GraphRAG approach also clusters the graph into communities and writes a summary for each, which lets the system answer global questions ("what are the main themes across these 10,000 reports?") that flat chunk retrieval can't. Flat vector RAG finds passages that look like the question; graph RAG finds connected evidence.

Why it matters: Ordinary RAG is weak on multi-hop questions ("which suppliers of the delayed component also supply our competitor?") because the needed facts sit in different documents and no single chunk resembles the question, and on corpus-wide summaries. GraphRAG can help, but it adds heavy indexing cost, pipeline complexity and failure modes. Knowing when it's worth it, and when hybrid search with good chunking is enough, is the real skill.

When to reach for it

  • Investigations, supply-chain and compliance analysis
  • Thematic summaries across large collections
  • Domains where relationships are the point

When to avoid or be careful

  • GraphRAG for simple FAQ or documentation lookup
  • Skipping entity resolution
  • Adopting it without comparing against hybrid search plus reranking

Retrieval approaches for connected questions

Hybrid vector + keyword RAG
Best for: Most lookups and single-hop questions

Strengths: Simple, cheap, mature.

Watch out: Weak on multi-hop and corpus-level questions.

GraphRAG (extracted graph + communities)
Best for: Multi-hop and global questions over document collections

Strengths: Connected evidence; theme-level answers.

Watch out: High indexing cost; extraction errors; maintenance.

Existing graph or database + Text-to-Cypher/SQL
Best for: Structured relationships you already store

Strengths: Accurate, no extraction needed.

Watch out: Needs reliable query generation and schema docs.

Interview signals & numbers to know

When this topic comes up

  • “Questions need facts from several documents”
  • “Summarise the main themes across the whole corpus”
  • “Who connects A to B?”
  • Knowledge graphs
  • Multi-hop QA

Benchmarks & rules of thumb

10 – 100× -
extraction cost relative to embedding alone
48% → 71% -
multi-hop gain in the example
25% -
share of questions the graph helped

Common mistakes & follow-ups

Common interview mistakes

  • Building a graph for a corpus where every question is a single-fact lookup.
  • Leaving duplicate entities unmerged, fragmenting the graph into unconnected pieces.
  • Treating the extracted graph as ground truth without checking error rates.

Likely interviewer follow-ups

  • When would you choose GraphRAG over plain RAG?
  • What is the difference between local and global search?
  • How would you keep a knowledge graph up to date?
Interview tip: Show you'd measure first: baseline failures by question type, then use the graph only for the types it helps. That is a production answer, not a hype answer.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply GraphRAG with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Citations
Next topic
Agentic RAG