Doc: add timestamp (#2580)

This commit is contained in:
Dev Khant
2025-04-23 01:05:16 +05:30
committed by GitHub
parent ba2e479902
commit d43ca06992
2 changed files with 72 additions and 0 deletions

View File

@@ -4900,6 +4900,13 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"timestamp": {
"description": "The timestamp of the memory. Format: Unix timestamp",
"title": "Timestamp",
"type": "integer",
"nullable": true,
"default": null
},
"expiration_date": { "expiration_date": {
"description": "The date and time when the memory will expire. Format: YYYY-MM-DD", "description": "The date and time when the memory will expire. Format: YYYY-MM-DD",
"title": "Expiration date", "title": "Expiration date",

View File

@@ -327,6 +327,71 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
</CodeGroup> </CodeGroup>
#### 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.
<CodeGroup>
```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"
}
]
}
```
</CodeGroup>
#### Setting Memory Expiration Date #### 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. 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.