fix: preserve custom metadata fields during memory update (#5480)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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() ────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user