Skip to content

Commit 6e6bd56

Browse files
committed
fix(memory): rebuild migrated search indexes
1 parent 28fb5b0 commit 6e6bd56

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

extensions/memory-core/src/memory/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ describe("memory index", () => {
17161716
expect(status.vector?.available).toBe(available);
17171717
});
17181718

1719-
it("drops the shipped legacy vector table after loading sqlite-vec", async () => {
1719+
it("drops the shipped legacy vector table and schedules a full reindex", async () => {
17201720
const cfg = createCfg({ vectorEnabled: true });
17211721
const manager = await getPersistentManager(cfg);
17221722
const db = Reflect.get(manager, "db") as DatabaseSync;
@@ -1732,6 +1732,7 @@ describe("memory index", () => {
17321732
.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'chunks_vec'")
17331733
.get(),
17341734
).toBeUndefined();
1735+
expect(Reflect.get(manager, "memoryFullRetryDirty")).toBe(true);
17351736
});
17361737

17371738
it("probes sqlite vector store availability without initializing embeddings", async () => {

extensions/memory-core/src/memory/manager-sync-ops.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ export abstract class MemoryManagerSyncOps {
650650
this.vector.extensionPath = loaded.extensionPath;
651651
this.vector.available = true;
652652
if (this.dropLegacyVectorTable()) {
653+
// A broad dirty sync can skip unchanged files whose source hashes were
654+
// migrated. Force the next sync to republish the derived vector rows.
653655
this.dirty = true;
656+
this.memoryFullRetryDirty = true;
654657
}
655658
return true;
656659
} catch (err) {

packages/memory-host-sdk/src/host/memory-schema.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ describe("memory index schema", () => {
6969
expect(db.prepare("SELECT id, text FROM memory_index_chunks").all()).toEqual([
7070
{ id: "chunk-1", text: "remember this" },
7171
]);
72+
expect(db.prepare("SELECT id, text FROM memory_index_chunks_fts").all()).toEqual([
73+
{ id: "chunk-1", text: "remember this" },
74+
]);
7275
expect(db.prepare("SELECT provider, hash FROM memory_embedding_cache").all()).toEqual([
7376
{ provider: "openai", hash: "chunk-hash" },
7477
]);

packages/memory-host-sdk/src/host/memory-schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ export function ensureMemoryIndexSchema(params: {
367367
` end_line UNINDEXED\n` +
368368
`${tokenizeClause});`,
369369
);
370+
// The shipped generic-table migration and a later FTS enablement both
371+
// create an empty derived table beside already-canonical chunk rows.
372+
params.db.exec(`
373+
INSERT INTO ${MEMORY_INDEX_FTS_TABLE} (
374+
text, id, path, source, model, start_line, end_line
375+
)
376+
SELECT text, id, path, source, model, start_line, end_line
377+
FROM ${MEMORY_INDEX_CHUNKS_TABLE}
378+
WHERE NOT EXISTS (SELECT 1 FROM ${MEMORY_INDEX_FTS_TABLE} LIMIT 1);
379+
`);
370380
ftsAvailable = true;
371381
} catch (err) {
372382
const message = formatErrorMessage(err);

0 commit comments

Comments
 (0)