Creates a new HybridSearcher.
Dense vector store for semantic search.
Manager for generating query embeddings.
BM25 sparse keyword index.
Optional config: HybridSearcherConfigOptional configuration overrides.
const searcher = new HybridSearcher(store, embeddings, bm25, {
denseWeight: 0.7,
sparseWeight: 0.3,
});
Searches both dense and sparse indexes, then fuses results.
Pipeline:
The search query text.
Vector store collection to search.
Optional topK: number = 10Maximum number of results to return.
Optional queryOptions: Partial<QueryOptions>Additional options for the vector store query.
Fused results sorted by relevance.
If embedding generation fails.
const results = await hybrid.search('error TS2304', 'knowledge-base', 5);
for (const r of results) {
console.log(`${r.id}: fused=${r.score.toFixed(4)} dense=${r.denseRank} sparse=${r.sparseRank}`);
}
Hybrid dense+sparse searcher combining vector embeddings with BM25.
Uses Reciprocal Rank Fusion (RRF) to merge results from both retrieval systems, capturing both semantic similarity and exact keyword matches.
Example: Basic usage
Example: Weighted sum fusion (when you have calibrated scores)