Skip to content

Hybrid search and reranking

Combine lexical and semantic retrieval, then use a reranker to improve precision before generation.

6 MIN READUPDATED 2026-11-18RAG & knowledge
ORIGINAL DIAGRAM · RETRIEVAL FLOWQUERYuser inputEMBEDvectorVECTOR STOREchunksRERANKtop-kLLMgroundedCITED ANSWERsource-linked

Original rag diagram — not a copied image

§ 01Key concepts
Lexical searchKeyword matching such as BM25; strong on exact terms and identifiers.
Dense retrievalVector similarity; strong on paraphrases and concepts.
RerankerA model that scores query-passage pairs for relevance after initial retrieval.
§ 02When to use
  • Queries mix product names with conceptual questions.
  • Vector search alone returns plausible but wrong passages.
  • You can afford a small extra latency step.
§ 03How it works
  1. 01Run keyword and vector search in parallel.
  2. 02Merge candidate lists with reciprocal rank fusion or weighted scores.
  3. 03Rerank the top candidates with a cross-encoder.
  4. 04Send only the highest-scoring passages to the model.
§ 04Use cases & scenarios

Searching by SKU and by intent

Context
Support staff search using both exact product codes and natural questions.
Problem
Vector-only retrieval misses exact codes; keyword-only retrieval misses paraphrases.
Approach
Run lexical and dense retrieval in parallel, fuse rankings and rerank the top candidates.
Outcome
Both kinds of query return the right passage in a compact final set.

Noisy top results in support search

Context
A support search returns twenty plausible passages.
Problem
The generator gets distracted by irrelevant context and answers poorly.
Approach
Rerank the candidates and pass only the four highest-scoring passages.
Outcome
Better answers with a smaller, cheaper prompt.
§ 05Examples

Fuse keyword and vector results

python
def rrf(bm25_ids, vector_ids, k=60):
    scores = {}
    for ranking in (bm25_ids, vector_ids):
        for rank, cid in enumerate(ranking, 1):
            scores[cid] = scores.get(cid, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)[:20]

Deduplicate by chunk ID before scoring. Reciprocal rank fusion merges rankings without calibrating raw scores.

Rerank config for a support search

yaml
keyword_weight: 0.4    # exact codes and product names
rerank_top_n: 30
final_passages: 4
log_retriever_source: true

Measure recall before adding the reranker, then tune final_passages so the prompt stays compact.

§ 06Trade-offs

Hybrid retrieval

Up: Best of lexical + semantic

Down: More moving parts

Reranking

Up: Large precision gain

Down: Extra latency and cost

Single retriever

Up: Simple and fast

Down: Lower recall on varied queries

§ 07Implementation checklist
  • Measure recall before adding a reranker.
  • Deduplicate candidates by chunk ID before scoring.
  • Tune the final passage count, not just top_k.
  • Log which retriever produced each winning passage.
§ 08Configuration reference
KeyTypical valueNote
keyword_weight0.3–0.5Tune on query mix.
rerank_top_n20–50Candidates sent to reranker.
final_passages3–6Keep context compact.
§ 09Troubleshooting
SymptomCauseFix
Exact names not foundVector-only retrievalAdd lexical search.
Reranker slows the APIToo many candidatesReduce rerank_top_n and cache common queries.
§ 10Frequently asked questions

Is hybrid search always better?

Usually for enterprise content with codes, names and jargon. Measure on your own queries.

Do I need a cross-encoder?

Not always; start with hybrid retrieval, then add reranking if precision is still low.

More in RAG & knowledge