From 47afe52296f2985e2e021a7195c7a9791cc5e8ef Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Wed, 31 Jul 2024 11:43:30 +0530 Subject: [PATCH] Add update method in client (#1615) --- docs/platform/quickstart.mdx | 43 +++++++++++++++++++++++++++++++++++- mem0/client/main.py | 14 ++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index 68182a5e..d16b60a3 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -495,7 +495,48 @@ curl -X GET "https://api.mem0.ai/v1/memories//history/" \ ``` -### 4.5 Delete Memory +### 4.5 Update Memory + +Update a memory with new data. + + + +```python Python +message = "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.." +client.update(memory_id, message) +``` + +```javascript JavaScript +const message = "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.."; +client.update("memory-id-here", message) + .then(result => console.log(result)) + .catch(error => console.error(error)); +``` + +```bash cURL +curl -X PUT "https://api.mem0.ai/v1/memories/memory-id-here" \ + -H "Authorization: Token your-api-key" \ + -H "Content-Type: application/json" \ + -d '{ + "message": "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.." + }' +``` + +```json Output +{ + "id":"c190ab1a-a2f1-4f6f-914a-495e9a16b76e", + "memory":"I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes..", + "agent_id":"travel-assistant", + "hash":"af1161983e03667063d1abb60e6d5c06", + "metadata":"None", + "created_at":"2024-07-30T22:46:40.455758-07:00", + "updated_at":"2024-07-30T22:48:35.257828-07:00" +} +``` + + + +### 4.6 Delete Memory Delete specific memory: diff --git a/mem0/client/main.py b/mem0/client/main.py index c4491964..058a9e57 100644 --- a/mem0/client/main.py +++ b/mem0/client/main.py @@ -168,6 +168,20 @@ class MemoryClient: capture_client_event("client.search", self, {"limit": kwargs.get("limit", 100)}) return response.json() + @api_error_handler + def update(self, memory_id: str, data: str) -> Dict[str, Any]: + """ + Update a memory by ID. + Args: + memory_id (str): Memory ID. + data (str): Data to update in the memory. + Returns: + Dict[str, Any]: The response from the server. + """ + capture_client_event("client.update", self) + response = self.client.put(f"/memories/{memory_id}/", json={"text": data}) + return response.json() + @api_error_handler def delete(self, memory_id: str) -> Dict[str, Any]: """Delete a specific memory by ID.