From a952df09530d4af8a8e1b75067b83d7eef87e8f3 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Fri, 23 May 2025 23:29:21 +0530 Subject: [PATCH] Doc: Add NOT filter for Search and GetAll V2 (#2785) --- docs/api-reference/memory/v2-get-memories.mdx | 2 +- .../memory/v2-search-memories.mdx | 2 +- docs/platform/quickstart.mdx | 186 ++++++++++++++++++ 3 files changed, 188 insertions(+), 2 deletions(-) diff --git a/docs/api-reference/memory/v2-get-memories.mdx b/docs/api-reference/memory/v2-get-memories.mdx index 885d853e..1da3036b 100644 --- a/docs/api-reference/memory/v2-get-memories.mdx +++ b/docs/api-reference/memory/v2-get-memories.mdx @@ -3,7 +3,7 @@ title: 'Get Memories (v2)' openapi: post /v2/memories/ --- -The v2 get memories API is powerful and flexible, allowing for more precise memory listing without the need for a search query. It supports complex logical operations (AND, OR) and comparison operators for advanced filtering capabilities. The comparison operators include: +The v2 get memories API is powerful and flexible, allowing for more precise memory listing without the need for a search query. It supports complex logical operations (AND, OR, NOT) and comparison operators for advanced filtering capabilities. The comparison operators include: - `in`: Matches any of the values specified - `gte`: Greater than or equal to - `lte`: Less than or equal to diff --git a/docs/api-reference/memory/v2-search-memories.mdx b/docs/api-reference/memory/v2-search-memories.mdx index a7959ec4..f0526869 100644 --- a/docs/api-reference/memory/v2-search-memories.mdx +++ b/docs/api-reference/memory/v2-search-memories.mdx @@ -3,7 +3,7 @@ title: 'Search Memories (v2)' openapi: post /v2/memories/search/ --- -The v2 search API is powerful and flexible, allowing for more precise memory retrieval. It supports complex logical operations (AND, OR) and comparison operators for advanced filtering capabilities. The comparison operators include: +The v2 search API is powerful and flexible, allowing for more precise memory retrieval. It supports complex logical operations (AND, OR, NOT) and comparison operators for advanced filtering capabilities. The comparison operators include: - `in`: Matches any of the values specified - `gte`: Greater than or equal to - `lte`: Less than or equal to diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index b2fbb8f0..81bd0d9b 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -694,6 +694,77 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \ +Example 4: Search using NOT filters + +```python Python +query = "What do you know about me?" +filters = { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] +} +client.search(query, version="v2", filters=filters) +``` + +```javascript JavaScript +const query = "What do you know about me?"; +const filters = { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] +}; + +client.search(query, { version: "v2", filters }) + .then(results => console.log(results)) + .catch(error => console.error(error)); +``` + +```bash cURL +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?", + "filters": { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] + } + }' +``` + +```json Output +{ + "results": [ + { + "id": "123abc-d456-7890-efgh-ijklmnopqrst", + "memory": "Lives in San Francisco", + "user_id": "alex", + "metadata": null, + "categories": ["location"], + "immutable": false, + "expiration_date": null, + "created_at": "2024-07-20T01:30:36.275141-07:00", + "updated_at": "2024-07-20T01:30:36.275172-07:00" + } + ] +} +``` + + + ### 4.3 Get All Users @@ -1311,6 +1382,121 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \ +Example 3: Get all memories using NOT filters + +```python Python +filters = { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] +} + +# Default (No Pagination) +client.get_all(version="v2", filters=filters) + +# Pagination (You can also use the page and page_size parameters) +client.get_all(version="v2", filters=filters, page=1, page_size=50) +``` + +```javascript JavaScript +const filters = { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] +}; + +// Default (No Pagination) +client.getAll({ version: "v2", filters }) + .then(memories => console.log(memories)) + .catch(error => console.error(error)); + +// Pagination (You can also use the page and page_size parameters) +client.getAll({ version: "v2", filters, page: 1, page_size: 50 }) + .then(memories => console.log(memories)) + .catch(error => console.error(error)); +``` + +```bash cURL +# Default (No Pagination) +curl -X GET "https://api.mem0.ai/v1/memories/?version=v2" \ + -H "Authorization: Token your-api-key" \ + -H "Content-Type: application/json" \ + -d '{ + "filters": { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] + } + }' + +# Pagination (You can also use the page and page_size parameters) +curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \ + -H "Authorization: Token your-api-key" \ + -H "Content-Type: application/json" \ + -d '{ + "filters": { + "NOT": [ + { + "categories": { + "contains": "food_preferences" + } + } + ] + } + }' +``` + +```json Output +[ + { + "id": "789xyz-e012-3456-fghi-jklmnopqrstu", + "memory": "Works as a software engineer", + "user_id": "alex", + "metadata": {"job": "tech"}, + "categories": ["work"], + "immutable": false, + "expiration_date": null, + "created_at": "2024-07-20T01:30:36.275141-07:00", + "updated_at": "2024-07-20T01:30:36.275172-07:00" + } +] +``` + +```json Output (Paginated) +{ + "count": 1, + "next": null, + "previous": null, + "results": [ + { + "id": "789xyz-e012-3456-fghi-jklmnopqrstu", + "memory": "Works as a software engineer", + "user_id": "alex", + "metadata": {"job": "tech"}, + "categories": ["work"], + "immutable": false, + "expiration_date": null, + "created_at": "2024-07-20T01:30:36.275141-07:00", + "updated_at": "2024-07-20T01:30:36.275172-07:00" + } + ] +} +``` + + + ### 4.5 Memory History