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

Why a dictionary is not memory

The obvious fix is a dictionary keyed by user. It works for about ten minutes, and the ways it breaks are exactly the features Mem0 has.

Here is that first attempt. Everything the customer says gets stored under his name.

Example
NOTES = {}

def remember(user, said):
    NOTES.setdefault(user, []).append(said)

def recall(user, about):
    return [note for note in NOTES.get(user, []) if about in note]

remember("ravi", "I prefer email updates, not SMS.")
remember("ravi", "Thanks!")
print(recall("ravi", "email"))

It stored the useful sentence and it found it. It also stored Thanks!, which is not a memory, and it found the note only because the question happened to use the word email.

The first break: the question uses different words

Example
print(recall("ravi", "contact"))
print(recall("ravi", "how should we reach him"))

Nothing. The fact is sitting right there and a substring search cannot reach it, because nobody says email when they ask how to contact someone. Matching text is not the same as matching meaning, and that gap is what an embedder closes.

The second break: facts change

Ravi changes his mind and asks for SMS after all. The dictionary now holds both, contradicting each other, and neither is marked as the current one. Whatever you search for, you get an answer that might be a year out of date.

The third break: it never stops growing

Every thanks, every ok, every greeting is in there forever. After a thousand conversations the useful facts are a tiny fraction of the pile, and every search has to wade through the rest.

The dictionaryWhat Mem0 does insteadLesson
Stores every sentenceAsks a model what is worth keeping5 and 8
Matches substringsMatches meaning, through an embedder6 and 9
Keeps contradictionsUpdates the memory that changed15
One flat list per userScoped by user, agent and run, and tagged12 and 13
No record of changesA history for every memory16
Two of those five need a model. Deciding what is worth keeping is a judgement, and matching meaning needs an embedder. That is why Mem0 wants an API key by default, and why the next part is about not needing one.
Try it yourself
  • Add remember("ravi", "Actually SMS is fine.") and run recall("ravi", "SMS"). Decide which of the two answers is true.
  • Try to write recall so that contact finds the email note, without listing synonyms by hand.
  • Count how many of the sentences in your last support chat were worth storing.

You understood something today that you didn't yesterday.