Hybrid Search

The Best of Both Worlds

Hybrid search combines BM25 keyword search and vector similarity search into a single system. It is the recommended approach for production because it reliably outperforms either method alone — their failure modes are complementary, so combining them covers both gaps.

Why combine them?

Keyword search fails at synonyms and paraphrasing. Vector search fails at exact identifier lookup. Hybrid search fails at neither. A query for "car crash prevention" finds documents using that exact phrase (keyword) and documents about "automobile safety" (vector).

How It Works

1

Parallel query — The query runs simultaneously against a BM25 inverted index and a vector ANN index. Each returns a ranked list of results.

2

Rank fusion — The two ranked lists are merged. The most common algorithm is Reciprocal Rank Fusion (RRF): each document scores based on its rank in each list. Documents near the top of both lists score highest.

3

Optional re-ranking — A cross-encoder re-ranker scores the top-k candidates more precisely by considering the query and each candidate together. Slow but accurate — run only over a small candidate set (50-100 results).

Reciprocal Rank Fusion (RRF)

Why RRF works

RRF only uses rank positions, not raw scores. This means you don't need to normalize BM25 scores and cosine similarity scores onto the same scale — they're on completely different scales, and any normalization introduces bias. RRF sidesteps this problem entirely.

A document that appears near the top of both ranked lists gets the highest combined score. A document that appears in only one list still contributes. This makes hybrid search robust to any individual system's failures.

Tuning Alpha

Alpha closer to 0

More weight on keyword search. Better when users search by exact names, codes, identifiers, or precise phrases.

Alpha closer to 1

More weight on vector search. Better when users ask natural language questions or describe what they want without knowing exact terminology.

Always tune alpha empirically on real queries with human-judged relevance. Do not guess.

Need Help?

Ask the AI assistant about hybrid search, Reciprocal Rank Fusion, re-ranking, or how to tune search systems.