Hybrid Search in Practice: Combining BM25 and Vector Search

Keyword search and vector search fail in opposite ways. BM25 finds exact terms but misses paraphrases: a query about “laptop battery life” will not match a document that says “notebook endurance”. Vector search understands meaning but fumbles exact identifiers like product codes, names, and error strings. Hybrid search runs both retrievers and merges their results, and in practice it beats either method alone on mixed workloads. That is the short version of hybrid search in practice combining BM25 and vector search. The rest of this guide covers the architecture, the two fusion methods worth using, the reranking stage most tutorials skip, and how to tune the combination on your own queries.

Why one method is not enough

BM25 is a ranking function from classic information retrieval. It scores documents by term frequency, adjusted for document length and for how rare each term is across the corpus. It is exact, fast, and transparent: you can always explain why a document ranked where it did.

Its blind spot is vocabulary mismatch. Users rarely phrase queries with the exact words in your documents. Synonyms, abbreviations, misspellings, and different phrasings all slip through, and no analyzer setting fully closes that gap.

Vector search fixes the paraphrase problem by embedding queries and documents into the same space and ranking by similarity. If the embedding side is new to you, our explainer on how vector embeddings work covers the mechanics with code. Vector search has its own blind spot, though: precision. It can return a semantically related document that never mentions the specific term the user asked about, and it has no built-in notion of rare-term importance.

Hybrid search exists because real query logs contain both kinds of queries, often from the same user in the same session.

How hybrid retrieval works

The architecture is straightforward:

  1. Run the query against a BM25 index and a vector index in parallel.
  2. Take the top k results from each. k should be larger than your final cutoff, for example 100 each for a final top 10.
  3. Combine the two ranked lists into one with a fusion method.
  4. Optionally rerank the fused candidates, then return the top n.

Both indexes must point at the same documents, chunked the same way, so decide your chunking strategy before either index is built. Each candidate then carries a BM25 score and a vector score, and the fusion step is where the real design decisions live.

Reciprocal rank fusion

Reciprocal rank fusion (RRF) ignores the raw scores and works only with ranks. For each document, sum 1 / (c + rank) across the result lists, where c is a constant (60 is the conventional default) that dampens the effect of very high ranks.

def reciprocal_rank_fusion(ranked_lists, c=60):
    scores = {}
    for results in ranked_lists:
        for rank, doc_id in enumerate(results, start=1):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (c + rank)
    return sorted(scores.items(), key=lambda x: x[1], reverse=True)

# ranked_lists = [bm25_doc_ids, vector_doc_ids]

RRF is popular because it needs no score normalization. BM25 scores and cosine similarities live on completely different scales, and RRF sidesteps that problem entirely. Documents that appear in both lists get a natural boost from being ranked twice, which is usually what you want.

Weighted score fusion

The alternative is to normalize both score distributions to the same range and take a weighted sum:

def weighted_fusion(bm25_scores, vector_scores, alpha=0.5):
    def normalize(scores):
        lo, hi = min(scores.values()), max(scores.values())
        if hi == lo:
            return {k: 1.0 for k in scores}
        return {k: (v - lo) / (hi - lo) for k, v in scores.items()}
    b, v = normalize(bm25_scores), normalize(vector_scores)
    fused = {doc: alpha * b.get(doc, 0) + (1 - alpha) * v.get(doc, 0)
             for doc in set(b) | set(v)}
    return sorted(fused.items(), key=lambda x: x[1], reverse=True)

The alpha parameter controls the balance: 1.0 is pure BM25, 0.0 is pure vector. This is a tuning knob that RRF does not give you. If your queries are heavy on product codes and exact names, push alpha up. If they are natural-language questions, push it down.

Add a reranking stage

Fusion gets the right documents into the candidate pool; it does not guarantee the best one lands on top. A cross-encoder reranker fixes that by reading the query and each candidate document together and scoring them as a pair, which is slower than either retriever but far more accurate about relevance. The standard pattern is to rerank only the fused top 30 to 50 and return the best 10, so the expensive model sees a small, already-promising set.

Reranking is worth its latency when results feed a person making a decision or an LLM writing an answer, because in both cases the top three results do most of the work. If your query log has a repetitive head, cache rerank scores for the most common queries; the candidates rarely change between calls. Skip it for autocomplete and other sub-second lookups, where the fused ranking is usually good enough and the budget is not there. Our guide to reranker models for search compares the main options if you are choosing one.

Hybrid Search Practice Combining BM25 Vector Search with a Real Stack

Most production hybrid search runs on Elasticsearch or OpenSearch, both of which support hybrid queries natively. The pattern in Elasticsearch looks like this:

GET /docs/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "content": "refund policy" } },
        { "knn": {
            "field": "content_vector",
            "query_vector": [0.12, -0.44, ...],
            "k": 50, "num_candidates": 200
        }}
      ]
    }
  },
  "rank": { "rrf": { "rank_window_size": 100, "rank_constant": 60 } }
}

The rank.rrf clause tells Elasticsearch to fuse the BM25 clause and the kNN clause with reciprocal rank fusion, and OpenSearch offers an equivalent hybrid query with a normalization processor. Either way you get one query and one fused ranking, with no application-side merging code to maintain. If your vectors live in a dedicated store instead, the application-side functions above do the same job; our vector database comparison covers the main candidates and when a dedicated store beats a search engine plugin.

Tuning Hybrid Search in Practice Combining BM25 and Vector Search

  • Retrieve more than you return. Pull 50 to 100 candidates per method and fuse down to your final top 10. Fusion needs a pool big enough to contain the documents that only one method surfaced.
  • Tune alpha on your own queries. Sample 30 to 50 real queries, label the results you would want, and grid-search the weight against that set. There is no universal best value, and copying someone else’s alpha copies their query mix, not yours.
  • Boost fields deliberately. A match in a title or heading usually means more than a match buried in body text. Apply field boosts on the BM25 side before fusion, not as an afterthought.
  • Watch indexing cost. Adding a vector index roughly doubles indexing work versus BM25 alone. For a mostly static corpus that is a one-time cost; for rapidly changing data, plan the re-embedding pipeline as carefully as the query path.
  • Filter before you fuse. Metadata filters such as tenant, language, or date belong inside each retriever, not after fusion. Filter late and the fused list fills with documents you were always going to throw away.
  • Keep BM25 as the safety net. When the embedding model meets out-of-vocabulary jargon or a term coined last week, BM25 is what keeps those queries working.

Measure before and after you change anything. Build a small evaluation set from real queries with judged results, then compare the fused ranking against each method alone on the same set. The metrics side of this is covered in our guide to evaluating RAG systems, and the same labeled set doubles as your regression test whenever you swap an embedding model.

Failure modes worth knowing

Query pattern What goes wrong Fix
Product codes and error strings Vector results drift toward near-matches that share no exact term Raise alpha, or gate exact-looking queries to BM25 first
Paraphrase-heavy questions BM25 returns little or nothing Lower alpha and expand synonyms at index time
Brand-new terminology Embeddings treat the new term as noise Let BM25 carry the query until the index and model catch up
Tiny corpus, a few hundred documents Hybrid machinery adds cost without improving results Plain BM25 or plain vector search is fine at this size

Start with RRF: it has almost no parameters to tune, and for most mixed workloads it is a clear improvement over either method alone. Move to weighted fusion when you have labeled queries and want the last increment of quality. More tech tutorials on the retrieval side of the stack, from chunking to evaluation, are linked throughout this guide.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.