Mem0
Memory layer for AI agents and assistants. PyPI package is mem0ai but imports as mem0. Two distinct usage modes: Memory class (OSS, self-hosted) and MemoryClient class (managed platform). v1.0.0 introduced breaking changes to response format.
Warnings
- breaking v1.0 changed all response formats. add() and get_all() now return a dict with a 'results' key, not a flat list. Code iterating directly over the return value breaks with TypeError.
- breaking output_format='v1.0' is removed server-side. Passing it raises DeprecationWarning then 400 Bad Request from the platform API.
- gotcha Package name is mem0ai but import name is mem0. pip install mem0ai, then from mem0 import Memory.
- gotcha MemoryClient.add() defaults to async_mode=True in v1.0+. Calling search() immediately after add() may return empty results as memory has not yet been stored.
- gotcha OSS Memory() with no config calls OpenAI by default. Fails with AuthenticationError if OPENAI_API_KEY is not set.
- gotcha Graph memory features require pip install mem0ai[graph]. Importing graph-related classes without this extra raises ImportError.
Install
-
pip install mem0ai -
pip install mem0ai[graph]
Imports
- Memory
from mem0 import Memory
- MemoryClient
from mem0 import MemoryClient
Quickstart
from mem0 import Memory
memory = Memory() # requires OPENAI_API_KEY by default
memory.add(
[{"role": "user", "content": "I like basketball."}],
user_id="alice"
)
results = memory.search(query="sports", user_id="alice", limit=3)
for r in results["results"]:
print(r["memory"])