Skip to content

Fix contradicting memory loss: ADD new fact when DELETing old one#4580

Closed
joaquinhuigomez wants to merge 2 commits intomem0ai:mainfrom
joaquinhuigomez:fix/contradictory-memory-add
Closed

Fix contradicting memory loss: ADD new fact when DELETing old one#4580
joaquinhuigomez wants to merge 2 commits intomem0ai:mainfrom
joaquinhuigomez:fix/contradictory-memory-add

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

Summary

  • Update DEFAULT_UPDATE_MEMORY_PROMPT to ADD the new fact when DELETing a contradicting old one
  • Prevents silent data loss when memory contradictions occur

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

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
@joaquinhuigomez joaquinhuigomez force-pushed the fix/contradictory-memory-add branch from 7628d56 to 6ad5cdc Compare March 28, 2026 12:57
Copy link
Copy Markdown
Contributor

@SaharshPatel24 SaharshPatel24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@joaquinhuigomez
Copy link
Copy Markdown
Author

Good point — removed the id field from the ADD entry. The pipeline ignores it anyway. Updated.

@joaquinhuigomez
Copy link
Copy Markdown
Author

Thanks for the approval — anything else needed to merge?

@kartik-mem0
Copy link
Copy Markdown
Contributor

Closing as superseded by the v3 memory pipeline (#4805).

The v3 algorithm replaced UPDATE_MEMORY_PROMPT with ADDITIVE_EXTRACTION_PROMPT, which is ADD-only — contradictions are now handled via memory linking instead of DELETE operations. The prompt changes in this PR target code that's no longer in the active code path.

Thank you for the contribution! The underlying issue (#4536) is now resolved by the architectural change in v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest change to memory adding with contradicting facts

3 participants