Conversation
- Create src/search.ts with centralized ftsQuery/ftsQueryOr functions - Add stopword filtering (conservative list, preserves domain terms) - Drop single-char tokens (contraction artifacts) but keep 2-char+ terms - Implement AND-then-OR fallback: AND first for precision, OR when AND returns nothing - Fix knowledge search to use BM25 rank instead of updated_at DESC - Uses bm25() with column weights: title=6.0, content=2.0, category=3.0 - JOIN pattern instead of subquery for proper rank access - Add distillation_fts table (schema migration v7) - FTS5 on observations column with porter unicode61 tokenizer - Backfill existing data, sync triggers for INSERT/UPDATE/DELETE - Replace LIKE-based distillation search with FTS5 ranked search - Add 'too vague' handling in recall tool for all-stopword queries - Remove ftsQuery from temporal.ts (now in search.ts, no re-export)
BYK
added a commit
that referenced
this pull request
Mar 22, 2026
## Phase 2 of search improvements (depends on #46) Adds cross-source score fusion using Reciprocal Rank Fusion and rewrites the recall tool to produce a single ranked result list. ### Changes **New in `src/search.ts`** - `reciprocalRankFusion<T>()` — merges multiple ranked lists using RRF (k=60, Cormack et al. 2009). Rank-based, not score-based, so magnitude differences across FTS tables don't matter. - `normalizeRank()` — min-max normalization of FTS5 BM25 ranks to 0–1 (for display only) **New scored search variants** - `ltm.searchScored()` — returns `KnowledgeEntry & { rank }` with BM25 scores via `bm25(knowledge_fts, 6, 2, 3)` - `temporal.searchScored()` — returns `TemporalMessage & { rank }` - `searchDistillationsScored()` — returns `Distillation & { rank }` All scored variants include AND→OR fallback (same as Phase 1 search functions). **Rewritten recall tool** - Runs all 3 scored searches, tags results with source type - Fuses via RRF into a single ranked list - Output format: source-annotated list (`[knowledge/category]`, `[distilled]`, `[temporal/role]`) - Most relevant results appear first regardless of which source they came from ### Test coverage - 11 new tests for `normalizeRank()` and `reciprocalRankFusion()` - Tests cover: multi-list merge, dedup, empty lists, single list, custom k, score correctness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of search improvements
Fixes the FTS5 search foundations as the first step toward a comprehensive search overhaul.
Changes
New:
src/search.ts— centralized search moduleftsQuery()— AND-based FTS5 query builder with stopword + single-char filteringftsQueryOr()— OR-based variant for fallback when AND returns nothingSTOPWORDS— conservative set (only genuinely content-free words, preserves domain terms likehandle,state,type)EMPTY_QUERYsentinel for all-stopword queriesFixed: Knowledge search ranking
ORDER BY updated_at DESC(most recently edited wins regardless of relevance)ORDER BY bm25(knowledge_fts, 6.0, 2.0, 3.0)(title matches weighted 6x, category 3x)New:
distillation_ftstable (schema migration v7)observationscolumn with porter unicode61 tokenizerImproved: AND→OR fallback pattern
New: "Too vague" handling
Test coverage
test/search.test.ts(query building, stopwords, edge cases)test/ltm.test.tstest/db.test.ts