Repository navigation
fix(memory): keep a different fact that shares most of a memory's words - #6902
Conversation
Storing "My mother-in-law's name is Miriam." silently overwrote "My
mother's name is Elena.": dedup merged any two facts with 80% word
overlap and replaced the old content in place.
Dedup now merges only a true duplicate: one fact's words, in order and
ignoring filler like "the", "is" and "my", must start the other's. A
restatement or a refinement ("... Elena" -> "... Elena Petrova") still
merges and keeps the fuller wording. A swapped, inserted or reordered
word, including a negation or a changed number, is stored as its own
entry, where extraction's UPDATE and consolidation can supersede it
with a trail.
Tests that relied on a value swap merging in place now use a real
refinement; the recall clamp test was vacuous because its 25 facts had
collapsed into one, and now checks the documented 100 cap.
Closes #4732
|
Verdict: Request changes This fixes a real data-loss bug: telling GAIA a second fact that only looked like an old one ("mother-in-law" vs "mother", "React 18" vs "19", "is" vs "is not") used to overwrite the first. Now only true repeats and refinements merge. The rule is tight, the tests try both orders of every near-miss pair, and the live API run shows the pairs kept apart. One thing blocks the merge:
One smaller issue, not blocking: when a shorter restatement merges into a longer memory, the agent now keeps the longer text but stores the meaning-search vector for the shorter one. Recall by meaning can then miss the extra words, and Rebuild Embeddings won't repair it. Real-world evidenceThe evidence stage ran the Agent UI memory API live on a fresh, empty backend ( After the change, each pair was stored as two entries. 🔍 Technical details🟡 Stale dedup claims outside the doc this PR edited The old "newer content replaces" rule is still stated in:
🟡 Embedding can describe different text than the merged row (non-blocking)
The row ends up with a non-NULL vector for "My sister's name is Ana" while its content is "… Ana Lopez". Checked, no issue
Strengths
|
…-dedup-distinct-facts
The SDK reference, the spec's summary line and the module docstring still said 80% word overlap replaces the old fact. Only a restatement or refinement merges now; a changed value is a new row that consolidation retires.
When a shorter restatement merges into a fuller memory, the row keeps the fuller wording, but callers embedded the text they passed in. The row then had a vector for different text, and since it was no longer NULL, rebuilding embeddings never repaired it. _embed_and_index now embeds the stored content.
|
Both points are fixed in 56a334e. The docs now describe the new rule, and a merged memory is embedded with the text it actually stores.
🔍 Technical details
|
…-dedup-distinct-facts # Conflicts: # docs/sdk/sdks/memory.mdx # docs/spec/agent-memory-architecture.md # src/gaia/agents/base/memory_store.py
… by id (amd#7212) Asking GAIA to remember a sensitive fact ("I am allergic to mango") saved it twice: once marked sensitive by the remember tool, and again a few seconds later, unmarked, by the turn's own extraction. Forgetting it by id then removed only the first copy, so the Memory page still listed it and a new chat still answered with it. Now the second save merges into the first and stays sensitive, and forgetting by id removes every copy. Closes amd#7175 ## Test plan - [x] `python -m pytest tests/unit/test_memory_sensitive_copy.py`: runs the real remember tool, then extraction's save, then forget by id, then recall. 11 of 12 fail without the fix, 12 pass with it - [x] Memory unit and integration suites, including the distinct-facts tests from amd#6924 and amd#6902: 2225 passed, 6 skipped - [ ] Replay in the app on the next RC (the agent ships as a downloaded binary): remember a sensitive fact, check Memory shows one entry, forget it, ask in a new chat - [ ] Eval categories to watch on the next RC: `memory`, `gaia_memory`, `context_retention` <details> <summary>🔍 Technical details</summary> - Duplicate detection compared only rows with the same entity tag. The tool tags the fact and extraction does not, so the copies never met. No tag, a bare label (`user`, `health`) and a `user:` tag now count as the user; any other `type:name` tag (`person:`, `app:`, `project:`) is its own subject. - A merged row's source still changes from `tool` to `llm_extract`, as it already did when the tags matched, so the Memory page labels it "Picked up in a chat". - Forgetting, by id or by words and from the tool or the Memory page, also erases copies with the same words bar filler about the same subject; if any copy is sensitive, all are recorded as stems only. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
Telling GAIA "My mother-in-law's name is Miriam." erased "My mother's name is Elena.", because memory treated any two facts sharing 80% of their words as one and overwrote the old one. Now only a real repeat merges: a restatement, or a refinement like "... Elena" → "... Elena Petrova". A fact that changes, inserts or reorders a word — a different relative, a negation, a new number — is kept as its own memory, so dedup can no longer lose a fact.
A changed value ("React 18" → "React 19") is now a second entry rather than an in-place overwrite; extraction's UPDATE and consolidation already supersede the old one with a trail.
Test plan
python -m pytest tests/unit/test_memory_dedup_distinct_facts.py tests/unit/test_memory_store.py tests/unit/test_memory_mixin.py tests/integration/test_memory_integration.pygaia chat, say "My mother's name is Elena", then "My mother-in-law's name is Miriam";gaia memory(or the Memory page) lists both🔍 Technical details
_merged_duplicateruns after the existing overlap pre-filter: filler-stripped token sequences must be equal or one a prefix of the other; the fuller content is kept. Numbers keep inner punctuation so "10" is not a prefix of "10:30".test_recall_limit_clamped_to_20only passed because its 25 facts had collapsed into one row — it now checks the 100 cap the recall tool documents.Closes #4732