Skip to content
StackSignal
RAG and search • 9 min read

Hybrid Search Architecture: Combining BM25, Dense Embeddings, and Cross-Encoder Rerankers

Build production enterprise retrieval systems combining lexical BM25, dense vector embeddings, reciprocal rank fusion (RRF), and cross-encoder rerankers.

By the StackSignal Editorial Team

Early Retrieval-Augmented Generation (RAG) tutorials advocated a simplistic architecture: convert documents into dense vector embeddings, store them in a vector database (Pinecone, Qdrant, Chroma), query with cosine similarity, and dump the top-k chunks into an LLM context prompt.

In enterprise software, pure dense vector retrieval routinely fails production evaluations. When a customer searches for a specific error code (ERR_502_BAD_GATEWAY), a contract clause identifier (Section 14.3(b)), or a technical part number (LM317T), vector search hallucinates conceptually adjacent passages rather than retrieving the exact string.

State-of-the-art production search systems solve this by deploying a Two-Stage Hybrid Search with Reranking Pipeline.

The Two-Stage Hybrid Architecture

User Query splits into:

  1. Lexical Retrieval (BM25 / Elasticsearch) yielding Top 50 Candidates.
  2. Dense Vector Retrieval (HNSW Index / Cosine Similarity) yielding Top 50 Candidates.

These candidates pass into: 3. Merge via Reciprocal Rank Fusion (RRF) yielding Top 30 Unified Candidates. 4. Stage 2: Cross-Encoder Neural Reranker (Cohere / BGE-Reranker) yielding Top 5 Precision Chunks injected into the LLM Generation Context.

Stage 1: Combining BM25 with Dense Vectors

  • BM25 (Best Matching 25): A probabilistic lexical ranking function based on Term Frequency and Inverse Document Frequency (TF-IDF). It excels at precise keyword matching, rare alphanumeric codes, and exact technical terminology.
  • Dense Vector Search: Encodes sentences into 768- or 1536-dimensional latent semantic space. It excels at synonym resolution, conceptual queries (“how to terminate agreement” matching “contract cancellation clause”), and cross-lingual retrieval.

Merging Candidates: Reciprocal Rank Fusion (RRF)

Vector cosine scores (0.0 to 1.0) and BM25 scores (0.0 to 45.0+) cannot simply be added together without arbitrary normalization weights that break across varying query types.

Reciprocal Rank Fusion bypasses score scale differences by ranking solely on candidate ordinal positions:

$$RRF\Score(d \in D) = \sum{m \in M} \frac{1}{k + r_m(d)}$$

Where $M$ is the set of retrieval systems (lexical and dense), $r_m(d)$ is the rank of document $d$ in system $m$, and $k$ is a smoothing constant (standard benchmark: $k = 60$). Documents that rank within the top 10 on both BM25 and vector search surge to the top of the combined candidate pool.

Stage 2: Cross-Encoder Reranking

Bi-encoder embedding models compute vector representations of the query and document completely independently. This enables pre-computing document vectors offline, but prevents token-to-token cross-attention between query words and document words.

A Cross-Encoder Reranker passes both strings simultaneously into a transformer network:

$$\text{Input} = [\text{CLS}] \; \text{Query} \; [\text{SEP}] \; \text{Document Chunk} \; [\text{SEP}]$$

Every single token in the query attends to every single token in the passage across all self-attention layers. This yields immense precision, filtering out “topically relevant but factually useless” chunks.

Performance and Cost Benchmarks

MetricPure Vector SearchHybrid (BM25 + Vector)Hybrid + Neural Reranker
Retrieval Recall@1072% – 78%86% – 91%96% – 98%
P95 Latency15ms – 35ms25ms – 55ms80ms – 160ms
Compute Cost Per Query$0.0001 (DB only)$0.00015 (DB only)$0.0015 – $0.0030 (GPU inference)
Handling of Exact CodesFails frequently100% accurate100% accurate

Sources and references

Frequently asked questions

Why is pure vector search insufficient for enterprise search?
Dense vector embeddings excel at conceptual semantic matching but fail on exact keyword lookups, part numbers, acronyms, SKU identifiers, and rare proper nouns.
What is Reciprocal Rank Fusion (RRF)?
RRF is an algorithm that combines ranked search result lists from multiple retrieval systems (e.g., BM25 and vector search) into a single unified score without requiring score normalization.
What is the latency trade-off of a cross-encoder reranker?
Bi-encoders embed queries and documents independently (fast vector indexing), while cross-encoders compute joint attention between the query and each candidate passage, adding 30ms to 120ms of latency per query.

About the author

Written by the StackSignal Editorial Team, which researches, writes, and tests every guide on this site. Read more about our editorial standards or contact us with suggestions.