From acf7a30d323096fdd1db92801d7c7ce6bf1b8fe7 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Wed, 25 Jun 2025 23:21:49 +0530 Subject: [PATCH] Doc: Add async_mode (#3037) --- docs/openapi.json | 6 ++++ docs/platform/quickstart.mdx | 55 +++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/docs/openapi.json b/docs/openapi.json index ffda5389..2f2d24f1 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -4910,6 +4910,12 @@ "type": "boolean", "default": false }, + "async_mode": { + "description": "Whether to add the memory completely asynchronously.", + "title": "Async mode", + "type": "boolean", + "default": false + }, "timestamp": { "description": "The timestamp of the memory. Format: Unix timestamp", "title": "Timestamp", diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index 4ad76026..3b7249c6 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -349,6 +349,59 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ + +#### Async Memory Addition + +When you set `async_mode=True`, memory processing happens completely asynchronously in the background. This allows for faster API responses while your memories are processed. The memories will be available on the dashboard and for retrieval within a few seconds. + + + +```python Python +messages = [ + {"role": "user", "content": "I love hiking and outdoor activities"}, + {"role": "assistant", "content": "That's great! I'll remember your interest in hiking and outdoor activities for future recommendations."} +] + +client.add(messages, user_id="alex", async_mode=True) +``` + +```javascript JavaScript +const messages = [ + {"role": "user", "content": "I love hiking and outdoor activities"}, + {"role": "assistant", "content": "That's great! I'll remember your interest in hiking and outdoor activities for future recommendations."} +]; + +client.add(messages, { user_id: "alex", async_mode: true }) + .then(response => console.log(response)) + .catch(error => console.error(error)); +``` + +```bash cURL +curl -X POST "https://api.mem0.ai/v1/memories/" \ + -H "Authorization: Token your-api-key" \ + -H "Content-Type: application/json" \ + -d '{ + "messages": [ + {"role": "user", "content": "I love hiking and outdoor activities"}, + {"role": "assistant", "content": "That's great! I'll remember your interest in hiking and outdoor activities for future recommendations."} + ], + "user_id": "alex", + "async_mode": true + }' +``` + +```json Output +{ + "results": [ + { + "message": "Memory processing has been queued for background execution" + } + ] +} +``` + + + #### Monitor Memories You can monitor memory operations on the platform dashboard: @@ -1347,7 +1400,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \ "memory":"Name: Alex. Vegetarian. Allergic to nuts.", "user_id":"alex", "hash":"62bc074f56d1f909f1b4c2b639f56f6a", - "metadata":null, + "metadata":None, "immutable": false, "expiration_date": null, "created_at":"2024-07-25T23:57:00.108347-07:00",