Shaf Lab

Hybrid search

Running keyword search and vector search together and merging their results into one ranking.

Hybrid search runs a keyword search and a vector search over the same corpus and merges the two result lists into one ranking. Each method covers the other's blind spot. Keyword search finds exact strings such as error codes, product numbers, function names, and rare proper nouns, which embeddings tend to blur. Vector search finds passages that mean the same thing as the query even when they share no words with it.

The hard part is merging. Keyword scores and vector similarities live on different scales and distributions, so adding them directly lets one method dominate for reasons that have nothing to do with relevance. Rank-based fusion avoids the problem by looking only at positions in each list. Weighted score blending can also work, but only after normalizing scores and tuning weights on real queries.

In a retrieval pipeline, hybrid search usually sits in the middle of a funnel. Each method retrieves a few dozen candidates, fusion merges them into one list, and a reranker reorders the top of that list before it goes to the model. Filters for permissions, language, or date should apply inside both searches, not afterward, so neither side returns documents the user should not see.

Hybrid search is the safe default for most retrieval over real documents, because real queries mix exact identifiers with loose natural language. Measure it the same way as any retrieval: a fixed set of real questions and a check on whether the right passage appears in the top few results.

Reciprocal rank fusion

Merging ranked lists by summing 1 / (k + rank) for each item, ignoring the original scores.

Reciprocal rank fusion, or RRF, merges several ranked lists into one using only positions, not scores. Each item earns 1 / (k + rank) from every list it appears in, and the amounts are added. The constant k, commonly 60, softens the advantage of the very top positions. Items that rank well in several lists rise to the top of the merged list.

Because it ignores raw scores, RRF sidesteps the problem that keyword scores and vector similarities are on incomparable scales. It needs no training and almost no tuning, and it is surprisingly hard to beat, which makes it the standard first choice for hybrid search. If one retriever is consistently more trustworthy, a weighted version can multiply its contribution.