Fix contradicting memory loss: ADD new fact when DELETing old one#4580
Fix contradicting memory loss: ADD new fact when DELETing old one#4580joaquinhuigomez wants to merge 2 commits intomem0ai:mainfrom
Conversation
When a new fact contradicts an existing memory, the update prompt previously instructed the LLM to DELETE the old memory without adding the replacement. This caused both the old and new facts to be silently lost. Update DEFAULT_UPDATE_MEMORY_PROMPT to instruct the LLM to both DELETE the contradicting old memory and ADD the new fact, so that contradicting memories are replaced rather than discarded. Fixes mem0ai#4536
7628d56 to
6ad5cdc
Compare
SaharshPatel24
left a comment
There was a problem hiding this comment.
Good fix for a real bug — the core idea is correct and the pipeline already handles ADD/DELETE independently.
One small suggestion: the new instruction 'For the new ADD entry, generate a new ID' contradicts the existing line 264 which says 'do not generate any new ID'. Also, the pipeline ignores the ID on ADD events anyway — it always generates a fresh UUID internally via _create_memory().
So you could simplify by just omitting the ID field in the ADD example:
{
"text": "Dislikes cheese pizza",
"event": "ADD"
}This keeps it consistent with the existing prompt instruction and avoids confusing the LLM with contradicting rules. Not a blocker, just a cleaner approach.
Omit the id field from the ADD entry in the DELETE example — the pipeline generates a fresh UUID internally via _create_memory() and ignores any id provided by the LLM for ADD events.
|
Good point — removed the id field from the ADD entry. The pipeline ignores it anyway. Updated. |
|
Thanks for the approval — anything else needed to merge? |
|
Closing as superseded by the v3 memory pipeline (#4805). The v3 algorithm replaced Thank you for the contribution! The underlying issue (#4536) is now resolved by the architectural change in v3. |
Summary
The DELETE section of the update memory prompt instructed the LLM to delete contradicting memories but never to add the replacement fact. For example, adding "I hate Chinese food" after "I love Chinese food" would delete the old memory and discard the new one, leaving the memory store empty.
The fix updates the prompt instructions and example so the LLM emits both a DELETE for the old memory and an ADD for the new contradicting fact. The memory processing pipeline already handles ADD and DELETE events independently, so no code changes are needed beyond the prompt.
Added a test to verify the prompt contains ADD instructions in the contradiction/DELETE section.
Fixes #4536