diff --git a/src/retriever.ts b/src/retriever.ts index 769c248b..40652f68 100644 --- a/src/retriever.ts +++ b/src/retriever.ts @@ -561,6 +561,9 @@ export class MemoryRetriever { async retrieve(context: RetrievalContext): Promise { const { query, limit, scopeFilter, category, source } = context; const safeLimit = clampInt(limit, 1, 20); + // Ensure store is fully initialized before routing decision (hybrid vs vector-only). + // Without this, hasFtsSupport may be false on first call if FTS index creation is still in flight. + await this.store.ensureInitialized(); this.lastDiagnostics = null; const diagnostics: RetrievalDiagnostics = { source, diff --git a/src/store.ts b/src/store.ts index 6d14b28f..95e08d92 100644 --- a/src/store.ts +++ b/src/store.ts @@ -220,7 +220,8 @@ export class MemoryStore { return this.config.dbPath; } - private async ensureInitialized(): Promise { + /** Ensure the store is fully initialized (FTS index created, table opened, etc.). Safe to call multiple times. */ + public async ensureInitialized(): Promise { if (this.table) { return; }