Search Memories - Mem0
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
cURL Example
curl -X POST https://api.mem0.ai/v3/memories/search/ \
-H "Authorization: Token <api-key>" \
-H "Content-Type: application/json" \
-d '{\n "query": "where does the user live?",\n "filters": {"user_id": "alice"},\n "top_k": 10\n }'
Python Example
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
results = client.search(
"where does the user live?",
filters={"user_id": "alice"},
top_k=10,
)
for r in results["results"]:
print(r["memory"], r["score"])
JavaScript Example
import MemoryClient from "mem0ai";
const client = new MemoryClient({ apiKey: "your-api-key" });
const results = await client.search("where does the user live?", {
filters: { userId: "alice" },
topK: 10,
});
for (const r of results.results) {
console.log(r.memory, r.score);
}
PHP Example
<?php
$curl = curl_init();
curl_setopt_array($curl, [\
CURLOPT_URL => "https://api.mem0.ai/v3/memories/search/",\
CURLOPT_RETURNTRANSFER => true,\
CURLOPT_ENCODING => "",\
CURLOPT_MAXREDIRS => 10,\
CURLOPT_TIMEOUT => 30,\
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\
CURLOPT_CUSTOMREQUEST => "POST",\
CURLOPT_POSTFIELDS => json_encode([\
'query' => 'where does the user live?',\
'filters' => [\
'user_id' => 'alice'\
],\
'top_k' => 10\
]),\
CURLOPT_HTTPHEADER => [\
"Content-Type: application/json"\
],\
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Go Example
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.mem0.ai/v3/memories/search/"
payload := strings.NewReader("{\n \"query\": \"where does the user live?\",\n \"filters\": {\n \"user_id\": \"alice\"\n },\n \"top_k\": 10\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
Example Response
{
"results": [
{
"id": "mem-uuid",
"memory": "User moved to San Francisco from New York in January 2026",
"score": 0.82,
"metadata": {},
"categories": ["location"],
"created_at": "2026-01-15T10:30:00Z",
"updated_at": "2026-01-15T10:30:00Z"
}
]
}
Search Parameter Defaults
| Parameter | Default |
|---|---|
top_k |
10 (range 1–1000) |
threshold |
0.1 (pass 0.0 to disable) |
rerank |
false (pass true to enable) |
Filters Supported
The filters object supports complex logical operations (AND, OR, NOT) and comparison operators:
in: Matches any of the values specifiedgte: Greater than or equal tolte: Less than or equal togt: Greater thanlt: Less thanne: Not equal toicontains: Case-insensitive containment check*: Wildcard character that matches everything
Example Cleaned Memory Query
related_memories = client.search(
query="What are Alice's hobbies?",
show_expired=False,
filters={
"OR": [
{ "user_id": "alice" },
{ "agent_id": {"in": ["travel-agent", "sports-agent"]} }
]
},
)
Conclusion
This document illustrates how to use the Memory API for retrieving memories based on various queries and filters.