Lesson 56.4 · 4 of 4 · 4 min read · Reviewed 24 Nov 2026
Choosing a store
By the end, you can
- Choose a store for each kind of memory.
- Combine stores in one agent.
A decision table
| Memory | Question it answers | Store |
|---|---|---|
| Preferences, settings | “What does this user want?” | Key-value or table |
| Account and order facts | “What’s true right now?” | System of record via tools |
| Session state | “Where are we in this task?” | Key-value with expiry |
| Past conversation summaries | “Have we discussed this before?” | Vector store with metadata |
| Project conventions | “How do we do things here?” | Files (CLAUDE.md, skills) |
| Agent working notes | “What have I found so far?” | Files or memory tool |
| Entities and relationships | “How is A connected to B?” | Graph (chapter 25) |
Start simple
Many agents need only a table of preferences and a notes file at first. Add a vector storeVector database: A database built to store embeddings and find the nearest ones to a query quickly. when:
- Memories number in the thousands per user or project, and
- Users ask about things in ways you can’t predict by key.
One agent, several stores
start of session:
prefs <- key-value (exact)
account <- tool call to the real system
episodes <- vector search on summaries, top 3
procedure <- skill or prompt
during:
notes <- memory tool
end:
summary -> vector store
new prefs -> key-value
Each store is reached through a narrow tool, with the user’s id enforced in code.
Key points
- Match the store to the question: exact lookups to key-value or SQL, fuzzy recall to vectors, curated notes to files.
- Systems of record stay the source of truth; memory holds what they don't.
- Start simple; add a vector store only when you have enough memory that search is needed.
Route memory questions to the right store
Write a router that sends each memory question to the store that fits it: key-value, system of record, vector search, files or a graph.
You will have: A route function, a table of routed questions, and a score against the expected answers.
Steps
- Read the sample QUESTIONS and their expected store.
- Write route(question) using simple keyword rules for each kind of question.
- Print each question with the chosen store and a tick or cross.
- Print the score, then add one new question of your own for each store and check it still routes correctly.
Done when
- All 6 sample questions route to the expected store.
- Live facts (plan, balance, orders) always go to the system of record.
- The router prints a final score line.
Open in the Playground No API key needed.
Starter code (Python)
QUESTIONS = [
("What tone does this user like?", "key-value"),
("What plan is the account on right now?", "system of record"),
("Have we talked about invoice errors before?", "vector search"),
("How do we run the release checklist here?", "files"),
("Which team owns the service that calls billing?", "graph"),
("Where are we in this refund task?", "key-value"),
]
def route(q):
q = q.lower()
# TODO: return one of: key-value, system of record, vector search, files, graph
return "vector search"
score = 0
for q, want in QUESTIONS:
got = route(q)
score += got == want
print("%-48s %-18s %s" % (q, got, "ok" if got == want else "WRONG, want " + want))
print("score: %d/%d routed correctly" % (score, len(QUESTIONS)))
Show a solution
QUESTIONS = [
("What tone does this user like?", "key-value"),
("What plan is the account on right now?", "system of record"),
("Have we talked about invoice errors before?", "vector search"),
("How do we run the release checklist here?", "files"),
("Which team owns the service that calls billing?", "graph"),
("Where are we in this refund task?", "key-value"),
]
RULES = [
("system of record", ["right now", "plan", "balance", "order status"]),
("graph", ["owns", "connected", "calls", "depends on"]),
("files", ["how do we", "checklist", "convention"]),
("key-value", ["like", "prefer", "where are we", "this task"]),
("vector search", ["before", "talked about", "remember when"]),
]
def route(q):
q = q.lower()
for store, words in RULES:
if any(w in q for w in words):
return store
return "vector search"
score = 0
for q, want in QUESTIONS:
got = route(q)
score += got == want
print("%-48s %-18s %s" % (q, got, "ok" if got == want else "WRONG, want " + want))
print("score: %d/%d routed correctly" % (score, len(QUESTIONS)))
Finished the chapter? Take the chapter check.