diff --git a/src/resources/extensions/sf/memory-store.ts b/src/resources/extensions/sf/memory-store.ts index 2be41d872..db2217217 100644 --- a/src/resources/extensions/sf/memory-store.ts +++ b/src/resources/extensions/sf/memory-store.ts @@ -6,6 +6,7 @@ import { _getAdapter, decayMemoriesBefore, + deleteMemoryEmbedding, incrementMemoryHitCount, insertMemoryRow, isDbAvailable, @@ -270,6 +271,12 @@ export function createMemory(fields: { /** * Update a memory's content and optionally its confidence. + * + * Invalidates the existing embedding row (if any): the stored vector was + * computed against the old content and would otherwise rank incorrectly + * on the next cosine query. The next runEmbeddingBackfill sweep will + * re-embed the new content. This is best-effort — a missing embedding + * row is the silent-fallback case the ranker already handles. */ export function updateMemoryContent( id: string, @@ -280,6 +287,12 @@ export function updateMemoryContent( try { updateMemoryContentRow(id, content, confidence, new Date().toISOString()); + try { + deleteMemoryEmbedding(id); + } catch { + // Stale-vector window is brief (until next backfill); never fail + // the content update because the embedding cleanup raised. + } return true; } catch { return false;