Brain Docs
Learn

Why memory exists

Why agents forgetWhy a bigger window doesn't fix itWhy RAG isn't memory

What a memory is

What a memory isThe statement kindsWhen facts collide

How it answers

How recall decidesDecay and retention

Using it well

What to write, and what not to

Reference

Brain/Docs
✦ ASKBrain on GitHubDashboard
LearnWhat to write, and what not to

What to write, and what not to

The judgement call every memory deployment gets wrong at least once — plus exactly which duplicates the database collapses for you, and which ones it lets through.

PURPOSE

With a vector store the answer is obvious: your documents. With a memory layer it genuinely isn't, and getting it wrong is the main way these deployments fail.

The stakes, measured

This is not a style question. In a published 32-day production audit of a Mem0 deployment, 97.8% of stored memories were junk — hash duplicates, hallucinated profiles, and feedback-loop contamination where the system's own output was read back in as fact. Harvard's D3 research points the same way: aggressive pre-store filtering is essential to memory-system quality.

The lesson generalises past any one system:

Retrieval quality has a ceiling set by what you admitted. No amount of fusion, reranking or tuning recovers from a store full of duplicates and self-generated claims.

The three failure categories in that audit are worth separating, because they have different fixes:

What was storedWhy it got thereWhat prevents it
Hash duplicatesThe same content written repeatedlyContent dedup — handled for you, but only for byte-identical text
Hallucinated profilesModel output written back as observationA rule in your code about what is eligible to be written
Feedback-loop contaminationThe system's own output read back as factThe same rule, plus never writing from the assistant turn

Only the first has a database-side answer. The other two are policy decisions that no store can make on your behalf, because both produce perfectly well-formed sentences about real subjects.

Which is why this page exists and why it is the last one in the section — it is the decision that determines whether everything upstream of it matters.

The two failure modes

Write everything. Every user message, every assistant reply, straight in. Recall degrades into a noise generator, because now a thousand memories match every query and the signal is buried under chatter, pleasantries and the agent quoting itself. Costs rise with volume and quality falls with it.

Write nothing until you're sure. Teams burned by the first failure swing to writing only carefully curated facts behind a manual gate. Now the agent knows almost nothing, the gate is a maintenance burden, and you've rebuilt a database with extra steps.

The target between them is narrower than it looks, and it has a usable test.

The test

Would a competent colleague, picking up this conversation next week, want to know this?

That's it. It's a question about durability and subject, not importance. It rejects "thanks, that worked" and accepts "they're on Postgres 14, not 16" even though the second sounds minor — it's durable and it's about something.

Two failure modes of the test itself, since people apply it too loosely in one direction and too strictly in the other. It is not "would this be interesting" — interesting is a property of the moment, durable is a property of the claim. And it is not "am I certain this is true" — a claim you are unsure about is still worth writing, because confidence is a field with evidence behind it rather than a bar for admission. Write it and let the confidence be low; that is strictly better than the claim not existing, which reads downstream as nobody ever said this.

Write these

WriteExample
Stable facts about a subjectTheir production database is Postgres 14
Preferences and constraintsThey want terse answers with no preamble
Decisions and their reasonsChose Redis over Memcached for persistence
Events with a timeMigrated to the new billing plan in March
Corrections the user makesActually it's the EU region, not US

That last row is the highest-value thing you can write and the most often missed. A correction is the user telling you your memory is wrong. It should become a memory immediately — that is what gives supersession something to work with.

Don't write these

Do not writeWhy not
Whole transcriptsConversational filler drowns the few durable claims inside it
The agent's own speculationIt becomes a fact on the next turn, and now it's cited
Secrets, tokens, card numbersYou'll need them gone and won't know every place they landed
Ephemera"Running the tests now" is false in ten minutes
Things you can look upCurrent order status belongs in your database, not your memory

The last row has an edge case worth naming: write the decision even when the state lives elsewhere. "They're on the Enterprise plan" belongs in your billing database. "They chose Enterprise because of the SSO requirement" belongs in memory, because no system of record stores the reason and the reason is what the agent needs next time.

Writing the model's own output back as memory is the one that bites hardest, and it is the exact mechanism behind the "feedback-loop contamination" in the audit above. The agent speculates, the speculation is stored, it is recalled next turn as established context, and it hardens — with a provenance chain that honestly reports the source as your own system. Write what the user asserted, or what your system verified — not what the model guessed.

What the database dedups, and what it doesn't

This matters more than most people expect, because the protection is real but narrower than the name suggests.

Byte-identical text is collapsed, always. Content deduplication is a database policy on text encode, not a client flag you can forget to set. Before allocating a slot, Brain checks a fingerprint index keyed on BLAKE3(text), scoped per (shard, space, session). On a hit you get the existing memory_id back with was_deduplicated = true, and no new slot, no WAL record and no index node are created. Re-saving the same sentence in a retry loop costs you nothing and leaves one row.

That is distinct from request_id idempotency, which dedups exact replays by request identity. One is content identity, the other is request identity, and you want both.

Near-duplicates are not collapsed at write time. A paraphrase, or the same fact restated in different words, is not byte-identical — so it is admitted as its own memory. Those are reconciled later, asynchronously, by the near-duplicate consolidation worker.

The practical consequence: writing "They prefer dark mode" on every turn that mentions theming will pile up rows, because no two turns phrase it identically. The fingerprint index will not save you. The turn-level decision about whether to write is still yours, and it is the one doing the real work.

Sessions are the other half of the decision

What to write has a companion question — where — and the answer is the session, which is the one piece of grouping a memory carries.

It matters more than it looks because three mechanisms key off it. Content dedup is scoped per (shard, space, session), so the same sentence in two sessions is two memories by design. The surprise term in initial salience is measured against the centroid of the last hundred memories in that session, so what counts as novel is session-relative. And consolidation clusters within a session, never across.

The practical consequence: a session should be a coherent unit of work — one conversation, one task, one ticket. Put a week of unrelated interactions in one session and novelty detection stops discriminating, because the centroid is an average of everything. Open a new session per turn and consolidation never has five related memories to cluster, and dedup never catches a repeat.

A memory belongs to exactly one session, and the field is not a tag — there is no multi-attach and no arbitrary metadata map to lean on instead. Structured attributes belong on entities and statements, which the typed graph queries directly. If you are reaching for a tag, you probably want a predicate.

Write sentences, not schemas

Hand Brain natural language. Don't pre-structure it into JSON.

✓  "Priya moved from billing to the platform team in June."
✗  {"subject":"priya","predicate":"team","object":"platform"}

Extraction resolves the entities, types the claim and sets the validity interval. Doing it yourself means maintaining an extraction pipeline, and losing the original sentence the evidence chain should point back at.

One claim per memory is a reasonable default, but don't fight the text. If a sentence naturally carries two facts, write the sentence — extraction will produce two statements from it, each citing the same memory as evidence.

Pass the time separately

If the content is about a moment, put that moment in occurred_at rather than only in the prose:

text:        "Migrated to the new billing plan."
occurred_at: 2026-03-14T09:00:00Z

A date inside the sentence is a string the embedder blurs. A date in occurred_at is a number the pipeline sorts on, survives crash recovery through the WAL, comes back on every recall, and is what the recency boost reads. Without it the only timeline Brain has is the order you happened to write things in.

What happens to your sentence after the ack

Knowing the pipeline changes what you write, so it's worth the two minutes.

Extraction runs after the write is acknowledged, in a per-shard worker — so none of what follows widens the latency of your encode call. It runs three tiers, cheapest first, each screening work away from the next:

OptionTypeDefault / Env
Pattern~10–100 µs, deterministic, free

Compiled regexes over the text, emitting entity, statement or relation mentions with a fixed confidence. Same input, same output, every time.

Classifier~5 ms p50, pinned model

A small zero-shot NER model with a statement-kind head sharing one encoder pass — so deciding this mentions a person and this is a Preference costs one forward pass, not two. This tier existing is what keeps the LLM off the common path.

LLMexpensive, residual only

Handles what the first two couldn't disambiguate. Cached on (input, extractor, version, model) so the same text doesn't pay twice.

Then every mention goes through a four-tier resolution gauntlet to decide which entity it refers to:

TierMatchCatches
1Exact normalised name or registered aliasThe easy case
2Trigram overlap ≥ 0.85Typos, minor surface variation
3Embedding similarity ≥ 0.78"Acme Inc" ≈ "Acme, Inc."
4LLM tie-break — opt-in, default offGenuine ambiguity, with surrounding text

Three outcomes: resolved to an existing entity, created as a new one, or ambiguous — and ambiguous means no link is written and the extraction is recorded as skipped.

That last outcome is the one your writing style controls. A sentence whose subject is a bare pronoun — "she prefers the EU region" — gives the resolver a span with almost no signal: no name to match exactly, nothing for trigrams to grip, and an embedding that is close to every other pronoun in the space. The likely result is an ambiguous resolution and no statement at all.

The memory is still stored and still recallable. But the structured claim you wanted never existed, and nothing errored to tell you so. Name the subject in the sentence you write, even when it reads redundantly against the conversation it came from — the sentence has to stand alone, because by the time it is read the conversation is gone.

When to write

Writing on every turn is usually wrong — most turns contain nothing durable. Two patterns that work:

  • On signal. Write when the user states a preference, corrects something, or makes a decision. Cheap, precise, and what most agents need.
  • At session end. Pass the conversation through a summarising step and write what it distils. Costs a model call, catches things a turn-level rule misses.

Either beats writing continuously, and both beat a manual gate.

Sizing the two against each other

The on-signal rule is cheap and has a recall problem: it fires on explicit statements and misses things inferred across several turns. Session-end summarisation has the opposite profile — it sees the whole arc, and it costs a model call plus the risk that the summariser itself speculates.

A combination most teams converge on: write on signal during the session, then run a session-end pass that writes only what the turn-level rule didn't catch. That bounds the summariser's output to the gap rather than letting it restate everything, which both halves the cost and removes most of the duplicate-writing problem — a summary that re-asserts six things already written is six near-duplicates the fingerprint index won't collapse.

Whichever you pick, write the user's phrasing rather than your summariser's where you can. A verbatim claim keeps the evidence chain honest — the memory says what was actually said — and it is the version a human reviewing a data-subject request can verify. A paraphrase is already an interpretation with no record of what it interpreted.

The engine pushes back too

Extraction fires automatically after every successful encode, on the same shard, running all three tiers asynchronously — pattern matcher, then a zero-shot classifier, then an LLM. It never blocks your write.

Low-signal content is gated there: it is kept as a memory, but not promoted into the typed graph. You get a record of what was said without polluting the structure answers are built from.

That is a backstop, not a strategy. The gate catches noise. It cannot tell that you wrote the model's hallucination instead of the user's statement, because both are well-formed sentences about a real subject — and the hallucination will extract cleanly into a statement with full provenance pointing at your own agent. The filter that matters is the one in your code, before the call.

Try it

Run Low signal in the playground and watch the extraction station produce nothing.

Then write the same sentence twice, byte for byte, and watch the second write come back was_deduplicated. Then write it a third time with two words changed, and watch a second memory appear. The gap between those two behaviours is the one your write policy has to cover.

Finally, write one with a bare pronoun as the subject — "she prefers the EU region" — and check the graph. The memory is there; the statement probably isn't. That silent gap between "stored" and "structured" is the single most useful thing to have seen once before you write your ingest code.

See also
How recall decidesDrop it into an existing loopHandling corrections

Was this page helpful?

Decay and retention

Salience decays on a kind-dependent half-life, superseded claims close off, tombstones reclaim after a grace period — three mechanisms, three different meanings of "forget".

Build

Task recipes for an agent you have already written — wiring in recall, handling corrections, combining with RAG, isolating tenants, and erasing a subject.

On this page

The stakes, measuredThe two failure modesThe testWrite theseDon't write theseWhat the database dedups, and what it doesn'tSessions are the other half of the decisionWrite sentences, not schemasPass the time separatelyWhat happens to your sentence after the ackWhen to writeSizing the two against each otherThe engine pushes back tooTry it
Suggest an editOpen in Playground