updates to the category docs (#3437)
This commit is contained in:
@@ -70,3 +70,39 @@ The v2 search API is powerful and flexible, allowing for more precise memory ret
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
</CodeGroup>
|
</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>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"$schema": "https://mintlify.com/docs.json",
|
"$schema": "https://mintlify.com/docs.json",
|
||||||
"name": "Mem0",
|
"name": "Mem0",
|
||||||
"description": "Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users.",
|
"description": "Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users.",
|
||||||
|
"theme": "maple",
|
||||||
"colors": {
|
"colors": {
|
||||||
"primary": "#6c60f0",
|
"primary": "#6c60f0",
|
||||||
"light": "#E6FFA2",
|
"light": "#E6FFA2",
|
||||||
|
|||||||
+2
-2
@@ -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",
|
"style": "deepObject",
|
||||||
"explode": true
|
"explode": true
|
||||||
},
|
},
|
||||||
@@ -5083,7 +5083,7 @@
|
|||||||
"filters": {
|
"filters": {
|
||||||
"title": "Filters",
|
"title": "Filters",
|
||||||
"type": "object",
|
"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": {
|
"properties": {
|
||||||
"user_id": {"type": "string"},
|
"user_id": {"type": "string"},
|
||||||
"agent_id": {"type": "string"},
|
"agent_id": {"type": "string"},
|
||||||
|
|||||||
@@ -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.
|
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.
|
Here you need to define `version` as `v2` in the search method.
|
||||||
|
|
||||||
#### Example 1: Search using user_id and agent_id filters
|
#### 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>
|
</CodeGroup>
|
||||||
|
|
||||||
#### Example 3: Search using metadata and categories
|
#### Example 3: Search using categories filters
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
```python Python
|
```python Python
|
||||||
query = "What do you know about me?"
|
# Example 3a: Using 'contains' for partial matching
|
||||||
|
query = "What are my financial goals?"
|
||||||
filters = {
|
filters = {
|
||||||
"AND": [
|
"AND": [
|
||||||
{"metadata": {"food": "vegan"}},
|
{ "user_id": "alice" },
|
||||||
{
|
{
|
||||||
"categories":{
|
"categories": {
|
||||||
"contains": "food_preferences"
|
"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)
|
client.search(query, version="v2", filters=filters)
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript JavaScript
|
```javascript JavaScript
|
||||||
const query = "What do you know about me?";
|
// Example 3a: Using 'contains' for partial matching
|
||||||
const filters = {
|
const query1 = "What are my financial goals?";
|
||||||
|
const filters1 = {
|
||||||
"AND": [
|
"AND": [
|
||||||
{"metadata": {"food": "vegan"}},
|
{ "user_id": "alice" },
|
||||||
{
|
{
|
||||||
"categories": {
|
"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))
|
.then(results => console.log(results))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash cURL
|
```bash cURL
|
||||||
|
# Example 3a: Using 'contains' for partial matching
|
||||||
curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
|
curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
|
||||||
-H "Authorization: Token your-api-key" \
|
-H "Authorization: Token your-api-key" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"query": "What do you know about me?",
|
"query": "What are my financial goals?",
|
||||||
"filters": {
|
"filters": {
|
||||||
"AND": [
|
"AND": [
|
||||||
{
|
{ "user_id": "alice" },
|
||||||
"metadata": {
|
|
||||||
"food": "vegan"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"categories": {
|
"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.
|
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.
|
Here you need to define `version` as `v2` in the get_all method.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user