From 308e79bb68922262a66aa03e1eba4e46d2a57de5 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Thu, 27 Feb 2025 15:41:28 +0530 Subject: [PATCH] Docs: Update v2 GET ALL endpoint (#2267) --- docs/openapi.json | 1 + docs/platform/quickstart.mdx | 120 ++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/docs/openapi.json b/docs/openapi.json index 68e3fb1d..12b6ddad 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -1091,6 +1091,7 @@ "created_at": {"type": "string", "format": "date-time"}, "updated_at": {"type": "string", "format": "date-time"}, "categories": {"type": "array", "items": {"type": "string"}}, + "metadata": {"type": "object"}, "keywords": {"type": "string"} }, "additionalProperties": { diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index dafb819f..69ac4c7c 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -1183,7 +1183,7 @@ Our advanced retrieval allows you to set custom filters when fetching memories. Here you need to define `version` as `v2` in the get_all method. -Example: Get all memories using user_id and date filters +Example 1. Get all memories using user_id and date filters @@ -1336,6 +1336,124 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \ +Example 2: Search using metadata and categories Filters + +```python Python +filters = { + "AND": [ + {"metadata": {"food": "vegan"}}, + { + "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 = { + "AND": [ + {"metadata": {"food": "vegan"}}, + { + "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": { + "AND": [ + {"metadata": {"food": "vegan"}}, + { + "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": { + "AND": [ + {"metadata": {"food": "vegan"}}, + { + "categories": { + "contains": "food_preferences" + } + } + ] + } + }' +``` + +```json Output (Default) +[ + { + "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", + "memory":"Name: Alex. Vegetarian. Allergic to nuts.", + "user_id":"alex", + "hash":"62bc074f56d1f909f1b4c2b639f56f6a", + "metadata":{"food":"vegan"}, + "immutable": false, + "created_at":"2024-07-25T23:57:00.108347-07:00", + "updated_at":"2024-07-25T23:57:00.108367-07:00", + "categories": ["food_preferences"] + } +] +``` + +```json Output (Paginated) +{ + "count": 1, + "next": null, + "previous": null, + "results": [ + { + "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", + "memory":"Name: Alex. Vegetarian. Allergic to nuts.", + "user_id":"alex", + "hash":"62bc074f56d1f909f1b4c2b639f56f6a", + "metadata":{"food":"vegan"}, + "immutable": false, + "created_at":"2024-07-25T23:57:00.108347-07:00", + "updated_at":"2024-07-25T23:57:00.108367-07:00", + "categories": ["food_preferences"] + } + ] +} +``` + + + ### 4.5 Memory History Get history of how a memory has changed over time.