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 →
history: what happened to a memory
A memory that changed silently is a bug you cannot investigate. Every memory keeps a record of what was done to it.
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.update(stored["id"], text="Deliver to the office reception.")
for entry in shop.history(stored["id"]):
print(entry["event"])Two entries: it was added, then it was updated. history takes the id on its own, like get.
What an entry holds
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.update(stored["id"], text="Deliver to the office reception.")
entry = shop.history(stored["id"])[-1]
print(sorted(entry))The old text, the new text, the event and when it happened. That is enough to answer the question you will actually be asked, which is why does it think that.
This is the field you will want at three in the morning. An assistant says something wrong about a customer, and the memory behind it looks reasonable. The history shows it was an
UPDATE two weeks ago, from a sentence somebody typed in a chat, and the question stops being a mystery.It survives deletion
Deleting a memory does not erase its history, which matters both for debugging and for the opposite reason: if a user asks you to forget them, deleting the memories is not the whole job. delete_all and a policy on the history table are.
Try it yourself
- Update the same memory twice and count the history entries.
- Print the old and new text from the last entry side by side.
- Delete a memory and then ask for its history.
Little by little, you're building something great.