Hybrid Search
contextd combines sqlite-vec KNN vector similarity with full-text keyword search (SQLite FTS5) across CLI, HTTP API, and MCP:
- Semantic (
sqlite-vec): Cosine similarity via local ONNX embeddings (WHERE embedding MATCH ?1 AND k = ?2), with progressivekexpansion when file, path, or time filters are active. - Keyword (
FTS5): Sanitized, tokenizedORqueries using the Porter stemming tokenizer (porter unicode61), with SQL filters applied beforeLIMIT. - Normalized Fusion: Reciprocal Rank Fusion (
k = 60) normalized to[0.0, 1.0]and blended with semantic cosine similarity.
Search Ranking Pipeline
- Vector KNN fetches top candidates (
clamp(limit * 5, 50, 200)) viasqlite-vecand applies recency decay (default weight0.1) and logarithmic frequency boost (default weight0.1). - FTS5 Keyword Search fetches top keyword matches with SQL filters applied prior to
LIMIT. - Normalized RRF combines both rank lists into
[0.0, 1.0]and blends rank consensus with vector similarity. - Filtering & Truncation applies
min_score, sorts deterministically (mappingNaNto0.0), truncates tolimit, and resolves optionalcontext_linesonly for the final results.