Vector search is the default way to give an agent knowledge. You chunk your documents, embed them, and retrieve the chunks closest to the question. It works well for "what does the travel policy say about hotels?" It struggles with "which customers are affected if this supplier's plant shuts down?", because that answer isn't in any single chunk. It's spread across a chain of facts, and similarity search has no way to follow the chain. A knowledge graph for AI agents stores those facts as connected entities, so the agent can follow them.
Whether that structure is worth building depends on the questions your agent faces, and the research includes results that favour plain retrieval as well as graphs. The sections below cover that evidence, graph memory and the real costs. It's part of a series on the context layer for AI. The series overview on the context layer explains where relationships fit alongside metrics, metadata and policies.
What a knowledge graph gives an agent
A knowledge graph stores entities as nodes and typed relationships as edges, with properties on both. "Acme Pumps SUPPLIES Valve V-20" is one edge. "Valve V-20 PART_OF Cooling Unit C7" is another. The structure is the point: the agent can traverse from a supplier to the parts it makes, to the products those parts go into, to the customers who ordered them.
An ontology defines the types and rules, such as "a Supplier SUPPLIES a Part." The knowledge graph holds the actual facts. Our ontology series explains the difference between a taxonomy, an ontology and a knowledge graph if the terms blur together.
Where vector search falls short
Vector search answers "which chunks look like this question?" That fails in three situations.
Multi-hop questions. If the answer needs two or more linked facts, each fact may sit in a different document, and none of them looks much like the question. The supplier question above needs four hops.
Global questions. "What are the main themes across these 2,000 support tickets?" has no single relevant chunk. Retrieving the top ten tells you about ten tickets.
Exact relationships and counts. "How many active contracts does this customer have?" needs an exact answer over structured facts. Similar text doesn't give you a count.
| Question type | Vector search | Knowledge graph | Hybrid | |---|---|---|---| | Answer sits in one passage | Good fit | Usually unnecessary | Good fit | | Answer spans linked facts in several sources | Weak | Good fit | Good fit | | Summary across a whole corpus | Weak | Good fit with community summaries | Good fit | | Exact counts and relationships | Weak | Good fit | Good fit |
Vector search is still the right tool for finding passages by meaning, for questions answered within one document, and for fuzzy matching where you don't know the exact terms. The question isn't which one wins in general. It's which questions your agent needs to answer.
What the research shows
The evidence for graphs is real, and so is the evidence against using them everywhere.
Global questions: GraphRAG. Microsoft Research's GraphRAG paper uses an LLM to extract an entity graph, groups entities into communities and summarizes each one. On whole-corpus questions over podcast transcripts and news, its global methods beat vector RAG on comprehensiveness in 72% to 83% of head-to-head comparisons. Root-level community summaries also used over 97% fewer tokens than summarizing the source text directly.
Enterprise data: SQL vs graph. A 2023 data.world study found GPT-4 answered 16% of business questions correctly over a SQL schema and 54% over a knowledge graph representation of the same database. Models have improved since, and the study comes from data.world, which sells knowledge graph products, so read it as a direction.
Hybrid retrieval. The HybridRAG paper combined graph and vector retrieval on financial earnings call transcripts and reported that the combination beat either one alone.
The counter-evidence. The GraphRAG-Bench study, accepted at ICLR 2026, reports that GraphRAG "frequently underperforms vanilla RAG on many real-world tasks." A 2025 systematic comparison found each approach wins on different task types, and that choosing between them or combining them gave gains.
The fair summary: graphs have the strongest evidence on global and relationship-heavy questions, while benchmarks such as GraphRAG-Bench show them losing to plain retrieval on many everyday tasks. If most of your agent's questions are "find the paragraph that answers this," a graph adds cost without adding accuracy.
A worked example: a multi-hop lookup in Python
Here's the supplier question as a small graph in networkx. It's deliberately tiny so you can see the traversal.
import networkx as nx
g = nx.MultiDiGraph()
facts = [
("Acme Pumps", "SUPPLIES", "Valve V-20"),
("Acme Pumps", "LOCATED_IN", "Plant Rotterdam"),
("Valve V-20", "PART_OF", "Cooling Unit C7"),
("Cooling Unit C7", "PART_OF", "Product Atlas"),
("Product Atlas", "ORDERED_BY", "Northwind Retail"),
("Product Atlas", "ORDERED_BY", "Contoso Foods"),
("Beta Seals", "SUPPLIES", "Gasket G-4"),
("Gasket G-4", "PART_OF", "Product Orion"),
("Product Orion", "ORDERED_BY", "Contoso Foods"),
]
for src, rel, dst in facts:
g.add_edge(src, dst, rel=rel)
def affected_customers(graph, supplier):
"""Follow SUPPLIES -> PART_OF* -> ORDERED_BY from a supplier to its customers."""
paths = []
for part in [d for _, d, r in graph.out_edges(supplier, data="rel") if r == "SUPPLIES"]:
frontier = [[supplier, part]]
while frontier:
path = frontier.pop()
for _, nxt, rel in graph.out_edges(path[-1], data="rel"):
if rel == "PART_OF":
frontier.append(path + [nxt])
elif rel == "ORDERED_BY":
paths.append(path + [nxt])
return paths
for p in affected_customers(g, "Acme Pumps"):
print(" -> ".join(p))
Output:
Acme Pumps -> Valve V-20 -> Cooling Unit C7 -> Product Atlas -> Northwind Retail
Acme Pumps -> Valve V-20 -> Cooling Unit C7 -> Product Atlas -> Contoso Foods
The function follows SUPPLIES to the part, then any number of PART_OF edges up the bill of materials, then ORDERED_BY to customers. It returns the full path, which the agent can show as its reasoning. On real data, add a visited set or a hop limit, because a cycle in the PART_OF edges would make this loop forever. Contoso Foods also buys Product Orion, but that comes from a different supplier, so it isn't reached through Acme.
In a graph database you'd write the same question as one query. Here it is in Cypher (the ISO GQL standard published in 2024 is similar but not identical):
MATCH path = (s:Supplier {name: $supplier})-[:SUPPLIES]->(:Part)
-[:PART_OF*1..5]->(:Product)-[:ORDERED_BY]->(c:Customer)
RETURN c.name, path
An agent gets this ability as a tool, typically from an MCP server in front of the graph store. The article on the Model Context Protocol shows how such tools are defined.
The hybrid pattern most teams end up with
In practice, a knowledge graph for AI agents rarely replaces vector search. The two work as stages:
- Find entry points with vector search or keyword search. "Problems with the Rotterdam plant" finds chunks that mention Acme Pumps and Plant Rotterdam.
- Link mentions to graph nodes. This is entity resolution, covered next.
- Expand one to three hops through the graph from those nodes.
- Pass the subgraph and the source chunks to the model, so it has both the structure and the original text to quote.
Keep the hop limit low. Each hop can multiply the number of nodes, and a 5,000-node subgraph in the prompt is a context problem of its own. The techniques in context engineering for AI agents apply: select, compress, and keep only what the step needs.
Entity resolution: the step everyone underestimates
A graph is only as connected as its entities. If one source says "IBM", another says "International Business Machines" and a third says "IBM Corp.", and they become three nodes, every path through that company breaks into three pieces. Counts come out wrong and multi-hop questions miss answers.
Entity resolution merges mentions that refer to the same real-world thing into one node. It's an engineering problem more than a research one, and a common place for graph projects to stall. Practical tactics:
- Resolve against a master list where one exists, such as a customer master or a product catalog.
- Use stable identifiers, such as tax IDs or SKUs, over names whenever you can.
- Combine exact rules, fuzzy matching and an LLM check for the ambiguous cases, and send low-confidence merges to a person.
- Keep the original mention on the node, so you can audit and undo a bad merge.
For enterprise data, entity resolution also connects the graph to your warehouse. A Customer node should carry the same customer ID your semantic layer uses, so an agent can move from "which customers are affected?" to "what's their revenue?" without guessing. The dbt Semantic Layer for AI agents tutorial covers the metric side of that handoff.
Do you need a graph database?
Not always. For a few thousand entities and short traversals, a relational database with an edges table and recursive SQL works, and Postgres with the pgvector extension can hold the embeddings in the same place. That leaves one system to run and back up.
A dedicated graph database earns its place when traversals get deeper and more varied, when the graph has millions of edges, or when you want a query language built for paths. Neo4j, Amazon Neptune and FalkorDB are common choices, and Graphiti supports all three as backends. The GQL standard should also make queries more portable between graph databases over time.
A sensible path is to prototype in whatever you already run, measure on real questions, and move to a graph database only when queries get slow or awkward to write.
How do you build the graph?
There are two main routes, and most projects use both.
From structured data. Customers, orders, products and suppliers already sit in tables with keys. Mapping them to nodes and edges is mostly deterministic, cheap and accurate. Start here.
From text with an LLM. Contracts, tickets and reports hold relationships that never made it into a table. LLM extraction can pull them out, but it costs money per document and makes mistakes. Constrain it with an ontology, validate the output, and send uncertain facts for review. The article on ontologies and LLMs covers that validation loop.
Building from structured data first gives you a reliable backbone. Text extraction then adds edges to it, rather than inventing a parallel graph.
Knowledge graphs as agent memory
Graphs also show up as long-term agent memory, because facts about users and the world change, and a graph can record when.
Zep's Graphiti engine is a temporally aware knowledge graph. Each fact has validity dates, and when a new fact contradicts an old one, the old one is marked invalid rather than deleted. That means the agent can answer "where did this customer work last year?" as well as "where do they work now?" In its own paper, Zep reports 94.8% on the Deep Memory Retrieval benchmark, against 93.4% for MemGPT.
Mem0's 2025 paper is a useful reality check. Its graph-based variant added only about 2% over its non-graph memory on the benchmark it reported. For simple user preferences, a key-value store is often enough. Graph memory pays off when relationships and changes over time are the point.
What a graph costs
Graphs aren't free, and the costs are easy to underestimate.
- Construction. LLM extraction over a large corpus is expensive, and full GraphRAG indexing more so. Microsoft's LazyGraphRAG cut indexing cost to the level of vector RAG, about 0.1% of full GraphRAG, by deferring work to query time.
- Schema design. Without an ontology, extracted graphs fill up with inconsistent relationship types. The ontology-driven GraphRAG article covers constraining extraction with an ontology.
- Maintenance. Facts change. Someone has to update, invalidate and re-resolve them, or the graph drifts out of date.
- Skills. Cypher, SPARQL or GQL, graph modeling and graph database operations are skills many data teams don't have yet.
When a knowledge graph for AI agents is worth it
Build one when:
- Your agent's important questions are multi-hop, such as supply chains, org structures, dependencies or fraud rings.
- You need whole-corpus summaries that top-k retrieval can't give.
- You need answers that come with an explainable path.
- Facts change over time and you need to know what was true when.
Skip it, for now, when:
- Most questions are answered within one document.
- Your structured data already sits in a warehouse with good joins, where a semantic layer is the better fit. See context layer vs semantic layer for that trade-off.
- You can't commit anyone to entity resolution and maintenance.
For how data platforms package entities and relationships for agents, see Snowflake Horizon Context vs Microsoft Fabric IQ. For where a graph sits in the overall plan, see how to build a context layer for AI.
Measuring whether the graph helped
Run the same set of real questions through vector search alone and through the hybrid setup, and compare. Split the results by question type: single-fact lookups, multi-hop questions and summary questions. If the graph helps only the multi-hop group, route only those questions through it and keep vector search for the rest. One 2025 comparison found that choosing the method per question improved results, and routing keeps the cost of a knowledge graph for AI agents tied to the questions that need one.
Common mistakes
- Assuming GraphRAG beats RAG everywhere. Recent benchmarks show it frequently underperforms plain RAG on many real-world tasks.
- Skipping entity resolution. Duplicate nodes break paths and inflate counts.
- Extracting without a schema. You get hundreds of near-duplicate relationship types.
- Overwriting facts. Give them validity dates instead.
- Unbounded traversals. Cap the hops and the subgraph size.
- Treating vendor benchmarks as independent. Several of the graph memory papers come from the companies selling the products.
Key takeaways
- A knowledge graph for AI agents stores connected facts, so the agent can answer multi-hop, global and relationship questions that vector search can't.
- The research supports graphs for those question types and shows they often lose on simple fact lookup. Match the tool to the questions.
- Most production systems are hybrid: vector search finds entry points, entity resolution links them to nodes, and a short traversal adds structure.
- Entity resolution and maintenance are the real costs. Budget for them before you build.
- Graphs make good agent memory when relationships and change over time matter. For simple preferences, simpler stores work.