docs/core-concepts/memory-operations/search.mdx
Mem0's search operation lets agents ask natural-language questions and get back the memories that matter most. Like a smart librarian, it finds exactly what you need from everything you've stored.
<Info> **Why it matters** - Retrieves the right facts without rebuilding prompts from scratch. - Supports both managed Platform and OSS so you can test locally and deploy at scale. - Keeps results relevant with filters, rerankers, and thresholds. </Info>search.This pipeline runs the same way for the hosted Platform API and the OSS SDK.
Search converts your natural language question into a vector embedding, then finds memories with similar embeddings in your database. The results are ranked by similarity score and can be further refined with filters or reranking.
# Minimal example that shows the concept in action
# Platform API
client.search("What are Alice's hobbies?", filters={"user_id": "alice"})
# OSS
m.search("What are Alice's hobbies?", filters={"user_id": "alice"})
| Capability | Mem0 Platform | Mem0 OSS |
|---|---|---|
| Entity IDs on search / get_all | Inside filters={"user_id": "alice"} | Inside filters={"user_id": "alice"} (aligned with Platform in v3 — top-level kwargs raise ValueError) |
| Filter syntax | Logical operators (AND, OR, comparisons) with field-level access | Basic field filters, extend via Python hooks |
| Reranking | Toggle rerank=True with managed reranker catalog | Requires configuring local or third-party rerankers |
| Thresholds | Request-level configuration (threshold, top_k) | Controlled via SDK parameters |
| Response metadata | Includes confidence scores, timestamps, dashboard visibility | Determined by your storage backend |
client = MemoryClient(api_key="your-api-key")
query = "What do you know about me?" filters = { "OR": [ {"user_id": "alice"}, {"agent_id": {"in": ["travel-assistant", "customer-support"]}} ] }
results = client.search(query, filters=filters)
```javascript JavaScript
import { MemoryClient } from "mem0ai";
const client = new MemoryClient({apiKey: "your-api-key"});
const query = "I'm craving some pizza. Any recommendations?";
const filters = {
AND: [
{ user_id: "alice" }
]
};
const results = await client.search(query, {
filters
});
m = Memory()
filtersrelated_memories = m.search("Should I drink coffee or tea?", filters={"user_id": "alice"})
memories = m.search( "food preferences", filters={"user_id": "alice", "categories": {"contains": "diet"}}, )
```javascript JavaScript
import { Memory } from 'mem0ai/oss';
const memory = new Memory();
// Simple search — entity IDs go inside `filters`
const relatedMemories = memory.search("Should I drink coffee or tea?", {
filters: { userId: "alice" },
});
// Combine entity + metadata filters in the same filters object
const memories = memory.search("food preferences", {
filters: { userId: "alice", categories: { contains: "diet" } },
});
OSS search combines semantic similarity with optional keyword and entity signals. Pass explain=True when tuning retrieval quality or debugging why a memory ranked where it did:
print(results["results"][0]["score_details"])
```javascript JavaScript
const results = await memory.search("food preferences", {
filters: { user_id: "alice" },
explain: true,
});
console.log(results.results[0].score_details);
Each result includes score_details with the semantic score, normalized BM25 score, entity boost, raw combined score, maximum possible score, final score, and threshold used for filtering. The field is omitted unless explain is enabled, so existing response shapes stay unchanged.
Filters help narrow down search results. Common use cases:
Filter by Session Context:
Platform API:
# Get memories from a specific agent session
client.search("query", filters={
"AND": [
{"user_id": "alice"},
{"agent_id": "chatbot"},
{"run_id": "session-123"}
]
})
OSS:
# Get memories from a specific agent session — entity IDs combined in filters
m.search("query", filters={
"user_id": "alice",
"agent_id": "chatbot",
"run_id": "session-123",
})
Filter by Date Range:
# Platform only - date filtering
client.search("recent memories", filters={
"AND": [
{"user_id": "alice"},
{"created_at": {"gte": "2024-07-01"}}
]
})
Filter by Categories:
# Platform only - category filtering
client.search("preferences", filters={
"AND": [
{"user_id": "alice"},
{"categories": {"contains": "food"}}
]
})
user_id to scope search to relevant memories
filters={"user_id": "alice"}user_id="alice" as parameterrun_id: "*") for broader matchestop_k for result count, threshold for relevance cutoffrerank=True (default) when you have a reranker configuredFor the full list of filter logic, comparison operators, and optional search parameters, see the Search Memory API Reference.