Hybrid Search

TLDR: Hybrid search runs keyword matching and vector similarity against the same query and merges the two result sets, because each method fails on queries the other handles well.

Hybrid search is a response to a practical finding: neither retrieval method is reliably better. Keyword search is exact and literal. Vector search is approximate and semantic. Their failure modes are close to opposite, which is precisely what makes combining them effective.

Where Each Method Fails:

Query Keyword search Vector search
Product code XR-4417B Exact match May return similar looking codes
How do I stop it overheating Misses differently worded docs Finds thermal management content
Rare technical term Matches reliably Weak if term was rare in training
Conceptual question Poor without shared vocabulary Strong
Quoted exact phrase Honors it precisely Treats it loosely
Misspelled input Often returns nothing Frequently still matches

The pattern is consistent. Identifiers, rare terms, and exact phrases favor keyword search. Natural language, paraphrase, and conceptual questions favor vector search. Real query logs contain both kinds in quantity.

Merging Two Result Sets:

The technical difficulty is that the two methods produce incomparable scores. A BM25 score of 14.2 and a cosine similarity of 0.83 cannot be added together meaningfully, and normalizing them is unstable because their distributions differ by query.

Reciprocal Rank Fusion avoids the problem by discarding scores entirely and using only rank position. Each document receives a contribution of 1 divided by a constant plus its rank in each result list, and the contributions are summed.

Because only ordering matters, no normalization is required, and the method is robust across very different scoring scales. It is widely used for exactly this reason.

Implementation:

def reciprocal_rank_fusion(result_lists, k=60):
    scores = {}

    for results in result_lists:
        for rank, doc_id in enumerate(results, start=1):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)

    return sorted(scores, key=scores.get, reverse=True)

def hybrid_search(query, keyword_index, vector_index, limit=10):
    keyword_hits = keyword_index.search(query, limit=50)
    vector_hits = vector_index.search(embed(query), limit=50)

    merged = reciprocal_rank_fusion([keyword_hits, vector_hits])
    return merged[:limit]

The constant k dampens the advantage of top ranks. A value around 60 is the conventional default from the original research. Lower values weight first place results more heavily, higher values flatten the contribution curve.

Note that both searches retrieve more candidates than the final result count. Fusion needs depth in each list to find documents that one method ranked modestly and the other ranked well.

Weighted Alternatives:

Rank fusion treats both methods equally. Some systems weight them instead, either with a fixed ratio or by query type.

Fixed weighting is simple but blunt, since the correct balance differs between a product code lookup and a conceptual question. Query dependent weighting performs better: queries containing quoted phrases, identifiers, or numeric patterns lean keyword, while longer natural language queries lean semantic.

The routing logic itself becomes a maintenance burden, which is why many systems stay with equal weight fusion and accept slightly worse performance on edge cases in exchange for predictability.

Operational Cost:

Hybrid search requires maintaining two indexes over the same content. Both must be populated, both must be updated when documents change, and both must be queried on every search.

This roughly doubles indexing work and storage, and adds latency unless the two searches run in parallel. It also doubles the surface area for inconsistency, since a document present in one index and missing from the other produces results that are difficult to diagnose.

The cost is usually accepted because the retrieval improvement is substantial on mixed query workloads, but it is a real operational commitment rather than a configuration flag.

Hybrid Search in Retrieval Pipelines:

In systems that ground model output in retrieved documents, retrieval quality sets the ceiling on answer quality. A document that is never returned cannot inform an answer, regardless of how well the prompt is constructed.

Hybrid retrieval raises that ceiling by reducing the number of queries where relevant material is missed entirely. It pairs naturally with query expansion on the keyword side and with well bounded document chunks on the vector side, since both methods degrade when chunks are too large to represent a single idea.

Where the corpus is built from web content, Bright Data’s Crawl API supplies clean Markdown suitable for indexing in both systems, and Datasets provide pre collected structured records where live crawling is unnecessary.

Ready to get started?