Lesson 56.1 · 1 of 4 · 4 min read · Reviewed 24 Nov 2026
Vector databases
By the end, you can
- Explain when a vector database fits agent memory.
- Store memories as embeddings with metadata.
Chapter 4 explains embeddings: numbers that place texts with similar meaning close together. A vector databaseVector database: A database built to store embeddings and find the nearest ones to a query quickly. stores them and finds the nearest ones to a query.
save: "Customer upset about invoice error in March"
--> embed --> [0.12, -0.40, ...] + metadata {user: C-2201, date: 2026-03-14, type: episode}
query: "billing problems" --> embed --> nearest vectors --> top 3 memories
Good fits
- Summaries of past conversations (episodic)
- Notes and learned facts in free text (semantic)
- Documents and knowledge bases (Part 4 covers RAGRetrieval-augmented generation (RAG): Retrieving relevant documents at request time and adding them to the prompt so the answer is grounded in them.)
Metadata matters
Store with every vector:
| Field | Use |
|---|---|
| owner (user, tenant) | Never return another user’s memory |
| type | Episode, fact, preference |
| created, last used | Ranking and expiry (57.4) |
| source | Where it came from, for trust |
Filter on owner before similarity search, not after. Chapter 22 explains how vector stores combine filters with search.
Limits
Vector search finds similar text, not exact facts. “What’s the user’s plan?” should be a database lookup (56.2), not a similarity search that might return an old note.
Key points
- A vector database stores embeddings and finds items by meaning, not exact words.
- Good for large, fuzzy memory: past conversation summaries, notes, documents.
- Always store metadata (user, date, type) alongside vectors so you can filter and expire memories.
Store memories in a local vector database
Run a vector database on your own machine, store memory summaries with owner and date metadata, and query them with an owner filter applied before similarity.
You will have: A script that adds ten memories for two users and prints the top 3 matches for one user's query, with metadata.
Steps
- Create a virtual environment and install a local vector store, for example: pip install chromadb (pgvector in Postgres works too).
- Create a collection and add ten short memories, each with metadata: owner, type, created date and source.
- Query 'billing problems' with a where filter on owner = C-2201 and n_results = 3.
- Print each result with its distance and metadata, then repeat the query without the filter and compare.
- Delete one user's memories with a single filtered delete call and confirm the count.
Done when
- Filtered results only ever include C-2201's memories.
- A memory saying 'invoice error' is returned for 'billing problems'.
- After the filtered delete, that user has 0 memories left.