Lesson 25.3 · 3 of 3 · 4 min read · Reviewed 24 Nov 2026
When graphs beat vectors
By the end, you can
- Decide when GraphRAG beats vector RAG.
- Avoid graphs where they add little.
Where graphs help
| Question type | Example | Why graphs help |
|---|---|---|
| Relationships | “Which teams depend on Auth?” | Edges answer directly |
| Multi-hop | “Who manages the owner of billing?” | Traversal follows the chain |
| Global themes | “Main risks across 500 incident reports?” | Community summaries cover the whole set |
| Impact analysis | “What breaks if supplier X fails?” | Paths reveal reach |
Where vectors are enough
- Single facts in one passage
- How-to questions answered by one section
- Small or rapidly changing document sets
Costs of a graph
- Extraction and resolution over every document
- Schema design and upkeep
- A graph store and query layer
- More ways to be wrong: a bad extraction becomes a false edge
A sensible path
- Build hybrid RAGRetrieval-augmented generation (RAG): Retrieving relevant documents at request time and adding them to the prompt so the answer is grounded in them. with rerankingReranking: Re-scoring an initial set of retrieved results with a more accurate model to put the best ones first. (chapter 23).
- Evaluate on real questions, tagged by type (chapter 26).
- If relationship or global questions fail often and matter, add a graph for those, and route those questions to it (chapter 41).
Key points
- Graphs win on relationship and multi-hop questions, and on 'big picture' questions across many documents.
- Vector RAG wins on specific factual questions answered by a passage, with far less setup.
- Start with vector or hybrid RAG; add a graph when evaluations show relationship questions failing.
Route questions to graph or vectors
Build a simple router that sends relationship and global questions to a graph and passage questions to vector search, and score it on tagged questions.
You will have: A route() function and accuracy against eight hand-tagged questions.
Steps
- Read the eight questions, each tagged with the route a person chose: graph or vector.
- Write route(): send questions about dependencies, ownership, who leads, impact or themes across many documents to the graph; everything else to vectors.
- Score the router against the tags and print any mismatches.
- Decide whether the graph path is worth building: count how many questions need it.
Done when
- The router matches at least 7 of 8 tags.
- Mismatches print with the question text.
- The script reports how many questions would go to the graph.
Open in the Playground No API key needed.
Starter code (Python)
QUESTIONS = [
("Which teams depend on the Auth service?", "graph"),
("How do I export my data to CSV?", "vector"),
("Who manages the team that owns billing?", "graph"),
("What is the refund window for shoes?", "vector"),
("What breaks if supplier Kappa fails?", "graph"),
("What are the main themes across all incident reports?", "graph"),
("How do I reset two-factor login?", "vector"),
("What does error E-4012 mean?", "vector"),
]
GRAPH_CUES = ["depend", "owns", "manages", "leads", "breaks if", "across all", "themes"]
def route(question):
# TODO: "graph" if any cue appears in the lowercased question, else "vector"
return "vector"
correct = sum(route(q) == tag for q, tag in QUESTIONS)
print(f"router matches {correct} of {len(QUESTIONS)}")
Show a solution
QUESTIONS = [
("Which teams depend on the Auth service?", "graph"),
("How do I export my data to CSV?", "vector"),
("Who manages the team that owns billing?", "graph"),
("What is the refund window for shoes?", "vector"),
("What breaks if supplier Kappa fails?", "graph"),
("What are the main themes across all incident reports?", "graph"),
("How do I reset two-factor login?", "vector"),
("What does error E-4012 mean?", "vector"),
]
GRAPH_CUES = ["depend", "owns", "manages", "leads", "breaks if", "across all", "themes"]
def route(question):
q = question.lower()
return "graph" if any(c in q for c in GRAPH_CUES) else "vector"
correct = 0
for q, tag in QUESTIONS:
r = route(q)
correct += r == tag
if r != tag:
print("mismatch:", q, "->", r, "(tagged", tag + ")")
print(f"router matches {correct} of {len(QUESTIONS)}")
print("questions routed to the graph:", sum(route(q) == "graph" for q, _ in QUESTIONS))
Finished the chapter? Take the chapter check.