Skip to main content

@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 (the SearchRanker port)
  • 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, rankWithFlexSearch in src/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 — the SearchRanker passed to createVault as deps.rank.

How to extend it​

  1. Change the SearchRanker port in vault-application first if the contract changes.
  2. Adjust the ranking in src/lib/flexsearch-ranker.ts.
  3. Cover the case in src/lib/flexsearch-ranker.spec.ts.
  4. Run npm exec nx test @ai-coach/vault-adapter-search and npm 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 SearchRanker port in its own adapter.
  • DEC-KI-0058 — the vault server offers full-text search over the user's vault.