Alongside your RAG
Documents and memory answer different questions — keep both, route the query to the right one, and let each do the job the other structurally cannot.
The split
Neither substitutes for the other. Chunked docs can't track that a customer changed plans; memory isn't where your 40-page policy belongs.
Run both, merge at the prompt
The simplest integration, and usually the right one:
const [docs, answer] = await Promise.all([
vectorStore.search(userMessage, { topK: 4 }),
brain.recall({ query: userMessage, maxResults: 5 }),
]);
const prompt = [
systemPrompt,
answer.answerKind !== "none"
? `About this customer:\n${answer.memories.map(m => `- ${m.text}`).join("\n")}`
: "",
docs.length ? `Reference material:\n${docs.map(d => d.text).join("\n\n")}` : "",
userMessage,
].filter(Boolean).join("\n\n");docs, answer = await asyncio.gather(
vector_store.search(user_message, top_k=4),
brain.recall(query=user_message, max_results=5),
)
parts = [SYSTEM_PROMPT]
if answer.answer_kind != "none":
parts.append("About this customer:\n" + "\n".join(f"- {m.text}" for m in answer.memories))
if docs:
parts.append("Reference material:\n" + "\n\n".join(d.text for d in docs))
parts.append(user_message)
prompt = "\n\n".join(parts)They're independent, so run them concurrently — the added latency is the slower of the two, not the sum.
Label the blocks differently
This matters more than the retrieval. Keep the two sources visibly separate in the prompt, with headers that say what each is.
A model handed one undifferentiated blob of context treats a policy document and a thing the customer said last Tuesday as equally authoritative. They are not. Reference material is authored and stable; memory is observed and revisable. If they conflict — the docs say 30-day refunds, memory says this customer was granted 60 — you want the model to see that as two different kinds of claim, not as one contradiction to resolve by coin flip.
Say which wins. A line like "Reference material is authoritative on policy; customer memory is authoritative on this account's history and state" removes the ambiguity for a few tokens.
When not to run both
If recall returns None and the question is plainly a documentation question,
skip the memory block entirely rather than emitting an empty header. And for
agents that only answer from docs with no per-user state, you don't need memory
at all — use the thing that fits.
Don't copy your docs into memory
A tempting shortcut that goes badly. Documents are long, authored, and non-contradicting; memory is tuned for short, observed, revisable claims about subjects. Loading a corpus of chunks in gives you a worse vector store and floods extraction with content that has no subject.
The exception is a genuine observation derived from a document — "this customer's contract allows 60-day refunds" is a claim about a customer, and it belongs in memory even though it came from a PDF.
Telling the two apart at answer time
The useful property is that memory can cite. A recall hit carries the memory id it came from, and the typed claims extracted from it carry evidence back to that memory. A retrieved document chunk carries only the chunk.
So when an answer mixes both, you can show the user where the personal half came from and let them correct it — which is the loop that makes memory get better over time and leaves RAG exactly as good as its corpus. See Faithfulness checking for the mechanics.
A correction only works on one of them
If the user says "no, we're on the annual plan now", that is a correction to memory, and supersession handles it: encode the new claim and the old one is closed off in time. There is no equivalent move for a document chunk — the corpus is authored elsewhere and a user cannot revise it through your agent.
Route corrections to memory, and leave the corpus to its own pipeline. An agent that tries to "correct" RAG by writing the correction into memory and continuing to retrieve the stale chunk will contradict itself on the next turn.
Was this page helpful?
Handling corrections
When a user says "actually, no" — the highest-value write an agent can make, and why it needs no special API, only a timely encode.
One space per customer
Namespace is the hard boundary, space is the isolation unit, and a trusted backend selects a tenant's space with act_as — a wire-tier capability the HTTP API does not have.