fix: preserve custom metadata fields during memory update (#5480)

This commit is contained in:
Hrushikesh Yadav
2026-06-15 16:29:44 +05:30
committed by GitHub
parent 3ef034a9e4
commit 4d949022f2
4 changed files with 176 additions and 30 deletions
+2 -9
View File
@@ -1722,20 +1722,13 @@ export class Memory {
existingEmbeddings[data] || (await this.embedder.embed(data));
const newMetadata = {
...existingMemory.payload,
...metadata,
data,
hash: createHash("md5").update(data).digest("hex"),
textLemmatized: lemmatizeForBm25(data),
createdAt: existingMemory.payload.createdAt,
updatedAt: new Date().toISOString(),
...(existingMemory.payload.user_id && {
user_id: existingMemory.payload.user_id,
}),
...(existingMemory.payload.agent_id && {
agent_id: existingMemory.payload.agent_id,
}),
...(existingMemory.payload.run_id && {
run_id: existingMemory.payload.run_id,
}),
};
await this.vectorStore.update(memoryId, embedding, newMetadata);
+15
View File
@@ -191,6 +191,21 @@ describe("Memory - update()", () => {
const after: MemoryItem | null = await memory.get(id);
expect(after!.hash).not.toBe(before!.hash);
});
test("preserves custom metadata fields after update", async () => {
const addResult: SearchResult = await memory.add("Original text", {
userId,
metadata: { category: "hobbies", priority: "high" },
infer: false,
});
const id = addResult.results[0].id;
await memory.update(id, "Updated text");
const after: MemoryItem | null = await memory.get(id);
expect(after!.memory).toBe("Updated text");
expect(after!.metadata).toEqual(
expect.objectContaining({ category: "hobbies", priority: "high" }),
);
});
});
// ─── delete() ────────────────────────────────────────────