{"record":{"id":"9a6847564d0ea1b1","repo":"mem0ai/mem0","slug":"memory-with-id-memoryid-not-found","errorCode":null,"errorMessage":"Memory with ID ${memoryId} not found","messagePattern":"Memory with ID (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/memory/index.ts","lineNumber":1959,"sourceCode":"      memoryId,\n      null,\n      data,\n      \"ADD\",\n      memoryMetadata.createdAt,\n    );\n\n    return memoryId;\n  }\n\n  private async updateMemory(\n    memoryId: string,\n    data: string | undefined,\n    existingEmbeddings: Record<string, number[]>,\n    metadata: Record<string, any> = {},\n  ): Promise<string> {\n    const existingMemory = await this.vectorStore.get(memoryId);\n    if (!existingMemory) {\n      throw new Error(`Memory with ID ${memoryId} not found`);\n    }\n\n    const prevValue = existingMemory.payload.data;\n    // Metadata-only update: fall back to the stored text so we can re-index it.\n    const newData = data ?? prevValue;\n    if (typeof newData !== \"string\") {\n      throw new Error(\n        `Memory with ID ${memoryId} does not have text content to update`,\n      );\n    }\n    const textChanged = newData !== prevValue;\n\n    const embedding = Object.prototype.hasOwnProperty.call(\n      existingEmbeddings,\n      newData,\n    )\n      ? existingEmbeddings[newData]\n      : await this.embedder.embed(newData, \"update\");","sourceCodeStart":1941,"sourceCodeEnd":1977,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/memory/index.ts#L1941-L1977","documentation":"Internal guard in the private updateMemory(): the memory ID is not present in the vector store (vectorStore.get(id) returned null) before attempting an update. It usually surfaces through the public update()/add() reconciliation flow when a stale or already-deleted memory ID is referenced, e.g. in linked_memory_ids or an inferred-update path.","triggerScenarios":"updateMemory(memoryId) is called with an ID that does not exist in the vector store — deleted by another process, expired and cleaned up, from a different environment, or a typo'd/hallucinated ID (LLM extraction can emit IDs that no longer resolve).","commonSituations":"Holding a memory ID across a long session while another client deletes or resets the store; multi-instance deployments where one instance resets the vector DB; LLM extraction returning linked IDs from a previous conversation state.","solutions":["Verify the ID exists first with memory.get(memoryId) and skip gracefully if null","If IDs are persisted long-term, re-fetch them per session instead of caching","In multi-writer setups, coordinate resets so no client holds stale IDs"],"exampleFix":"// before\nawait memory.update(staleId, { text: 'updated' });\n\n// after\nconst mem = await memory.get(staleId);\nif (mem) {\n  await memory.update(staleId, { text: 'updated' });\n}","handlingStrategy":"try-catch","validationCode":"const existing = await memory.get(memoryId);\nif (!existing) {\n  // stale reference — refresh your memory list and skip\n}","typeGuard":null,"tryCatchPattern":"try { await memory.update(id, { text }); } catch (e) { if (e instanceof Error && e.message.includes('not found')) { await refreshMemoryList(); return; } throw e; }","preventionTips":["Do not cache memory IDs across store resets or long sessions — re-fetch before mutating","In multi-instance deployments, coordinate who may call reset() while others hold references"],"tags":["oss","memory-update","not-found","internal"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}