chore: update user facing timestamp for a memory (#4066)
This commit is contained in:
@@ -7,6 +7,14 @@ mode: "wide"
|
|||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab title="Python">
|
<Tab title="Python">
|
||||||
|
|
||||||
|
<Update label="2026-02-17" description="v1.0.4">
|
||||||
|
|
||||||
|
**New Features & Updates:**
|
||||||
|
- **Memory Update:**
|
||||||
|
- Added `timestamp` parameter to `update()` — accepts Unix epoch (int/float) or ISO 8601 string
|
||||||
|
|
||||||
|
</Update>
|
||||||
|
|
||||||
<Update label="2026-01-29" description="v1.0.3">
|
<Update label="2026-01-29" description="v1.0.3">
|
||||||
|
|
||||||
**New Features & Updates:**
|
**New Features & Updates:**
|
||||||
@@ -716,6 +724,14 @@ mode: "wide"
|
|||||||
|
|
||||||
<Tab title="TypeScript">
|
<Tab title="TypeScript">
|
||||||
|
|
||||||
|
<Update label="2026-02-17" description="v2.2.3">
|
||||||
|
|
||||||
|
**New Features & Updates:**
|
||||||
|
- **Memory Update:**
|
||||||
|
- Added `timestamp` parameter to `update()` — accepts Unix epoch or ISO 8601 string
|
||||||
|
|
||||||
|
</Update>
|
||||||
|
|
||||||
<Update label="2026-01-29" description="v2.2.2">
|
<Update label="2026-01-29" description="v2.2.2">
|
||||||
|
|
||||||
**New Features & Updates:**
|
**New Features & Updates:**
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Mem0’s update operation lets you fix or enrich an existing memory without dele
|
|||||||
- **memory_id** – Unique identifier returned by `add` or `search` results.
|
- **memory_id** – Unique identifier returned by `add` or `search` results.
|
||||||
- **text** / **data** – New content that replaces the stored memory value.
|
- **text** / **data** – New content that replaces the stored memory value.
|
||||||
- **metadata** – Optional key-value pairs you update alongside the text.
|
- **metadata** – Optional key-value pairs you update alongside the text.
|
||||||
|
- **timestamp** – Unix epoch (int/float) or ISO 8601 string to override the memory's timestamp.
|
||||||
- **batch_update** – Platform API that edits multiple memories in a single request.
|
- **batch_update** – Platform API that edits multiple memories in a single request.
|
||||||
- **immutable** – Flagged memories that must be deleted and re-added instead of updated.
|
- **immutable** – Flagged memories that must be deleted and re-added instead of updated.
|
||||||
|
|
||||||
@@ -50,7 +51,8 @@ memory_id = "your_memory_id"
|
|||||||
client.update(
|
client.update(
|
||||||
memory_id=memory_id,
|
memory_id=memory_id,
|
||||||
text="Updated memory content about the user",
|
text="Updated memory content about the user",
|
||||||
metadata={"category": "profile-update"}
|
metadata={"category": "profile-update"},
|
||||||
|
timestamp="2025-01-15T12:00:00Z"
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -62,7 +64,8 @@ const memory_id = "your_memory_id";
|
|||||||
|
|
||||||
await client.update(memory_id, {
|
await client.update(memory_id, {
|
||||||
text: "Updated memory content about the user",
|
text: "Updated memory content about the user",
|
||||||
metadata: { category: "profile-update" }
|
metadata: { category: "profile-update" },
|
||||||
|
timestamp: "2025-01-15T12:00:00Z"
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mem0ai",
|
"name": "mem0ai",
|
||||||
"version": "2.2.2",
|
"version": "2.2.3",
|
||||||
"description": "The Memory Layer For Your AI Apps",
|
"description": "The Memory Layer For Your AI Apps",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
|||||||
@@ -253,18 +253,32 @@ export default class MemoryClient {
|
|||||||
|
|
||||||
async update(
|
async update(
|
||||||
memoryId: string,
|
memoryId: string,
|
||||||
{ text, metadata }: { text?: string; metadata?: Record<string, any> },
|
{
|
||||||
|
text,
|
||||||
|
metadata,
|
||||||
|
timestamp,
|
||||||
|
}: {
|
||||||
|
text?: string;
|
||||||
|
metadata?: Record<string, any>;
|
||||||
|
timestamp?: number | string;
|
||||||
|
},
|
||||||
): Promise<Array<Memory>> {
|
): Promise<Array<Memory>> {
|
||||||
if (text === undefined && metadata === undefined) {
|
if (
|
||||||
throw new Error("Either text or metadata must be provided for update.");
|
text === undefined &&
|
||||||
|
metadata === undefined &&
|
||||||
|
timestamp === undefined
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"At least one of text, metadata, or timestamp must be provided for update.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.telemetryId === "") await this.ping();
|
if (this.telemetryId === "") await this.ping();
|
||||||
this._validateOrgProject();
|
this._validateOrgProject();
|
||||||
const payload = {
|
const payload: Record<string, any> = {};
|
||||||
text: text,
|
if (text !== undefined) payload.text = text;
|
||||||
metadata: metadata,
|
if (metadata !== undefined) payload.metadata = metadata;
|
||||||
};
|
if (timestamp !== undefined) payload.timestamp = timestamp;
|
||||||
|
|
||||||
const payloadKeys = Object.keys(payload);
|
const payloadKeys = Object.keys(payload);
|
||||||
this._captureEvent("update", [payloadKeys]);
|
this._captureEvent("update", [payloadKeys]);
|
||||||
|
|||||||
+25
-12
@@ -2,7 +2,7 @@ import hashlib
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import requests
|
import requests
|
||||||
@@ -300,29 +300,34 @@ class MemoryClient:
|
|||||||
memory_id: str,
|
memory_id: str,
|
||||||
text: Optional[str] = None,
|
text: Optional[str] = None,
|
||||||
metadata: Optional[Dict[str, Any]] = None,
|
metadata: Optional[Dict[str, Any]] = None,
|
||||||
|
timestamp: Optional[Union[int, float, str]] = None,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Update a memory by ID.
|
Update a memory by ID.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): Memory ID.
|
memory_id (str): Memory ID.
|
||||||
text (str, optional): New content to update the memory with.
|
text (str, optional): New content to update the memory with.
|
||||||
metadata (dict, optional): Metadata to update in the memory.
|
metadata (dict, optional): Metadata to update in the memory.
|
||||||
|
timestamp (int, float, or str, optional): Unix epoch timestamp or ISO 8601 string.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict[str, Any]: The response from the server.
|
Dict[str, Any]: The response from the server.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
>>> client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
>>> client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
||||||
|
>>> client.update(memory_id="mem_123", timestamp="2025-01-15T12:00:00Z")
|
||||||
"""
|
"""
|
||||||
if text is None and metadata is None:
|
if text is None and metadata is None and timestamp is None:
|
||||||
raise ValueError("Either text or metadata must be provided for update.")
|
raise ValueError("At least one of text, metadata, or timestamp must be provided for update.")
|
||||||
|
|
||||||
payload = {}
|
payload = {}
|
||||||
if text is not None:
|
if text is not None:
|
||||||
payload["text"] = text
|
payload["text"] = text
|
||||||
if metadata is not None:
|
if metadata is not None:
|
||||||
payload["metadata"] = metadata
|
payload["metadata"] = metadata
|
||||||
|
if timestamp is not None:
|
||||||
|
payload["timestamp"] = timestamp
|
||||||
|
|
||||||
capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "sync"})
|
capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "sync"})
|
||||||
params = self._prepare_params()
|
params = self._prepare_params()
|
||||||
@@ -1196,30 +1201,38 @@ class AsyncMemoryClient:
|
|||||||
|
|
||||||
@api_error_handler
|
@api_error_handler
|
||||||
async def update(
|
async def update(
|
||||||
self, memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None
|
self,
|
||||||
|
memory_id: str,
|
||||||
|
text: Optional[str] = None,
|
||||||
|
metadata: Optional[Dict[str, Any]] = None,
|
||||||
|
timestamp: Optional[Union[int, float, str]] = None,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Update a memory by ID asynchronously.
|
Update a memory by ID asynchronously.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): Memory ID.
|
memory_id (str): Memory ID.
|
||||||
text (str, optional): New content to update the memory with.
|
text (str, optional): New content to update the memory with.
|
||||||
metadata (dict, optional): Metadata to update in the memory.
|
metadata (dict, optional): Metadata to update in the memory.
|
||||||
|
timestamp (int, float, or str, optional): Unix epoch timestamp or ISO 8601 string.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict[str, Any]: The response from the server.
|
Dict[str, Any]: The response from the server.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
>>> await client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
>>> await client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
||||||
|
>>> await client.update(memory_id="mem_123", timestamp="2025-01-15T12:00:00Z")
|
||||||
"""
|
"""
|
||||||
if text is None and metadata is None:
|
if text is None and metadata is None and timestamp is None:
|
||||||
raise ValueError("Either text or metadata must be provided for update.")
|
raise ValueError("At least one of text, metadata, or timestamp must be provided for update.")
|
||||||
|
|
||||||
payload = {}
|
payload = {}
|
||||||
if text is not None:
|
if text is not None:
|
||||||
payload["text"] = text
|
payload["text"] = text
|
||||||
if metadata is not None:
|
if metadata is not None:
|
||||||
payload["metadata"] = metadata
|
payload["metadata"] = metadata
|
||||||
|
if timestamp is not None:
|
||||||
|
payload["timestamp"] = timestamp
|
||||||
|
|
||||||
capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "async"})
|
capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "async"})
|
||||||
params = self._prepare_params()
|
params = self._prepare_params()
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "mem0ai"
|
name = "mem0ai"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
description = "Long-term memory for AI Agents"
|
description = "Long-term memory for AI Agents"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Mem0", email = "founders@mem0.ai" }
|
{ name = "Mem0", email = "founders@mem0.ai" }
|
||||||
|
|||||||
Reference in New Issue
Block a user