Doc: update example on quickstart (#2255)

This commit is contained in:
Dev Khant
2025-02-26 00:04:38 +05:30
committed by GitHub
parent eba6f77330
commit 5660fffa96
3 changed files with 82 additions and 76 deletions

View File

@@ -64,7 +64,7 @@ Search for memories based on a query asynchronously.
<CodeGroup> <CodeGroup>
```python Python ```python Python
await client.search(query="What is Alice's favorite sport?", user_id="alice") await client.search("What is Alice's favorite sport?", user_id="alice")
``` ```
```javascript JavaScript ```javascript JavaScript

View File

@@ -41,7 +41,7 @@ You can retrieve memories using the `search` method.
<CodeGroup> <CodeGroup>
```python Python ```python Python
client.search(query="What is Alice's favorite sport?", user_id="alice", output_format="v1.1") client.search("What is Alice's favorite sport?", user_id="alice", output_format="v1.1")
``` ```
```json Output ```json Output

View File

@@ -78,16 +78,20 @@ const client = new MemoryClient({ apiKey: 'your-api-key' });
```python Python ```python Python
messages = [ messages = [
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."}, {"role": "user", "content": "Thinking of making a sandwich. What do you recommend?"},
{"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."} {"role": "assistant", "content": "How about adding some cheese for extra flavor?"},
{"role": "user", "content": "Actually, I don't like cheese."},
{"role": "assistant", "content": "I'll remember that you don't like cheese for future recommendations."}
] ]
client.add(messages, user_id="alex") client.add(messages, user_id="alex")
``` ```
```javascript JavaScript ```javascript JavaScript
const messages = [ const messages = [
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."}, {"role": "user", "content": "Thinking of making a sandwich. What do you recommend?"},
{"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."} {"role": "assistant", "content": "How about adding some cheese for extra flavor?"},
{"role": "user", "content": "Actually, I don't like cheese."},
{"role": "assistant", "content": "I'll remember that you don't like cheese for future recommendations."}
]; ];
client.add(messages, { user_id: "alex" }) client.add(messages, { user_id: "alex" })
.then(response => console.log(response)) .then(response => console.log(response))
@@ -100,8 +104,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"messages": [ "messages": [
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."}, {"role": "user", "content": "I live in San Francisco. Thinking of making a sandwich. What do you recommend?"},
{"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."} {"role": "assistant", "content": "How about adding some cheese for extra flavor?"},
{"role": "user", "content": "Actually, I don't like cheese."},
{"role": "assistant", "content": "I'll remember that you don't like cheese for future recommendations."}
], ],
"user_id": "alex" "user_id": "alex"
}' }'
@@ -109,13 +115,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
```json Output ```json Output
[{'id': '24e466b5-e1c6-4bde-8a92-f09a327ffa60', [{'id': '24e466b5-e1c6-4bde-8a92-f09a327ffa60',
'memory': 'Name is Alex', 'memory': 'Does not like cheese',
'event': 'ADD'}, 'event': 'ADD'},
{'id': 'f2d874ac-09c7-49db-b34a-22cf666bd4ad', {'id': 'e8d78459-fadd-4c5a-bece-abb8c3dc7ed7',
'memory': 'Is a vegetarian', 'memory': 'Lives in San Francisco',
'event': 'ADD'},
{'id': 'bce04006-01e8-4dbc-8a22-67fa46f1822c',
'memory': 'Is allergic to nuts',
'event': 'ADD'}] 'event': 'ADD'}]
``` ```
</CodeGroup> </CodeGroup>
@@ -129,7 +132,8 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
<CodeGroup> <CodeGroup>
```python Python ```python Python
query = "What can I cook for dinner tonight?" # Example showing location and preference-aware recommendations
query = "I'm craving some pizza. Any recommendations?"
filters = { filters = {
"AND": [ "AND": [
{ {
@@ -141,7 +145,7 @@ client.search(query, version="v2", filters=filters)
``` ```
```javascript JavaScript ```javascript JavaScript
const query = "What can I cook for dinner tonight?"; const query = "I'm craving some pizza. Any recommendations?";
const filters = { const filters = {
"AND": [ "AND": [
{ {
@@ -159,7 +163,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
-H "Authorization: Token your-api-key" \ -H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"query": "What can I cook for dinner tonight?", "query": "I'm craving some pizza. Any recommendations?",
"filters": { "filters": {
"AND": [ "AND": [
{ {
@@ -174,11 +178,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
[ [
{ {
"id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5", "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
"memory": "Name: Alex. Vegetarian. Allergic to nuts.", "memory": "Does not like cheese",
"user_id": "alex", "user_id": "alex",
"metadata": null, "metadata": null,
"created_at": "2024-07-20T01:30:36.275141-07:00", "created_at": "2024-07-20T01:30:36.275141-07:00",
"updated_at": "2024-07-20T01:30:36.275172-07:00" "updated_at": "2024-07-20T01:30:36.275172-07:00",
"score": 0.92
},
{
"id": "8f165f7e-b411-4afe-b7e5-35789b72c4b6",
"memory": "Lives in San Francisco",
"user_id": "alex",
"metadata": null,
"created_at": "2024-07-20T01:30:36.275141-07:00",
"updated_at": "2024-07-20T01:30:36.275172-07:00",
"score": 0.85
} }
] ]
``` ```
@@ -193,7 +207,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
filters = { filters = {
"AND": [ "AND": [
{ {
"user_id": "alice" "user_id": "alex"
} }
] ]
} }
@@ -205,7 +219,7 @@ all_memories = client.get_all(version="v2", filters=filters, page=1, page_size=5
const filters = { const filters = {
"AND": [ "AND": [
{ {
"user_id": "alice" "user_id": "alex"
} }
] ]
}; };
@@ -232,24 +246,24 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \
```json Output ```json Output
[ [
{ {
"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
"memory":"是素食主义者,对坚果过敏。", "memory": "Does not like cheese",
"agent_id":"travel-assistant", "user_id": "alex",
"hash":"62bc074f56d1f909f1b4c2b639f56f6a", "metadata": null,
"metadata":"None", "created_at": "2024-07-20T01:30:36.275141-07:00",
"created_at":"2024-07-25T23:57:00.108347-07:00", "updated_at": "2024-07-20T01:30:36.275172-07:00",
"updated_at":"2024-07-25T23:57:00.108367-07:00" "score": 0.92
}, },
{ {
"id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878", "id": "8f165f7e-b411-4afe-b7e5-35789b72c4b6",
"memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.", "memory": "Lives in San Francisco",
"agent_id":"travel-assistant", "user_id": "alex",
"hash":"35a305373d639b0bffc6c2a3e2eb4244", "metadata": null,
"metadata":"None", "created_at": "2024-07-20T01:30:36.275141-07:00",
"created_at":"2024-07-26T00:31:03.543759-07:00", "updated_at": "2024-07-20T01:30:36.275172-07:00",
"updated_at":"2024-07-26T00:31:03.543778-07:00" "score": 0.85
} }
] ]
``` ```
</CodeGroup> </CodeGroup>
@@ -293,12 +307,15 @@ m = Memory()
<CodeGroup> <CodeGroup>
```python Code ```python Code
# For a user # For a user
result = m.add("I like to take long walks on weekends.", user_id="alice", metadata={"category": "hobbies"}) result = m.add("I like to drink coffee in the morning and go for a walk.", user_id="alice", metadata={"category": "preferences"})
``` ```
```json Output ```json Output
[{'id': 'ea9b08ee-09d7-4e8b-9912-687ad65548b4', [{'id': '3dc6f65f-fb3f-4e91-89a8-ed1a22f8898a',
'memory': 'Likes to take long walks on weekends', 'data': {'memory': 'Likes to drink coffee in the morning'},
'event': 'ADD'},
{'id': 'f1673706-e3d6-4f12-a767-0384c7697d53',
'data': {'memory': 'Likes to go for a walk'},
'event': 'ADD'}] 'event': 'ADD'}]
``` ```
</CodeGroup> </CodeGroup>
@@ -311,48 +328,37 @@ result = m.add("I like to take long walks on weekends.", user_id="alice", metada
<Accordion title="Search for relevant memories"> <Accordion title="Search for relevant memories">
<CodeGroup> <CodeGroup>
```python Code ```python Code
related_memories = m.search(query="Help me plan my weekend.", user_id="alice") related_memories = m.search("Should I drink coffee or tea?", user_id="alice")
``` ```
```json Output ```json Output
[ [
{ {
"id":"ea925981-272f-40dd-b576-be64e4871429", 'id': '3dc6f65f-fb3f-4e91-89a8-ed1a22f8898a',
"memory":"Likes to take long walks on weekends.", 'memory': 'Likes to drink coffee in the morning',
"hash":"c8809002-25c1-4c97-a3a2-227ce9c20c53", 'user_id': 'alice',
"metadata":{ 'metadata': {'category': 'preferences'},
"category":"hobbies" 'categories': ['user_preferences', 'food'],
}, 'immutable': False,
"score":0.32116443111457704, 'created_at': '2025-02-24T20:11:39.010261-08:00',
"created_at":"2024-07-26T10:29:36.630547-07:00", 'updated_at': '2025-02-24T20:11:39.010274-08:00',
"updated_at":"None", 'score': 0.5915589089130715
"user_id":"alice" },
} {
'id': 'e8d78459-fadd-4c5a-bece-abb8c3dc7ed7',
'memory': 'Likes to go for a walk',
'user_id': 'alice',
'metadata': {'category': 'preferences'},
'categories': ['hobby', 'food'],
'immutable': False,
'created_at': '2025-02-24T11:47:52.893038-08:00',
'updated_at': '2025-02-24T11:47:52.893048-08:00',
'score': 0.43263634637810866
}
] ]
``` ```
</CodeGroup> </CodeGroup>
</Accordion>
<Accordion title="Get all memories of a user">
<CodeGroup>
```python Code
# Get all memories
all_memories = m.get_all(user_id="alice")
```
```json Output
[
{
"id":"13efe83b-a8df-4ec0-814e-428d6e8451eb",
"memory":"Likes to take long walks on weekends",
"hash":"87bcddeb-fe45-4353-bc22-15a841c50308",
"metadata":"None",
"created_at":"2024-07-26T08:44:41.039788-07:00",
"updated_at":"None",
"user_id":"alice"
}
]
```
</CodeGroup>
</Accordion> </Accordion>
</AccordionGroup> </AccordionGroup>