Skip to content

Commit

Permalink
Doc: add example for filtering through categories and metadata (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-Khant authored Nov 15, 2024
1 parent e909e3e commit fd7fab4
Showing 1 changed file with 61 additions and 5 deletions.
66 changes: 61 additions & 5 deletions docs/platform/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ 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
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));
```
Expand All @@ -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"
}
}'
```

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit fd7fab4

Please sign in to comment.