From a140829395585a8060a23b2ad14962e3650208c4 Mon Sep 17 00:00:00 2001 From: Mragank Shekhar Date: Wed, 18 Feb 2026 03:27:46 +0530 Subject: [PATCH] chore: update user facing timestamp for a memory (#4066) --- docs/changelog.mdx | 16 ++++++++ .../memory-operations/update.mdx | 7 +++- mem0-ts/package.json | 2 +- mem0-ts/src/client/mem0.ts | 28 ++++++++++---- mem0/client/main.py | 37 +++++++++++++------ pyproject.toml | 2 +- 6 files changed, 69 insertions(+), 23 deletions(-) diff --git a/docs/changelog.mdx b/docs/changelog.mdx index 7146a61c9..1568c4935 100644 --- a/docs/changelog.mdx +++ b/docs/changelog.mdx @@ -7,6 +7,14 @@ mode: "wide" + + +**New Features & Updates:** +- **Memory Update:** + - Added `timestamp` parameter to `update()` — accepts Unix epoch (int/float) or ISO 8601 string + + + **New Features & Updates:** @@ -716,6 +724,14 @@ mode: "wide" + + +**New Features & Updates:** +- **Memory Update:** + - Added `timestamp` parameter to `update()` — accepts Unix epoch or ISO 8601 string + + + **New Features & Updates:** diff --git a/docs/core-concepts/memory-operations/update.mdx b/docs/core-concepts/memory-operations/update.mdx index b53b6b562..51ea3c8e1 100644 --- a/docs/core-concepts/memory-operations/update.mdx +++ b/docs/core-concepts/memory-operations/update.mdx @@ -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. - **text** / **data** – New content that replaces the stored memory value. - **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. - **immutable** – Flagged memories that must be deleted and re-added instead of updated. @@ -50,7 +51,8 @@ memory_id = "your_memory_id" client.update( memory_id=memory_id, 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, { text: "Updated memory content about the user", - metadata: { category: "profile-update" } + metadata: { category: "profile-update" }, + timestamp: "2025-01-15T12:00:00Z" }); ``` diff --git a/mem0-ts/package.json b/mem0-ts/package.json index bee822f0b..7075ec765 100644 --- a/mem0-ts/package.json +++ b/mem0-ts/package.json @@ -1,6 +1,6 @@ { "name": "mem0ai", - "version": "2.2.2", + "version": "2.2.3", "description": "The Memory Layer For Your AI Apps", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts index a57e3b0c5..1cd5a5aa4 100644 --- a/mem0-ts/src/client/mem0.ts +++ b/mem0-ts/src/client/mem0.ts @@ -253,18 +253,32 @@ export default class MemoryClient { async update( memoryId: string, - { text, metadata }: { text?: string; metadata?: Record }, + { + text, + metadata, + timestamp, + }: { + text?: string; + metadata?: Record; + timestamp?: number | string; + }, ): Promise> { - if (text === undefined && metadata === undefined) { - throw new Error("Either text or metadata must be provided for update."); + if ( + 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(); this._validateOrgProject(); - const payload = { - text: text, - metadata: metadata, - }; + const payload: Record = {}; + if (text !== undefined) payload.text = text; + if (metadata !== undefined) payload.metadata = metadata; + if (timestamp !== undefined) payload.timestamp = timestamp; const payloadKeys = Object.keys(payload); this._captureEvent("update", [payloadKeys]); diff --git a/mem0/client/main.py b/mem0/client/main.py index f2869cd13..6f9304717 100644 --- a/mem0/client/main.py +++ b/mem0/client/main.py @@ -2,7 +2,7 @@ import hashlib import logging import os import warnings -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union import httpx import requests @@ -300,29 +300,34 @@ class MemoryClient: memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, + timestamp: Optional[Union[int, float, str]] = None, ) -> Dict[str, Any]: """ Update a memory by ID. - + Args: memory_id (str): Memory ID. text (str, optional): New content to update the memory with. metadata (dict, optional): Metadata to update in the memory. - + timestamp (int, float, or str, optional): Unix epoch timestamp or ISO 8601 string. + Returns: Dict[str, Any]: The response from the server. - + Example: >>> 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: - raise ValueError("Either text or metadata must be provided for update.") + if text is None and metadata is None and timestamp is None: + raise ValueError("At least one of text, metadata, or timestamp must be provided for update.") payload = {} if text is not None: payload["text"] = text if metadata is not None: payload["metadata"] = metadata + if timestamp is not None: + payload["timestamp"] = timestamp capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "sync"}) params = self._prepare_params() @@ -1196,30 +1201,38 @@ class AsyncMemoryClient: @api_error_handler 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]: """ Update a memory by ID asynchronously. - + Args: memory_id (str): Memory ID. text (str, optional): New content to update the memory with. metadata (dict, optional): Metadata to update in the memory. - + timestamp (int, float, or str, optional): Unix epoch timestamp or ISO 8601 string. + Returns: Dict[str, Any]: The response from the server. - + Example: >>> 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: - raise ValueError("Either text or metadata must be provided for update.") + if text is None and metadata is None and timestamp is None: + raise ValueError("At least one of text, metadata, or timestamp must be provided for update.") payload = {} if text is not None: payload["text"] = text if metadata is not None: payload["metadata"] = metadata + if timestamp is not None: + payload["timestamp"] = timestamp capture_client_event("client.update", self, {"memory_id": memory_id, "sync_type": "async"}) params = self._prepare_params() diff --git a/pyproject.toml b/pyproject.toml index 279c81c4d..1915c4989 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "mem0ai" -version = "1.0.3" +version = "1.0.4" description = "Long-term memory for AI Agents" authors = [ { name = "Mem0", email = "founders@mem0.ai" }