Guide · 5 min read
Vector database vs knowledge graph for agent memory
Where to store AI agent memory: vectors, a knowledge graph, plain tables or a mix. What each is good at, what each misses, and how to choose for your case.
The store shapes what your agent can recall. There are three common choices and most real systems end up with two of them.
Vectors: search by meaning
Each note is turned into an embedding. At recall, the question is embedded too, and the nearest notes are returned.
Good at: fuzzy matches. “Where should we eat?” finds “is vegetarian” although no word is shared.
Weak at: exact terms such as names, product codes and numbers; anything involving time (“the latest”); and questions that need two facts joined together.
Improve it with: hybrid search (add keyword matching), metadata filters (scope, date, type) and a reranking step on the top results.
Knowledge graph: search by relationship
Facts are stored as entities and links: Maya — works at — Acme, Ana — sister of — Maya.
Good at: questions that follow links, keeping one record per entity, and updating a fact in exactly one place.
Weak at: setup cost. Something has to extract entities and relations reliably and decide when “Ana”, “her sister” and “A. Silva” are the same person. Loose, nuanced statements do not always fit a triple.
Plain tables or documents: exact lookup
A profile record with named fields, or a short text file of facts per user.
Good at: values that must be exact and always present: name, plan, language, timezone. Easy to show to the user and easy to edit.
Weak at: anything you did not plan a field for.
Side by side
| Vectors | Graph | Tables | |
|---|---|---|---|
| Finds by | Meaning | Relationship | Key |
| Setup | Low | High | Low |
| Exact values | Poor | Good | Best |
| Multi-step questions | Poor | Best | Poor |
| Unplanned facts | Best | Fair | Poor |
How to choose
- Start with a profile record for the handful of facts every answer needs, plus a vector index of notes for everything else.
- Add keyword search as soon as users ask about names or codes.
- Add a graph when you see questions failing because they need two linked facts.
Whichever you choose, every query must be filtered by scope before anything else. Search across all users and then filter, and one day a memory will reach the wrong person.