Hybrid Search

Hybrid search combines result sets from different retrieval signals, most commonly BM25 and dense retrieval. The point is not aesthetic balance: lexical methods catch exact names, IDs, and rare terms, while embeddings catch paraphrase. A good hybrid system keeps both failure modes visible in search evaluation.

Reciprocal rank fusion

One common rank-only fusion method is reciprocal rank fusion:

Here is the set of retrievers, and missing documents contribute nothing. Score-based fusion instead normalizes scores and computes a weighted sum, for example

Here is the fused score for document , and sets the lexical-versus-dense tradeoff. This formula is meaningful only when the component scores are normalized onto compatible scales.

RRF avoids score calibration; weighted sums give more control when a labelled development set is available.

flowchart TD
  Query[Query] --> BM25[BM25 lexical retriever]
  Query --> Dense[Dense embedding retriever]
  BM25 --> Fuse[Fusion: reciprocal rank or weighted score]
  Dense --> Fuse
  Fuse --> Merged[Merged candidate set]
  Merged --> Rerank[Reranking and filters]

Worked example

This snippet combines sparse and dense rankings with reciprocal-rank fusion and prints the fused document order.

from collections import defaultdict
 
bm25_rank = [1, 3, 2]
dense_rank = [2, 3, 1]
scores = defaultdict(float)
for ranklist in [bm25_rank, dense_rank]:
    for rank, doc_id in enumerate(ranklist, start=1):
        scores[doc_id] += 1 / (60 + rank)
print("rrf", [(d, round(s, 5)) for d, s in sorted(scores.items(), key=lambda x: x[1], reverse=True)])

Observed output:

rrf [(1, 0.03227), (2, 0.03227), (3, 0.03226)]

Documents 1 and 2 tie because each is first in one retriever and third in the other. Document 3 is consistently second, which is almost but not quite enough with this .

Where it fits

Hybrid retrieval is usually still a candidate-generation stage. The merged set can feed reranking, metadata filters, diversity rules, or source balancing. In RAG systems it sits near retrieval pipelines, where source coverage and citation quality matter as much as raw relevance.

Caveats

Fusion can hide regressions: a dense retriever may improve paraphrase queries while hurting exact-code queries, and the aggregate metric may barely move. RRF also has parameters, especially the rank constant and window size. Weighted fusion needs calibrated scores or labelled tuning data; otherwise one score scale can dominate the other.

References