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

get_all, get, and the memory id

Search answers a question. Sometimes you want everything, or one specific thing, and those are different calls.

Example
from pretend_mem0 import memory

shop = memory()
shop.add("I prefer email updates, not SMS. Deliver to my office.", user_id="ravi")

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

get_all takes filters the same way search does, and no query. It is what you show on a what do you know about me screen, and what you read before deleting anything. The order it returns is not promised, so this sorts before printing.

The id

Every memory has an id, and it is the handle for everything in part 5: updating one, deleting one, reading its history. It is a uuid, so it changes every run, which is why the lessons print the memory rather than the id wherever they can.

Example
from pretend_mem0 import memory

shop = memory()
shop.add("I prefer email updates, not SMS. Deliver to my office.", user_id="ravi")

first = shop.get_all(filters={"user_id": "ravi"})["results"][0]
same = shop.get(first["id"])
print(same["memory"])
print(same["id"] == first["id"])

get takes the id on its own, with no filters, because an id is already unique. Ask for one that does not exist and you get None rather than an error.

A memory is not the sentence the customer typed. It is what the model decided to write down, which may be shorter, reworded, or split in two. When you show memories to a user, you are showing them the model's notes, so it is worth making those notes readable.

What else is on a memory

Example
from pretend_mem0 import memory

shop = memory()
shop.add("I prefer email updates, not SMS. Deliver to my office.", user_id="ravi")

first = shop.get_all(filters={"user_id": "ravi"})["results"][0]
print(sorted(first))

hash is how Mem0 spots the same memory arriving twice, created_at and updated_at are timestamps, and metadata is yours to fill in, which is lesson 13.

Try it yourself
  • Call get with a made-up id and check what comes back.
  • Add a second user and confirm get_all with Ravi's filter does not show their memories.
  • Print created_at and updated_at on a fresh memory and compare them.

Every expert started right here.