Skip to main content
POST
/
v2
/
memories
/
Python
# To use the Python SDK, install the package:
# pip install mem0ai

from mem0 import MemoryClient
client = MemoryClient(api_key="your_api_key", org_id="your_org_id", project_id="your_project_id")

# Retrieve memories with filters
memories = client.get_all(
    filters={
        "AND": [
            {
                "user_id": "alex"
            },
            {
                "created_at": {
                    "gte": "2024-07-01",
                    "lte": "2024-07-31"
                }
            }
        ]
    },
    version="v2"
)

print(memories)
[
  {
    "id": "<string>",
    "memory": "<string>",
    "created_at": "2023-11-07T05:31:56Z",
    "updated_at": "2023-11-07T05:31:56Z",
    "owner": "<string>",
    "immutable": false,
    "expiration_date": null,
    "organization": "<string>",
    "metadata": {}
  }
]
The v2 get memories API is powerful and flexible, allowing for more precise memory listing without the need for a search query. It supports complex logical operations (AND, OR, NOT) and comparison operators for advanced filtering capabilities. The comparison operators include:
  • in: Matches any of the values specified
  • gte: Greater than or equal to
  • lte: Less than or equal to
  • gt: Greater than
  • lt: Less than
  • ne: Not equal to
  • icontains: Case-insensitive containment check
  • *: Wildcard character that matches everything
memories = m.get_all(
    filters={
        "AND": [
            {
                "user_id": "alex"
            },
            {
                "created_at": {"gte": "2024-07-01", "lte": "2024-07-31"}
            }
        ]
    }
)
# Using wildcard to get all memories for a specific user across all run_ids
memories = m.get_all(
    filters={
        "AND": [
            {
                "user_id": "alex"
            },
            {
                "run_id": "*"
            }
        ]
    }
)

Graph Memory

To retrieve memories with graph-based relationships, pass the enable_graph=True parameter. This includes relationship data in the response for more contextual results.
Learn more in the Graph Memory documentation.

Authorizations

Authorization
string
header
required

API key authentication. Prefix your Mem0 API key with 'Token '. Example: 'Token your_api_key'

Body

application/json
filters
object
required

A dictionary of filters to apply to retrieve memories. Available fields are: user_id, agent_id, app_id, run_id, created_at, updated_at, categories, keywords. Supports logical operators (AND, OR) and comparison operators (in, gte, lte, gt, lt, ne, contains, icontains, *). For categories field, use 'contains' for partial matching (e.g., {"categories": {"contains": "finance"}}) or 'in' for exact matching (e.g., {"categories": {"in": ["personal_information"]}}).

fields
string[]

A list of field names to include in the response. If not provided, all fields will be returned.

page
integer
default:1

Page number for pagination. Default: 1

page_size
integer
default:100

Number of items per page. Default: 100

org_id
string | null

The unique identifier of the organization associated with the memory.

project_id
string | null

The unique identifier of the project associated with the memory.

Response

Successfully retrieved memories.

id
string
required
memory
string
required
created_at
string<date-time>
required
updated_at
string<date-time>
required
owner
string
required
organization
string
required
immutable
boolean
default:false

Whether the memory is immutable.

expiration_date
string<date-time> | null

The date and time when the memory will expire. Format: YYYY-MM-DD.

metadata
object
I