Skip to content

Hybrid search and reranking

Running a keyword search and a vector search for one question, merging the two ranked lists by position, and letting a slower, more accurate model reorder the short list. In a RAG design it decides which passages reach the prompt.

On this page

What it is

Hybrid search runs two different retrievers over the same corpus for one question and merges what they return. A lexical retriever, BM25 over an inverted index, scores a passage by the literal words it shares with the query. It does not recognize a synonym, an acronym spelled out differently, or a misspelling, and its strength is the exact token: a policy number or a product code written the same way in the query and the document. A dense retriever encodes the query into a vector with an embedding model and returns the passages whose stored embeddings lie nearest to it, usually through an approximate nearest-neighbor index such as HNSW. It matches meaning across wording and, with a multilingual embedding model, across languages with no per-language analyzer. Each catches what the other drops, which is the reason to run both.

Adding the raw scores is a poor way to merge the two lists. A BM25 score starts at 0 with no upper bound, while a vector similarity in Azure AI Search lands between 0.333 and 1.0, so a sum of the two needs weights or calibration and shifts from query to query. Reciprocal rank fusion (RRF) ignores the scores and uses positions: a document receives 1 / (k + rank) from each list it appears in, and those contributions are summed. k is a constant; the RRF retriever in Elasticsearch 8.19 defaults it to 60, and a larger k lets documents low in a list keep more weight. Each retriever contributes its top rank_window_size results, and the merged list is cut to the requested size. The method needs no tuning and the lists don't have to score on related scales. With k = 60, a passage ranked second in both lists (1/62 + 1/62) finishes ahead of one ranked first in one list and missing from the other (1/61).

pseudo
score(d) = sum over lists L containing d of  1 / (k + rank_L(d))
# rank starts at 1; k = 60 in this example

list A (BM25):   [p7, p2, p9]
list B (vector): [p2, p4, p7]

p2: 1/62 + 1/61 = 0.0325   # second in A, first in B
p7: 1/61 + 1/63 = 0.0323   # first in A, third in B
p4: 1/62        = 0.0161   # in B, absent from A
p9: 1/63        = 0.0159   # in A, absent from B

merged: p2, p7, p4, p9

The first stage has to be cheap enough to scan millions of passages, which is why it works from an embedding per passage computed ahead of time: a bi-encoder encodes the query and each passage separately, so the passage side is done at indexing time and the query side is one encoding per request. A cross-encoder instead feeds the query and one candidate passage through the transformer together, with attention running across both texts, and outputs a single relevance score, between 0 and 1 in the Sentence Transformers models. That joint reading is more accurate, but it costs a forward pass per (query, passage) pair, so scoring thousands or millions of pairs for each query would be far too slow. The usual pipeline therefore retrieves around 100 candidates and lets the cross-encoder reorder them. Hosted search services expose the same split as ranking levels: a first-level (L1) score from retrieval, then a second-level (L2) semantic reranker that rescores the L1 results, because running it as the first stage would be prohibitively expensive. Hosted rerankers such as Cohere's Rerank v2 endpoint take a query and a list of documents and return them ordered by a relevance score, with a top_n parameter limiting how many come back.

Permissions belong in the retrieval query, not after it. The pattern: each indexed chunk carries a filterable field listing the groups or users allowed to read it, marked so the field is not returned in results, and the application adds to each query a filter that keeps chunks whose list contains one of the caller's group identifiers. Azure AI Search documents this as a security filter over a group_ids collection, with the caller's groups passed into a search.in() filter. Where the filter runs matters for vector search. In Elasticsearch 8.19, the filter on a kNN search is applied during the approximate search so that k matching documents come back; the alternative, post-filtering, applies the filter after the approximate search has finished, and since the neighbors were picked without it, the survivors can number fewer than k, or none, even when permitted passages on the topic exist. Pre-filtering has a price: unlike a conventional query, where a stricter filter usually makes the query faster, a filter inside an approximate kNN search over an HNSW index can slow it down.

When to use it

Reach for hybrid retrieval when the questions mix styles: some paraphrase a document's content ("how many days off do new parents get"), others carry an exact token ("policy HR-114", a person's name, an error code). A single retriever handles one style well and misses the other; running both and fusing by rank covers both without weights to tune. It also helps when the corpus spans languages, since a vector query can match multilingual content without a language analyzer or a translation step.

Add a reranker when the top of the list matters more than the tail. In retrieval-augmented generation a handful of passages fit in the prompt, so the question is not whether the right passage is somewhere in the top 100 but whether it is in the top 5; a cross-encoder reorders the top 100 so the prompt receives the passages that answer the question. The cost is one model call over the 50 to 100 candidates per query.

Filter at retrieval when readers hold different rights over one corpus, as happens when HR files, legal drafts and a public handbook share a single index. Pre-filter with the caller's group identifiers so the k results are drawn from what that person may read; everything downstream, the reranker and the prompt, then works on permitted text. Our advice: resolve the caller's groups from the identity provider at request time rather than copying them into the index per user, so a membership change shows up on the next query.

When not to

Skip the first stage when the collection is small. If a user is searching inside one document or a small set of paragraphs, the cross-encoder can score all of them directly, as the Sentence Transformers in-document example does; retrieval exists to cut a large collection down to around 100 candidates, and the smaller the set, the less it buys. Skip the reranker when the latency or cost budget rules it out: an interface that re-queries on each keystroke may not have room for a model call per request, and a hosted semantic reranker can be a metered, premium feature (Azure's is). Skip the vector side when queries are exact identifiers and nothing else, such as a ticket ID lookup; BM25 answers those, and an embedding pipeline adds operational weight for no gain.

Post-filtering is sometimes the right call. When the filter removes little (say, it excludes a small archived set), most nearest neighbors pass it anyway, so applying it after the vector search skips the slowdown a filtered HNSW traversal can bring and still returns close to k results. Pre-filter when the filter is selective; a permission filter that leaves a reader a small share of the corpus is the clear case. And don't hand the reranker or the language model the job of removing forbidden passages: a reranker reorders what it is given, and a passage that reaches the prompt has already been shown to the model.

Compared

ApproachWhat it findsWhat it costs or missesWhen it is the right choice

Lexical search (BM25)

Exact words: codes, names, acronyms

Misses synonyms, acronyms spelled differently, misspellings

Queries are identifiers or exact phrases; no embedding pipeline wanted

Vector search

Meaning across wording; across languages too when the embedding model is multilingual

Scores on a scale unrelated to BM25's (bounded in some services); an embedding per chunk and a vector index, approximate or exact

Natural-language questions over prose; multilingual corpora

Hybrid with RRF

Both lists, ordered by where each passage ranks in each

Two searches per request; k and the window size to pick, though the defaults need no tuning

Mixed query styles; no labeled data to tune score weights

Hybrid plus cross-encoder

The best few among the top 50 to 100, judged by reading question and passage together

Model work per (question, passage) pair, so added latency; a hosted reranker is billed for usage

A handful of results must be right: RAG prompts, top-3 answers

Permission pre-filter

Up to k results, all of them readable by the caller

Slower HNSW traversal when the filter is selective

Per-reader permissions and other selective filters

Permission post-filter

Nearest neighbors first, forbidden ones dropped after

Can return fewer than k, or none

The filter matches most documents and filtered traversal isn't worth paying for

In a picture

Question + groupsFiltered BM25Filtered kNN

Step 1 of 3

Two retrievers, both filtered

The question and the caller's group IDs go to a BM25 search and a vector search. Each applies the permission filter inside the search, so the up to k passages each returns are ones the caller may read.

How to say it in an interview

The common mistake

Quiz

Why does reciprocal rank fusion use each passage's position in a list rather than the retriever's score?
You run a vector search for k = 5 and then drop the passages an intern may not read. The intern asks about parental leave, and the five nearest passages are all HR-restricted. What comes back?
Why does the cross-encoder run on roughly 100 candidates instead of the whole index?
A user searches for the error code "E-4471". Which component is most likely to surface the passage that contains it?

Questions that use this

Hear it in

Related

Sources

  1. Elasticsearch 8.19 reference: Reciprocal rank fusion
  2. Elasticsearch 8.19 reference: k-nearest neighbor (kNN) search
  3. Sentence Transformers documentation: Retrieve & Re-Rank
  4. Cohere documentation: An overview of Cohere's Rerank model
  5. Azure AI Search: Security filters for trimming results
  6. Azure AI Search: Hybrid search overview
  7. Azure AI Search: Relevance and ranking overview
Sign in to report a mistake