Mem0mem0ai 2.0.20 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
24 small wins to finish your pathNext lesson

update and delete

People change their minds, and a memory layer that cannot keep up is worse than none: it answers confidently with last year's answer.

Example
from pretend_mem0 import memory

shop = memory()
shop.add("Deliver to my office.", user_id="ravi")
stored = shop.get_all(filters={"user_id": "ravi"})["results"][0]

print(shop.update(stored["id"], text="Deliver to the office reception."))
print(shop.get(stored["id"])["memory"])

update takes the id and the new text, and says it worked. The memory is rewritten in place, keeping its id, and re-embedded so searches find it by its new words rather than its old ones.

Deleting one

Example
from pretend_mem0 import memory

shop = memory()
shop.add("Deliver to my office.", user_id="ravi")
stored = shop.get_all(filters={"user_id": "ravi"})["results"][0]

shop.delete(stored["id"])
print(shop.get(stored["id"]))
print(len(shop.get_all(filters={"user_id": "ravi"})["results"]), "left")

Gone, and get returns None rather than raising. delete_all takes identifiers instead of an id and clears everything matching, which is what a forget me button calls.

The update you did not ask for

Mem0 also updates memories on its own. Every add is compared against what is already stored, and when the model decides the new sentence replaces an old one, the result carries UPDATE rather than ADD. That is why add returns an event at all.

The stand-in model in this course never does that: it has no opinion about whether two sentences conflict, so it always adds. A real model does, and it is worth knowing before it surprises you, because a memory you did not delete can still change under you.

A contradiction is not resolved by storing both. If Ravi says SMS after a year of email, you want one memory that says SMS, not two that disagree. Automatic updates are Mem0 trying to do that for you, and they are the main reason to read the event field in the result rather than ignoring it.

Deciding who wins

When a fact is critical, do not leave it to the model. Search for the existing memory, delete it, and add the new one, so the outcome is code you wrote rather than a judgement you did not see.

Try it yourself
  • Update a memory and then search for a word that was only in the old text.
  • Delete a memory and call get on its id.
  • Add a sentence that flatly contradicts a stored memory and look at the event you get back.

Every expert started right here.