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.
Common errors
-
ModuleNotFoundError: No module named 'mem0'
cause The Python package is named `mem0ai` on PyPI, but the import name within Python code is `mem0`.fixEnsure you have installed the correct package using `pip install mem0ai` and then import it as `import mem0` or `from mem0 import Memory, MemoryClient`. -
ValueError: The v1.0 API format is no longer supported in mem0ai 1.0.0+. Please use v1.1 format which returns a dict with 'results' key.
cause This error occurs because mem0ai v1.0.0 introduced breaking changes, removing support for the v1.0 API format and standardizing all responses to a dictionary with a 'results' key.fixUpdate your code to use the v1.1 API format. This typically involves removing `version` and `output_format` parameters from method calls and accessing results via `result['results']` instead of treating the response directly as a list. -
AttributeError: 'Memory' object has no attribute 'version'
cause This is typically caused by attempting to access or pass a `version` parameter to `Memory` or `MemoryClient` methods, which was removed in mem0ai v1.0.0. Other `AttributeError`s may arise from accessing removed parameters or properties that were part of pre-v1.0.0 API.fixRemove the `version` parameter from all `Memory` and `MemoryClient` method calls and configurations. Refer to the migration guide for other potential parameter removals and response format changes. -
ImportError: cannot import name 'MemoryClient' from partially initialized module 'mem0' (most likely due to a circular import)
cause This specific ImportError usually means you have named one of your local Python files `mem0.py`, creating a circular import conflict with the installed `mem0` library.fixRename your local `mem0.py` file to something else to avoid conflict with the library's import name. -
HTTP error occurred: Client error '400 Bad Request' for url 'https://api.mem0.ai/v1/memories/' Failed to add to long term memory: API request failed: {"error":"At least one of the filters: agent_id, user_id, app_id, run_id is required!"}cause When using `MemoryClient` with the managed platform, certain API calls (like adding memories) require specific identifiers such as `user_id`, `agent_id`, `app_id`, or `run_id` for proper scoping and data isolation.fixEnsure you are passing at least one of the required identification parameters (e.g., `user_id`) when making API calls that store or retrieve memories through the `MemoryClient`.
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.
- breaking Installation fails when building 'psycopg2' from source due to 'pg_config executable not found'. This typically occurs in environments like Alpine Linux that lack PostgreSQL development headers, which are required to compile psycopg2.
Install
-
pip install mem0ai -
pip install mem0ai[graph]
Imports
- Memory
from mem0ai import Memory
from mem0 import Memory
- MemoryClient
from mem0 import Memory
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"])