Retrieval and RAG

Hybrid Search for RAG Agents: BM25, Vectors, and Fusion

Build hybrid search for RAG agents with lexical and vector retrieval, rank fusion, consistent access filters, evidence selection, and realistic evaluation.

· · 8 min read

Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.

Hybrid search for RAG combines lexical retrieval with semantic retrieval, then turns their candidate lists into one evidence set. The engineering challenge is preserving the strengths of both methods while enforcing access boundaries, avoiding duplicated evidence, and measuring whether the final answer actually improves.

This guide develops a hypothetical internal troubleshooting assistant. Its example rankings and calculations explain design choices; they are not results from a deployed search system.

Give each retrieval method a clear job

Suppose an engineer asks: “Why does the ZX-41 gateway disconnect after certificate rotation?” The identifier ZX-41 matters literally. “Disconnect” might appear in a useful incident report as “connection terminated,” so related meaning also matters. A lexical retriever and an embedding retriever can supply complementary candidates, provided the index represents those details accurately.

BM25 scores matching terms using corpus statistics and document-length normalization. Elasticsearch exposes parameters controlling term-frequency saturation and length normalization. Those scoring mechanics do not make every query an exact identifier lookup: tokenization and field mappings still determine what can match. Elasticsearch similarity settings.

For the proposed assistant, index product identifiers in an exact-match field and explanatory text in an analyzed text field. Preserve a canonical identifier separately from display text. If punctuation normalization changes ZX-41 into unrelated tokens, adjusting fusion weights will not repair the missing identifier signal.

The vector branch should search semantically useful passages using the embedding model and distance configuration selected for that index. Keep the embedding model version in metadata. Mixing vectors produced by incompatible models can invalidate the distance comparison even if the database accepts their dimensions.

Do not assume the two branches must contribute equally to every query. Some questions are identifier lookups; others describe a symptom without knowing its product terminology. First establish reliable individual branches, then determine whether combining them improves the relevant query families.

Fuse ranks without pretending scores share a scale

A lexical score and a vector similarity are different quantities. Adding them directly makes the effective weighting depend on their numerical ranges, which may change across queries and index configurations.

Reciprocal rank fusion, or RRF, combines positions rather than raw scores. For a document present in a ranked list, its contribution is 1 / (c + rank); contributions are summed across lists. Documents absent from a list contribute zero. The ranking constant c controls how strongly high positions dominate. Elasticsearch documents this formula and its separate candidate-window parameter. RRF reference.

The constant and the retrieval depth are different controls. Increasing the constant does not retrieve more documents. Increasing a branch’s candidate depth can admit evidence previously missing from the union, but adds retrieval and downstream processing cost.

RRF also discards score magnitude. A document barely ahead of its neighbor and one dramatically ahead both receive the same rank-based treatment. That can be acceptable when score calibration is unreliable, but it is a real information tradeoff.

Research by Bruch, Gai, and Ingber compares RRF with convex combinations of lexical and semantic scores. The authors report parameter sensitivity for RRF and favorable results for a tuned convex combination in their experiments. This is evidence to compare alternatives on a target workload, not proof that one fusion method always wins. An Analysis of Fusion Functions for Hybrid Retrieval.

Work through a hypothetical candidate set

Assume the assistant receives these illustrative rankings after applying the same access and product-scope constraints:

Passage Lexical rank Vector rank Evidence role
A 1 Absent Exact ZX-41 error-code entry
B 2 1 Certificate-rotation incident report
C Absent 2 General connection-renewal explanation
D 3 3 Older troubleshooting checklist

Choose c = 10 solely to make the arithmetic easy. Passage A scores 1/11, about 0.0909. B scores 1/12 + 1/11, about 0.1742. C scores 1/12, about 0.0833. D scores 1/13 + 1/13, about 0.1538. The fused order is B, D, A, C.

That order shows an important limitation: agreement between branches promotes D above A even though A contains a potentially decisive exact error code. RRF does not know which passage proves the diagnosis. It only combines rankings supplied by other components.

For this proposed assistant, retain evidence roles alongside fused scores. If an identifier-specific query has a verified exact match, preserve that candidate for subsequent relevance assessment rather than losing it to a tiny context cutoff. This is a design hypothesis to evaluate, not a universally safe override. A misleading exact match could otherwise crowd out better evidence.

The arithmetic also explains why duplicate handling matters. If B and another candidate are overlapping chunks from the same report, including both may consume the evidence budget without adding support. Deduplicate by stable passage identity before fusion, then consider document-level diversity during selection. Do not merge distinct passages merely because their text looks similar; revisions may differ in the fact that matters.

Apply authorization before evidence reaches the model

Both branches must operate under the authenticated caller’s permitted scope. A tenant filter applied only to the lexical query leaves the vector branch able to introduce another tenant’s content into the fused list. A later prompt instruction cannot repair that disclosure.

Filtering also changes retrieval behavior. Azure AI Search distinguishes filtering during vector traversal from filtering after candidate retrieval. Its documentation warns that postfiltering can miss eligible results when filters are selective or candidate counts are small. These are implementation-specific mechanics worth understanding before interpreting an empty result. Vector-query filtering.

In the illustrative design, construct one server-controlled authorization predicate and translate it into both query paths. Check the returned passage metadata again before constructing model context. That final check is defense in depth; it is not permission to retrieve unrestricted private content into application logs or shared caches.

Separate authorization predicates from optional relevance preferences. “May access this tenant” is mandatory. “Prefer documents updated this quarter” may be a ranking preference unless the question requires a current policy. The agent must not relax a security boundary when an initial search returns nothing.

Separate retrieval, reranking, and context assembly

Give each stage a distinct artifact. Retrieval produces branch-ranked candidates with source identity. Fusion produces a combined list with branch membership and component ranks. Reranking, if used, assesses candidate relevance against the question. Context assembly chooses passages that fit the model’s evidence budget while retaining citations and uncertainties.

Record the branch ranks even if only the fused order reaches the application. They reveal whether useful exact matches are being crowded out, whether the vector branch contributes anything, or whether a failure silently converted hybrid search into one-method search.

A reranker cannot recover a relevant passage absent from the candidate union. Before tuning its prompt or model, measure candidate recall. Conversely, increasing candidate recall indefinitely can worsen latency and create more distractors for later stages. See RAG reranking and context selection for the next-stage design.

Freshness belongs in this pipeline too. If the lexical index contains a new troubleshooting update but its embedding has not been generated, the branches represent different snapshots. Carry document versions into every candidate, define which revision is authoritative, and exclude superseded evidence according to application policy. RAG freshness and index consistency examines these update boundaries.

Evaluate the evidence path before the answer

Build a labeled query set with identifier-heavy lookups, symptom descriptions, ambiguous terminology, missing answers, access-restricted documents, and recently changed procedures. Label relevant passages at a fixed corpus snapshot. Keep tuning queries separate from final comparison queries.

Compare lexical-only, vector-only, RRF, and any calibrated score-fusion alternative under the same permissions, corpus, candidate budget, and answer-generation settings. Otherwise an apparent fusion improvement may simply reflect additional evidence access or a larger token budget.

Use several measurements together:

  • Candidate recall: whether relevant evidence enters the candidate union.
  • Ranking quality: how early useful passages appear, using a defined relevance scale.
  • Evidence coverage: whether selected context supports every required answer component.
  • Operational behavior: latency, branch timeouts, result counts, and processing cost.
  • Answer quality: correct grounded conclusions, unsupported claims, and appropriate abstention.

Inspect results by query family. An overall average can hide a regression on exact product identifiers. Review failures where one branch found relevant evidence but fusion or context truncation discarded it.

Inject branch failures deliberately. If vector search times out, the system may serve a lexical-only result under an explicit degraded-mode policy. Record that decision instead of presenting it as a successful hybrid run. If both branches return nothing, the answer should acknowledge missing evidence rather than invent a plausible troubleshooting instruction.

Frequently asked questions

No. It introduces another retrieval path, additional configuration, and fusion decisions. Use it when evaluation shows that lexical evidence contributes useful coverage or ranking quality at an acceptable operational cost.

Does RRF remove the need for tuning?

It avoids calibrating raw scores onto a shared scale, but candidate depth, ranking constants, field configuration, and context selection still affect results. Treat the whole retrieval configuration as an evaluated versioned system.

Should an agent rewrite every query?

Only when rewriting addresses an observed failure. Preserve exact identifiers, mandatory filters, and the original question. Compare rewritten and original retrieval paths so expanded wording does not silently remove the strongest evidence signal.

Source reference list

Hybrid Search
RAG
BM25
Vector Search
AI Agents