diff --git a/docs/api-reference/memory/v2-search-memories.mdx b/docs/api-reference/memory/v2-search-memories.mdx index 044d9f722..a81b898a2 100644 --- a/docs/api-reference/memory/v2-search-memories.mdx +++ b/docs/api-reference/memory/v2-search-memories.mdx @@ -70,3 +70,39 @@ The v2 search API is powerful and flexible, allowing for more precise memory ret ) ``` + + + ```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"] + } + } + ] + }, + ) + ``` + diff --git a/docs/docs.json b/docs/docs.json index 9dd514619..ebf1e2a1c 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -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", diff --git a/docs/openapi.json b/docs/openapi.json index b80016053..9a1cf6f41 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -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"}, diff --git a/docs/platform/advanced-memory-operations.mdx b/docs/platform/advanced-memory-operations.mdx index 15061cbc6..4d4af306a 100644 --- a/docs/platform/advanced-memory-operations.mdx +++ b/docs/platform/advanced-memory-operations.mdx @@ -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" \ ``` -#### Example 3: Search using metadata and categories +#### Example 3: Search using categories filters ```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.