Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions extensions/memory-core/src/memory/manager-sync-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export abstract class MemoryManagerSyncOps {
return openMemoryDatabaseAtPath(dbPath, this.settings.store.vector.enabled);
}

private seedEmbeddingCache(sourceDb: DatabaseSync): void {
private async seedEmbeddingCache(sourceDb: DatabaseSync): Promise<void> {
if (!this.cache.enabled) {
return;
}
Expand Down Expand Up @@ -323,6 +323,9 @@ export abstract class MemoryManagerSyncOps {
updated_at=excluded.updated_at`,
);
this.db.exec("BEGIN");
// Yield to event loop every N rows so HTTP /health probes stay responsive.
const SEED_EMBEDDING_YIELD_EVERY = 1000;
let rowCount = 0;
for (const row of rows) {
insert.run(
row.provider,
Expand All @@ -333,6 +336,12 @@ export abstract class MemoryManagerSyncOps {
row.dims,
row.updated_at,
);
rowCount += 1;
if (rowCount % SEED_EMBEDDING_YIELD_EVERY === 0) {
await new Promise<void>((resolve) => {
setImmediate(resolve);
});
}
}
this.db.exec("COMMIT");
} catch (err) {
Expand Down Expand Up @@ -1160,7 +1169,7 @@ export abstract class MemoryManagerSyncOps {
targetPath: dbPath,
tempPath: tempDbPath,
build: async () => {
this.seedEmbeddingCache(originalDb);
await this.seedEmbeddingCache(originalDb);
const shouldSyncMemory = this.sources.has("memory");
const shouldSyncSessions = this.shouldSyncSessions(
{ reason: params.reason, force: params.force },
Expand Down
Loading