1. Installation

2. API Key Setup

  1. Sign in to Mem0 Platform
  2. Copy your API Key from the dashboard

3. Instantiate Client

3.1 Instantiate Async Client (Python only)

For asynchronous operations in Python, you can use the AsyncMemoryClient:

Python
from mem0 import AsyncMemoryClient

client = AsyncMemoryClient(api_key="your-api-key")


async def main():
    response = await client.add("I'm travelling to SF", user_id="john")
    print(response)

await main()

4. Memory Operations

Mem0 provides a simple and customizable interface for performing CRUD operations on memory.

4.1 Create Memories

Long-term memory for a user

These memory instances persist across multiple sessions. Ideal for maintaining memory over long time spans.

The add method offers support for two output formats: v1.0 (default) and v1.1. To enable the latest format, which provides enhanced detail for each memory operation, set the output_format parameter to v1.1. Note that v1.0 will be deprecated in version 0.1.30.

Short-term memory for a user session

These memory instances persist only for the duration of a user session. Ideal for non-repetitive interactions and managing context windows efficiently.

Long-term memory for agents

Add a memory layer for the assistants and agents so that their responses remain consistent across sessions.

Monitor Memories

You can monitor memory operations on the platform dashboard:

4.2 Search Memories

Pass user messages, interactions, and queries into our search method to retrieve relevant memories.

The search method supports two output formats: v1.0 (default) and v1.1. To use the latest format, which provides more detailed information about each memory operation, set the output_format parameter to v1.1:

Use category and metadata filters:

Search using custom filters

Our advanced search allows you to set custom search filters. You can filter by user_id, agent_id, app_id, date, and more.

Here you need to define version as v2 in the search method.

Example 1: Search using user_id and agent_id filters

Example 2: Search using date filters

4.3 Get All Users

Get all users, agents, and runs which have memories associated with them.

4.4 Get All Memories

Fetch all memories for a user, agent, or run using the getAll() method.

The get_all method supports two output formats: v1.0 (default) and v1.1. To use the latest format, which provides more detailed information about each memory operation, set the output_format parameter to v1.1:

Get all memories of a user

Get all memories of an AI Agent

Get the short-term memories for a session

Get specific memory

Get all memories using custom filters

Our advanced retrieval allows you to set custom filters when fetching memories. You can filter by user_id, agent_id, app_id, date, and more.

Here you need to define version as v2 in the get_all method.

Example: Get all memories using user_id and date filters

4.5 Memory History

Get history of how a memory has changed over time.

4.6 Update Memory

Update a memory with new data.

4.7 Delete Memory

Delete specific memory.

Delete all memories of a user.

Delete all users.

4.8 Reset Client

Fun fact: You can also delete the memory using the add() method by passing a natural language command:

If you have any questions, please feel free to reach out to us using one of the following methods: