39.1 How Graphs Improve AI Reasoning Over Vector Search Alone
Multi-hop reasoning. Vector search finds semantically similar documents; graph traversal finds connected concepts across explicit relationships — a fundamentally different capability.
Example — “What services would be affected if the payment database goes down?”
- Vector search: finds documents that mention “payment database.”
- Graph query: traverses the dependency chain to find every transitively dependent service.
MATCH path = (db:Database {name: "PaymentDB"})<-[:READS_FROM|WRITES_TO*1..5]-(s:Service)
RETURN s.name, length(path) AS hops
ORDER BY hops
Contextual enrichment. Before context reaches the LLM, enrich retrieved chunks with graph-derived structure:
User Query: "Why is the checkout service slow?"
Vector Search → retrieves relevant docs about the checkout service
Graph Enrichment → adds:
- Checkout depends on: Inventory Service, Payment Gateway, User Service
- Recent changes: Payment Gateway deployed v2.1 yesterday
- Current alerts: Inventory Service at 95% CPU
- Owner: Team Commerce
Entity disambiguation. When a query mentions an ambiguous term (e.g., a name that’s both a person and an internal service), the graph resolves which entity is meant based on the user’s context and the graph’s own relationships — something pure vector similarity cannot do reliably.
39.2 GraphRAG Architecture Diagram
flowchart TD
Query["User Input Query"] --> Analysis["Query Intent & Entity Extraction\n(Identifies Target Entities & Relations)"]
Analysis --> VectorPath["Vector Retrieval Path\n(Dense Embedding Search)"]
Analysis --> GraphPath["Graph Traversal Path\n(Multi-Hop Graph Queries / Neighbors)"]
VectorPath --> VectorChunks[("Vector Knowledge Store\n• Top-K Text Chunks\n• Semantic Passages")]
GraphPath --> GraphContext[("Knowledge Graph Store (Neo4j)\n• Entity Subgraphs\n• Explicit Dependencies & Hierarchy")]
VectorChunks --> Fusion["Context Fusion & Deduplication Engine\n(Interweaves Structural Graph Facts + Text Chunks)"]
GraphContext --> Fusion
Fusion --> Prompt["Enriched Augmented Prompt\n(System Rules + Graph Triples + Text Grounding)"]
Prompt --> LLM["Frontier LLM Generator"]
LLM --> Answer["Structurally Aware Grounded Response\n(Multi-Hop Reasoning + Source Citations)"]
39.3 Combining Vector Search With Graph Retrieval — Step by Step
Step 1 — Query analysis. Use the LLM to extract entities and intent from the query (e.g., “What happens to order processing if Redis goes down?” → entities: [Redis, order processing], intent: impact analysis).
Step 2 — Parallel retrieval. Vector path: embed the query, search the vector DB, retrieve top-K relevant chunks. Graph path: locate the entity node(s), traverse relevant relationships (e.g., DEPENDS_ON), collect connected entities and their documentation.
Step 3 — Context fusion. Merge vector results (specific document content) with graph results (structural context); de-duplicate overlapping information; prioritize graph context for structural questions and vector context for detailed explanations.
Step 4 — Augmented generation.
System prompt: You are an infrastructure expert. Use the following context
to answer the user's question.
Document Context (from vector search):
[Retrieved chunks about Redis configuration, order processing architecture]
Structural Context (from graph):
- Redis is a dependency of: OrderService, CartService, SessionService
- OrderService also depends on: PaymentGateway, InventoryService
- Redis is deployed on: k8s-cluster-us-east-1
- Redis owner: Team Platform
Question: What happens to order processing if Redis goes down?
This combination lets the LLM give a detailed, technically grounded answer and structural awareness that neither retrieval mode achieves alone.
Section 39 — Interview Q&A
Q1: Explain how you would combine vector search with graph retrieval for a Q&A system, end to end. Extract entities and intent from the query using the LLM. Run vector search and graph traversal in parallel — vector search returns relevant document chunks, graph traversal returns the structural neighborhood of the identified entities (dependencies, ownership, recent changes). Fuse the two: deduplicate overlap, use graph context to answer “what’s connected to what” and vector context for detailed narrative explanation, then pass the combined, labeled context to the LLM for generation. This gives multi-hop reasoning (via the graph) that pure vector similarity search structurally cannot provide, because vector search only ever finds documents that are textually similar to the query, not documents that are structurally connected to the entities in the query.
Q2: Why can’t vector search alone answer a multi-hop “blast radius” style question well? Vector search retrieves by semantic similarity to the query text — it will find documents that mention the entity in question, but has no notion of transitive relationships. A question like “what’s affected if X goes down” requires walking a dependency chain multiple hops deep, which is a structural graph-traversal operation, not a similarity-search operation. Even with a very good embedding model, similarity ranking degrades sharply past 1-2 conceptual hops because indirect relationships aren’t captured in the text of any single document.