From 5660fffa964ac0b6fa9280df0cfe25cc447bdd87 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Wed, 26 Feb 2025 00:04:38 +0530 Subject: [PATCH] Doc: update example on quickstart (#2255) --- docs/features/async-client.mdx | 2 +- docs/features/direct-import.mdx | 2 +- docs/quickstart.mdx | 154 +++++++++++++++++--------------- 3 files changed, 82 insertions(+), 76 deletions(-) diff --git a/docs/features/async-client.mdx b/docs/features/async-client.mdx index c520ba88..1ee048fa 100644 --- a/docs/features/async-client.mdx +++ b/docs/features/async-client.mdx @@ -64,7 +64,7 @@ Search for memories based on a query asynchronously. ```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 diff --git a/docs/features/direct-import.mdx b/docs/features/direct-import.mdx index 64cbf2aa..a1619ece 100644 --- a/docs/features/direct-import.mdx +++ b/docs/features/direct-import.mdx @@ -41,7 +41,7 @@ You can retrieve memories using the `search` method. ```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 diff --git a/docs/quickstart.mdx b/docs/quickstart.mdx index db0ef920..54f05c49 100644 --- a/docs/quickstart.mdx +++ b/docs/quickstart.mdx @@ -78,16 +78,20 @@ const client = new MemoryClient({ apiKey: 'your-api-key' }); ```python Python 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."} + {"role": "user", "content": "Thinking of making a sandwich. What do you recommend?"}, + {"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") ``` ```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."} + {"role": "user", "content": "Thinking of making a sandwich. What do you recommend?"}, + {"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" }) .then(response => console.log(response)) @@ -100,8 +104,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ -H "Content-Type: application/json" \ -d '{ "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."} + {"role": "user", "content": "I live in San Francisco. Thinking of making a sandwich. What do you recommend?"}, + {"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" }' @@ -109,13 +115,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ ```json Output [{'id': '24e466b5-e1c6-4bde-8a92-f09a327ffa60', - 'memory': 'Name is Alex', + 'memory': 'Does not like cheese', 'event': 'ADD'}, - {'id': 'f2d874ac-09c7-49db-b34a-22cf666bd4ad', - 'memory': 'Is a vegetarian', - 'event': 'ADD'}, - {'id': 'bce04006-01e8-4dbc-8a22-67fa46f1822c', - 'memory': 'Is allergic to nuts', + {'id': 'e8d78459-fadd-4c5a-bece-abb8c3dc7ed7', + 'memory': 'Lives in San Francisco', 'event': 'ADD'}] ``` @@ -129,7 +132,8 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ ```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 = { "AND": [ { @@ -141,7 +145,7 @@ client.search(query, version="v2", filters=filters) ``` ```javascript JavaScript -const query = "What can I cook for dinner tonight?"; +const query = "I'm craving some pizza. Any recommendations?"; const filters = { "AND": [ { @@ -159,7 +163,7 @@ 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 can I cook for dinner tonight?", + "query": "I'm craving some pizza. Any recommendations?", "filters": { "AND": [ { @@ -174,11 +178,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \ [ { "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5", - "memory": "Name: Alex. Vegetarian. Allergic to nuts.", + "memory": "Does not like cheese", "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" + "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 = { "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 = { "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 [ - { - "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", - "memory":"是素食主义者,对坚果过敏。", - "agent_id":"travel-assistant", - "hash":"62bc074f56d1f909f1b4c2b639f56f6a", - "metadata":"None", - "created_at":"2024-07-25T23:57:00.108347-07:00", - "updated_at":"2024-07-25T23:57:00.108367-07:00" - }, - { - "id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878", - "memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.", - "agent_id":"travel-assistant", - "hash":"35a305373d639b0bffc6c2a3e2eb4244", - "metadata":"None", - "created_at":"2024-07-26T00:31:03.543759-07:00", - "updated_at":"2024-07-26T00:31:03.543778-07:00" - } + { + "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5", + "memory": "Does not like cheese", + "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.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 + } ] ``` @@ -293,12 +307,15 @@ m = Memory() ```python Code # 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 -[{'id': 'ea9b08ee-09d7-4e8b-9912-687ad65548b4', - 'memory': 'Likes to take long walks on weekends', +[{'id': '3dc6f65f-fb3f-4e91-89a8-ed1a22f8898a', + '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'}] ``` @@ -311,48 +328,37 @@ result = m.add("I like to take long walks on weekends.", user_id="alice", metada ```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 [ - { - "id":"ea925981-272f-40dd-b576-be64e4871429", - "memory":"Likes to take long walks on weekends.", - "hash":"c8809002-25c1-4c97-a3a2-227ce9c20c53", - "metadata":{ - "category":"hobbies" - }, - "score":0.32116443111457704, - "created_at":"2024-07-26T10:29:36.630547-07:00", - "updated_at":"None", - "user_id":"alice" - } + { + 'id': '3dc6f65f-fb3f-4e91-89a8-ed1a22f8898a', + 'memory': 'Likes to drink coffee in the morning', + 'user_id': 'alice', + 'metadata': {'category': 'preferences'}, + 'categories': ['user_preferences', 'food'], + 'immutable': False, + 'created_at': '2025-02-24T20:11:39.010261-08:00', + 'updated_at': '2025-02-24T20:11:39.010274-08:00', + 'score': 0.5915589089130715 + }, + { + '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 + } ] ``` - - - -```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" - } -] -``` -