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
28 changes: 18 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,24 @@ async function main() {
const needsRebuild = bm25Index.size === 0;

if (needsRebuild) {
const indexCount = await rebuildIndex(kv).catch((err) => {
console.warn(`[agentmemory] Failed to rebuild search index:`, err);
return 0;
});
if (indexCount > 0) {
bootLog(
`Search index rebuilt: ${indexCount} entries`,
);
indexPersistence.scheduleSave();
}
// Fire-and-forget. rebuildIndex iterates every observation across
// every session and AWAITS an embedding-provider call per record.
// On a large corpus + rate-limited embedding endpoint that can
// take HOURS; awaiting it here blocks every subsequent boot step
// (including startViewerServer below, leaving the viewer port
// unbound for the duration). The index lazily fills in over time
// and search degrades gracefully — partial coverage > no viewer
// for hours. Errors still surface via the inner .catch.
void rebuildIndex(kv)
.then((indexCount) => {
if (indexCount > 0) {
bootLog(`Search index rebuilt: ${indexCount} entries`);
indexPersistence.scheduleSave();
}
})
.catch((err) => {
console.warn(`[agentmemory] Failed to rebuild search index:`, err);
});
} else {
// Backfill memories into BM25 for users upgrading from <0.9.5: prior
// versions of mem::remember never indexed memories, so the persisted
Expand Down