Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

Doc: add example for filtering through categories and metadata (#2031)

Dev Khantfd7fab4e0833
diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx
index ea1725ff8..f3ab774b9 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/" \
```
</CodeGroup>
+Use category and metadata filters:
+<CodeGroup>
+
+```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"
+ }
+]
+```
+</CodeGroup>
+
#### Search using custom filters