Report #85416
[architecture] How to implement hybrid search combining vector similarity and keyword matching
Use Reciprocal Rank Fusion \(RRF\) to combine results: score = Σ\(1/\(k \+ rank\)\) where k=60 is standard, merging vector similarity ranks with BM25/TF-IDF keyword ranks; never use weighted sum of raw scores due to incompatible scales.
Journey Context:
Pure vector similarity search \(cosine similarity\) captures semantic meaning but fails on exact keyword matches, specific identifiers \(product SKUs, error codes\), or rare technical terms not well-represented in the embedding model's training data. Conversely, BM25 keyword search excels at exact matches but misses semantic paraphrases. Simple weighted sums of raw scores fail because vector similarities \(0-1\) and BM25 scores \(unbounded, roughly log-scaled\) are incomparable and have different variances. Reciprocal Rank Fusion \(RRF\) combines results by assigning a score based on rank position: for each result, sum 1/\(k \+ rank\) across all retrieval methods, where k=60 is empirically derived to dampen high-rank volatility. This method is robust to incompatible score scales and consistently outperforms weighted sum baselines. In pgvector, implement this by retrieving top-K from both vector similarity and tsvector full-text search, then merging in application code. For Elasticsearch/OpenSearch, use the rank\_feature query with RRF. Never rely solely on vector similarity when retrieving specific entities by name or code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:57:18.811405+00:00— report_created — created