From fd7fab4e0833b41458358c466a50df2cf6db89fb Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Fri, 15 Nov 2024 13:45:46 +0530 Subject: [PATCH] Doc: add example for filtering through categories and metadata (#2031) --- docs/platform/quickstart.mdx | 66 +++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index ea1725ff..f3ab774b 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -77,7 +77,7 @@ messages = [ client.add(messages, user_id="alex", output_format="v1.0") # To use the latest output_format, set the output_format parameter to "v1.1" -client.add(messages, user_id="alex", output_format="v1.1") +client.add(messages, user_id="alex", output_format="v1.1", metadata={"food": "vegan"}) ``` ```javascript JavaScript @@ -85,7 +85,7 @@ const messages = [ {"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."}, {"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."} ]; -client.add(messages, { user_id: "alex", output_format: "v1.1" }) +client.add(messages, { user_id: "alex", output_format: "v1.1", metadata: { food: "vegan" } }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` @@ -100,7 +100,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ {"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."} ], "user_id": "alex", - "output_format": "v1.1" + "output_format": "v1.1", + "metadata": { + "food": "vegan" + } }' ``` @@ -331,7 +334,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \ ], "user_id": "alex", "hash": "9ee7e1455e84d1dab700ed8749aed75a", - "metadata": null, + "metadata": {"food": "vegan"}, "categories": ["food_preferences"], "created_at": "2024-07-20T01:30:36.275141-07:00", "updated_at": "2024-07-20T01:30:36.275172-07:00" @@ -357,7 +360,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \ ], "user_id": "alex", "hash": "9ee7e1455e84d1dab700ed8749aed75a", - "metadata": null, + "metadata": {"food": "vegan"}, "categories": ["food_preferences"], "created_at": "2024-07-20T01:30:36.275141-07:00", "updated_at": "2024-07-20T01:30:36.275172-07:00" @@ -367,6 +370,59 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \ ``` +Use category and metadata filters: + + +```python Python +query = "What do you know about me?" + +client.search(query, categories=["food_preferences"], metadata={"food": "vegan"}) +``` + +```javascript JavaScript +const query = "What do you know about me?"; +client.search(query, categories=["food_preferences"], metadata={"food": "vegan"}) + .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?", + "categories": ["food_preferences"], + "metadata": {"food": "vegan"} + }' +``` + +```json Output +[ + { + "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5", + "memory": "Name: Alex. Vegetarian. Allergic to nuts.", + "input": [ + { + "role": "user", + "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts." + }, + { + "role": "assistant", + "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions." + } + ], + "user_id": "alex", + "hash": "9ee7e1455e84d1dab700ed8749aed75a", + "metadata": {"food": "vegan"}, + "categories": ["food_preferences"], + "created_at": "2024-07-20T01:30:36.275141-07:00", + "updated_at": "2024-07-20T01:30:36.275172-07:00" + } +] +``` + + #### Search using custom filters