POST
https://api.mem0.ai/
/
v2
/
memories
/
search
# 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")

query = "What do you know about me?"
filters = {
   "OR":[
      {
         "user_id":"alex"
      },
      {
         "agent_id":{
            "in":[
               "travel-assistant",
               "customer-support"
            ]
         }
      }
   ]
}
client.search(query, version="v2", filters=filters)
[
  {
    "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "memory": "<string>",
    "user_id": "<string>",
    "metadata": {},
    "categories": [
      "<string>"
    ],
    "immutable": false,
    "expiration_date": null,
    "created_at": "2023-11-07T05:31:56Z",
    "updated_at": "2023-11-07T05:31:56Z"
  }
]

The v2 search API is powerful and flexible, allowing for more precise memory retrieval. 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

    related_memories = m.search(
        query="What are Alice's hobbies?",
        version="v2",
        filters={
            "OR": [
                {
                  "user_id": "alice"
                },
                {
                  "agent_id": {"in": ["travel-agent", "sports-agent"]}
                }
            ]
        },
    )
    

Authorizations

Authorization
string
header
required

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

Body

application/json

Response

200 - application/json

The response is of type object[].