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 path

The assistant that remembers, end to end

Everything in the course, in one file. This is the assistant promised in lesson 0: it remembers a customer across conversations, and it runs with no API key.

Nothing here is new. Every piece was built alone in an earlier lesson and the table says which.

PieceWhat it doesLesson
pretend_mem0.pyThe model, the embedder and the config5, 6 and 7
answer()The assistant, unchanged since lesson 11
search before, add afterMemory around the reply21
user_idKeeps one customer apart from another12
metadataWhere the memory came from13
The three checksProof that it stored, found and separated22

Two conversations, a week apart

Example
from shop import assistant, memory

shop = memory()
print(assistant(shop, "ravi", "I prefer email updates, not SMS."))
print(assistant(shop, "ravi", "Deliver to my office, not my home."))
print()
print(assistant(shop, "ravi", "Can you send me an update?"))

The first two turns teach it something. The third is the conversation that went wrong in lesson 1, and this time the assistant knows how Ravi wants to be contacted before it answers.

What it kept

Example
from shop import assistant, memory

shop = memory()
for said in ["I prefer email updates, not SMS.", "Deliver to my office, not my home.",
             "Thanks, that is all."]:
    assistant(shop, "ravi", said)

kept = shop.get_all(filters={"user_id": "ravi"})["results"]
for text in sorted(m["memory"] for m in kept):
    print("-", text)

Three messages in, and the pleasantry is not in the list. That is the model earning its place: the dictionary in lesson 2 would have kept it forever.

The failure worth showing

Example
from shop import assistant, memory

shop = memory()
assistant(shop, "ravi", "Deliver to my office.")
print(assistant(shop, "priya", "Where is my order?"))
print(shop.search("deliver", filters={"user_id": "priya"})["results"])

Priya gets no reference to an office, because the search was filtered to her. Drop that filter and the assistant tells one customer another customer's address, which is the single worst thing a memory layer can do and the reason lesson 22 tests for it.

Where to go next

Swap in a real model with the two lines from lesson 19 and keep this file as the test fixture. Point the store at a directory that persists, from lesson 18. Then add a run_id so that what is true in one conversation does not leak into the next.

The assistant, and the lesson each piece came from
before the replythe replyafter the replyunderneathassistant()
Try it yourself
  • Add a fourth message that contradicts an earlier one and look at what is stored.
  • Give the assistant a run_id and check that a new session does not see the last one.
  • Write the three checks from lesson 22 against this file and run them.

Slow is fine. Stopping is the only problem.