updates to the category docs (#3437)

This commit is contained in:
Prateek Chhikara
2025-09-09 11:47:09 -07:00
committed by GitHub
parent f5e0fb9e4b
commit e64488b598
4 changed files with 114 additions and 21 deletions
@@ -70,3 +70,39 @@ The v2 search API is powerful and flexible, allowing for more precise memory ret
)
```
</CodeGroup>
<CodeGroup>
```python Categories Filter Examples
# Example 1: Using 'contains' for partial matching
finance_memories = m.search(
query="What are my financial goals?",
version="v2",
filters={
"AND": [
{ "user_id": "alice" },
{
"categories": {
"contains": "finance"
}
}
]
},
)
# Example 2: Using 'in' for exact matching
personal_memories = m.search(
query="What personal information do you have?",
version="v2",
filters={
"AND": [
{ "user_id": "alice" },
{
"categories": {
"in": ["personal_information"]
}
}
]
},
)
```
</CodeGroup>
+1
View File
@@ -2,6 +2,7 @@
"$schema": "https://mintlify.com/docs.json",
"name": "Mem0",
"description": "Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users.",
"theme": "maple",
"colors": {
"primary": "#6c60f0",
"light": "#E6FFA2",
+2 -2
View File
@@ -1094,7 +1094,7 @@
}
}
},
"description": "Filters to apply to the 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)",
"description": "Filters to apply to the 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\"]}}).",
"style": "deepObject",
"explode": true
},
@@ -5083,7 +5083,7 @@
"filters": {
"title": "Filters",
"type": "object",
"description": "A dictionary of filters to apply to the search. 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).",
"description": "A dictionary of filters to apply to the search. 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\"]}}).",
"properties": {
"user_id": {"type": "string"},
"agent_id": {"type": "string"},
+75 -19
View File
@@ -285,6 +285,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
Our advanced search allows you to set custom search filters. You can filter by user_id, agent_id, app_id, run_id, created_at, updated_at, categories, and text. The filters support logical operators (AND, OR) and comparison operators (in, gte, lte, gt, lt, ne, contains, icontains, `*`). The wildcard character (`*`) matches everything for a specific field.
For the **categories** field specifically:
- Use `contains` for partial matching (e.g., `{"categories": {"contains": "finance"}}`)
- Use `in` for exact matching (e.g., `{"categories": {"in": ["personal_information"]}}`).
Here you need to define `version` as `v2` in the search method.
#### Example 1: Search using user_id and agent_id filters
@@ -407,58 +411,106 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
```
</CodeGroup>
#### Example 3: Search using metadata and categories
#### Example 3: Search using categories filters
<CodeGroup>
```python Python
query = "What do you know about me?"
# Example 3a: Using 'contains' for partial matching
query = "What are my financial goals?"
filters = {
"AND": [
{"metadata": {"food": "vegan"}},
{ "user_id": "alice" },
{
"categories":{
"contains": "food_preferences"
}
}
"categories": {
"contains": "finance"
}
}
]
}
client.search(query, version="v2", filters=filters)
# Example 3b: Using 'in' for exact matching
query = "What personal information do you have?"
filters = {
"AND": [
{ "user_id": "alice" },
{
"categories": {
"in": ["personal_information"]
}
}
]
}
client.search(query, version="v2", filters=filters)
```
```javascript JavaScript
const query = "What do you know about me?";
const filters = {
// Example 3a: Using 'contains' for partial matching
const query1 = "What are my financial goals?";
const filters1 = {
"AND": [
{"metadata": {"food": "vegan"}},
{ "user_id": "alice" },
{
"categories": {
"contains": "food_preferences"
"contains": "finance"
}
}
]
};
client.search(query, { version: "v2", filters })
client.search(query1, { version: "v2", filters: filters1 })
.then(results => console.log(results))
.catch(error => console.error(error));
// Example 3b: Using 'in' for exact matching
const query2 = "What personal information do you have?";
const filters2 = {
"AND": [
{ "user_id": "alice" },
{
"categories": {
"in": ["personal_information"]
}
}
]
};
client.search(query2, { version: "v2", filters: filters2 })
.then(results => console.log(results))
.catch(error => console.error(error));
```
```bash cURL
# Example 3a: Using 'contains' for partial matching
curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
-H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "What do you know about me?",
"query": "What are my financial goals?",
"filters": {
"AND": [
{
"metadata": {
"food": "vegan"
}
},
{ "user_id": "alice" },
{
"categories": {
"contains": "food_preferences"
"contains": "finance"
}
}
]
}
}'
# Example 3b: Using 'in' for exact matching
curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
-H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "What personal information do you have?",
"filters": {
"AND": [
{ "user_id": "alice" },
{
"categories": {
"in": ["personal_information"]
}
}
]
@@ -693,6 +745,10 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex&keywords=to play&page
Our advanced retrieval allows you to set custom filters when fetching memories. You can filter by user_id, agent_id, app_id, run_id, created_at, updated_at, categories, and keywords. The filters support logical operators (AND, OR) and comparison operators (in, gte, lte, gt, lt, ne, contains, icontains, `*`). The wildcard character (`*`) matches everything for a specific field.
For the **categories** field specifically:
- Use `contains` for partial matching (e.g., `{"categories": {"contains": "finance"}}`)
- Use `in` for exact matching (e.g., `{"categories": {"in": ["personal_information"]}}`).
Here you need to define `version` as `v2` in the get_all method.
<CodeGroup>