@ai-coach/vault-adapter-search
Ranks full-text search hits. rankWithFlexSearch is the SearchRanker behind the search and find_passages tools, built on FlexSearch. You change this package when search results should be ranked differently.
What it does not do
- No choosing what to search. Which notes and passages are searched, and with which summaries stripped, is decided in
vault-application(searchNotes,searchPassages). - No index on disk. It ranks the units it is given, in memory, for each call.
- Only
flexsearch. Nx boundaries (adapter:vault-search) forbid any other external import.
Architecture fit
- Scope:
scope:vault - Style:
architecture:hexagonal(type:adapter,adapter:vault-search) - Depends on:
@ai-coach/vault-application(theSearchRankerport) - Used by:
@ai-coach/vault-mcp-server,@ai-coach/vault-view-server(their composition roots)
[search / find_passages] ──▶ searchNotes, searchPassages ──▶ SearchRanker ◀──implements── rankWithFlexSearch
Internal architecture & rules
- One function,
rankWithFlexSearchinsrc/lib/flexsearch-ranker.ts. - Titles count more than bodies, and diacritics are folded, so Polish and English match alike.
- Known gap: it folds
ż,ó,ęandś, but notł. - No comments in source code (DEC-AIC-0011).
Public surface
rankWithFlexSearch— theSearchRankerpassed tocreateVaultasdeps.rank.
How to extend it
- Change the
SearchRankerport invault-applicationfirst if the contract changes. - Adjust the ranking in
src/lib/flexsearch-ranker.ts. - Cover the case in
src/lib/flexsearch-ranker.spec.ts. - Run
npm exec nx test @ai-coach/vault-adapter-searchandnpm exec nx lint @ai-coach/vault-adapter-search.
Running & testing
npm exec nx test @ai-coach/vault-adapter-search
npm exec nx lint @ai-coach/vault-adapter-search
npm exec nx typecheck @ai-coach/vault-adapter-search
npm exec nx build @ai-coach/vault-adapter-search
The specs rank small in-memory units with Vitest.
Key ADRs
- DEC-AIC-0052 — puts ranking behind the
SearchRankerport in its own adapter. - DEC-KI-0058 — the vault server offers full-text search over the user's vault.