mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Closes the last gap from ADR-125's hardening pass: when the embedder is
unavailable the memory subsystem returns FTS-ranked keyword results
instead of throwing, and the previously-stubbed `hybridSearch` controller
finally returns real fused results.
- `AgentDBAdapter.semanticSearch` — wraps the embedder call in try/catch.
On no-generator OR generator-throws: emits
`health:embedder { status: 'degraded' }` then delegates to
`searchKeyword(query, opts)` (Acceptance Criterion #5).
- `AgentDBAdapter.searchKeyword` — new in-memory token-overlap ranking
with a dependency-free `tokenize` helper. Used both as the embedder
fallback and as the sparse arm of `hybridSearch`.
- `SQLiteBackend` + `SqlJsBackend` — both gain a FTS5 virtual table
(`memory_fts USING fts5(id UNINDEXED, content, tokenize='porter
unicode61')`), mirror writes on `store()`, prune on `delete()`, and a
`searchKeyword(query, limit)` method that queries `memory_fts MATCH`
ranked by FTS5's BM25 and joins back to `memory_entries`. Both fall
back to `LIKE` when FTS5 isn't available on the build.
- `controller-registry.ts` `hybridSearch` controller — replaces the
`return null` placeholder with a real RRF + MMR pipeline:
1. Run `semanticSearch` (which itself degrades) AND `searchKeyword`
independently with fanOutK = limit * 3.
2. Fuse via Reciprocal Rank Fusion (k=60) using the new public
`applyRRF` helper exported from `smart-retrieval.ts`.
3. Diversify via MMR (lambda=0.7) using the new public `applyMMR`
helper (re-export of the existing `mmrRerank`).
Auto-enables when a `MemoryService` is registered.
Tests:
- `src/graceful-retrieval.test.ts` — 3 cases covering Acceptance
Criterion #5 (no embedder → keyword + degraded event), embedder-throws
fallback, and the `hybridSearch` controller's fused output shape.
- `src/fts5.test.ts` — 6 cases covering sqljs FTS5 insert/match/delete/
update and gated sqlite FTS5 tests (skip when `better-sqlite3` isn't
installable in the env).
403/15 tests pass (was 394/13).
Refs: #2061, ADR-125 §Phase 5, Acceptance Criterion #5.
Co-Authored-By: RuFlo <ruv@ruv.net>