Combining lexical (keyword) and semantic (vector) retrieval to find the most robust set of relevant documents.
Hybrid Search with Reciprocal Rank Fusion (RRF) is the gold standard for production-grade retrieval. Keyword search (BM25) is excellent for finding specific proper nouns and identifiers (e.g., "Error Code 404"), while vector search is excellent for finding conceptual similarities (e.g., "How to fix node issues"). RRF allows us to merge these two distinct rankings into a single, unified list without requiring manual weight tuning.
Engineering Trade-offs
Feature
Technical Impact
Pros
Maximizes recall across name-heavy and concept-heavy queries; provides a unified score for disparate systems.
Cons
Requires maintaining two indices (BM25 + Vector); increases the total search execution time.
Architecture Overview
The Hybrid RRF data flow unifies disparate search systems:
We apply the RRF formula: Score = Σ (1 / (rank + k)). This rewards documents that appear high in multiple rankings.
/** * RRF Score Function * k=60 is the standard constant for stable merging. */function calculateRRF(rank) { return 1 / (60 + rank);}const doc1Score = calculateRRF(0) + calculateRRF(1); // doc1 was Rank 1 in set A and Rank 2 in set B.console.log(`[RRF] Doc1 Unified Score: ${doc1Score.toFixed(4)}`);
Complete Production Script
This script implements a baseline RRF algorithm to merge two distinct document queues.