diff --git a/docs/openapi.json b/docs/openapi.json index 97527fc8..b74dd358 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -4900,6 +4900,13 @@ "type": "boolean", "default": false }, + "timestamp": { + "description": "The timestamp of the memory. Format: Unix timestamp", + "title": "Timestamp", + "type": "integer", + "nullable": true, + "default": null + }, "expiration_date": { "description": "The date and time when the memory will expire. Format: YYYY-MM-DD", "title": "Expiration date", diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index c049acb2..d328897d 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -327,6 +327,71 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ +#### Add custom timestamp + +You can provide a custom timestamp when adding memories to specify when the memory was created. This is useful for historical data or when you want to maintain specific chronology of memories that were generated in the past. + + + +```python Python +import time +from datetime import datetime, timedelta + +# Get the current time +current_time = datetime.now() + +# Calculate 5 days ago +five_days_ago = current_time - timedelta(days=5) + +# Convert to Unix timestamp (seconds since epoch) +unix_timestamp = int(five_days_ago.timestamp()) + +# Add memory with custom timestamp +client.add("I'm travelling to SF", user_id="user1", timestamp=unix_timestamp) +``` + +```javascript JavaScript +// Get the current time +const currentTime = new Date(); + +// Calculate 5 days ago +const fiveDaysAgo = new Date(); +fiveDaysAgo.setDate(currentTime.getDate() - 5); + +// Convert to Unix timestamp (seconds since epoch) +const unixTimestamp = Math.floor(fiveDaysAgo.getTime() / 1000); + +// Add memory with custom timestamp +client.add("I'm travelling to SF", { user_id: "user1", timestamp: unixTimestamp }) + .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'm travelling to SF"}], + "user_id": "user1", + "timestamp": 1721577600 + }' +``` + +```json Output +{ + "results": [ + { + "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5", + "data": {"memory": "Travelling to SF"}, + "event": "ADD" + } + ] +} +``` + + + #### Setting Memory Expiration Date You can set an expiration date for memories, after which they will no longer be retrieved in searches. This is useful for creating temporary memories or memories that are only relevant for a specific time period.