| Lexical search | Keyword matching such as BM25; strong on exact terms and identifiers. |
| Dense retrieval | Vector similarity; strong on paraphrases and concepts. |
| Reranker | A model that scores query-passage pairs for relevance after initial retrieval. |
- Queries mix product names with conceptual questions.
- Vector search alone returns plausible but wrong passages.
- You can afford a small extra latency step.
- 01Run keyword and vector search in parallel.
- 02Merge candidate lists with reciprocal rank fusion or weighted scores.
- 03Rerank the top candidates with a cross-encoder.
- 04Send only the highest-scoring passages to the model.
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.
Fuse keyword and vector results
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
keyword_weight: 0.4 # exact codes and product names
rerank_top_n: 30
final_passages: 4
log_retriever_source: trueMeasure recall before adding the reranker, then tune final_passages so the prompt stays compact.
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
| Option | Upside | Cost |
|---|---|---|
| Hybrid retrieval | Best of lexical + semantic | More moving parts |
| Reranking | Large precision gain | Extra latency and cost |
| Single retriever | Simple and fast | Lower recall on varied queries |
- 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.
| Key | Typical value | Note |
|---|---|---|
| keyword_weight | 0.3–0.5 | Tune on query mix. |
| rerank_top_n | 20–50 | Candidates sent to reranker. |
| final_passages | 3–6 | Keep context compact. |
| Symptom | Cause | Fix |
|---|---|---|
| Exact names not found | Vector-only retrieval | Add lexical search. |
| Reranker slows the API | Too many candidates | Reduce rerank_top_n and cache common queries. |
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
RAG pipeline end to end
The six stages of retrieval-augmented generation and where each one most often fails.
Chunking and metadata design
How to split documents so retrieved passages remain useful, and which metadata to keep.
RAG evaluation: retrieval and answer quality
Separate the two halves of RAG quality so you know whether to fix retrieval or generation.