Uncorp
Log In
Generative AI & LLMs3 min readUpdated 2026-10-26

Why Naive RAG Fails in Production: Building Hybrid Search (BM25 + pgvector) with Cross-Encoder Reranking

How to fix missing SKU codes, legal clause lookups, and context dilution by combining sparse BM25 keyword search, dense vector embeddings, Reciprocal Rank Fusion (RRF), and Cross-Encoders.

Naitik Tailor & Uncorp Engineering Faculty
Hybrid RAG Architecture BM25 Vector Database and Cross-Encoder Reranking Isometric Illustration
TL;DR — Key Engineering & Career Takeaways
  • Dense vector search excels at conceptual similarity but often fails on exact alphanumeric identifiers like `ERR-4092`, policy IDs, or part numbers.
  • Hybrid RAG runs Sparse Keyword Search (BM25 / PostgreSQL Full-Text Search) and Dense Vector Search (`pgvector` HNSW) in parallel, merging the top candidates via Reciprocal Rank Fusion (RRF).
  • Adding a Cross-Encoder Reranker (`bge-reranker-large` or Cohere Rerank) to score the top 25 fused chunks down to the top 5 boosts retrieval precision by 25%–40% while slashing LLM prompt token costs.

1. The Blind Spot of Dense Vector Embeddings

When you build your first RAG prototype, dense vector embeddings feel like magic—until a user searches for `'What is the refund policy for order tier SKU-9981-B?'` or `'How do I fix Kafka exception OffsetOutOfRangeException?'`. Because embedding models compress entire paragraphs into a single 1536-dimensional vector, rare alphanumeric tokens get smoothed out, returning chunks about generic refunds instead of `SKU-9981-B`.

2. The 4-Stage Production Hybrid RAG Pipeline

To achieve enterprise-grade retrieval recall and precision, replace single-step vector lookup with this 4-stage pipeline:

Hybrid Search + RRF + Cross-Encoder Reranking Architecture
[User Query] ──► (Stage 1: Query Rewrite / HyDE Expansion)
   ├──► [Dense Vector Search (pgvector HNSW Top-25)] ──┐
   └──► [Sparse Keyword Search (BM25 / FTS Top-25)]  ──┼──► (Stage 2: Reciprocal Rank Fusion RRF -> Top-25)
                                                       │
   (Stage 4: LLM Generation w/ Citations) ◄── [Top-5] ◄┴── (Stage 3: Cross-Encoder Reranker Scores Query+Chunk Pairs)
Comparing Retrieval Strategies Across Real Enterprise Query Types
Query TypeDense Vector OnlyBM25 Keyword OnlyHybrid RAG + Cross-Encoder Reranker
Conceptual ('How do we handle employee parental leave?')High RecallPoor (misses synonyms like 'maternity/paternity')Excellent (captures semantic meaning + exact policy terms)
Exact Identifier ('Show SLA for contract ID MSA-2026-884')Poor (dilutes exact ID in vector space)High RecallExcellent (BM25 surfaces exact ID; Reranker promotes best clause)
Complex Multi-Part Technical QueryModerate (often ranks noisy chunks in top 3)ModerateSuperior (Cross-Encoder computes full cross-attention between query and candidate chunk)

3. How Reciprocal Rank Fusion (RRF) Combines Scores Without Calibration Headaches

BM25 returns unbounded positive scores (e.g., `14.2`), while Cosine Similarity returns values in `[-1, 1]`. Instead of fragile min-max normalization, Reciprocal Rank Fusion (RRF) combines rankings using only the position of each document in both lists: `RRF_Score(d) = 1 / (k + rank_vector(d)) + 1 / (k + rank_bm25(d))` where `k = 60`. You can implement this entire hybrid fusion in a single PostgreSQL CTE query!

Frequently Asked Questions

Why not run the Cross-Encoder over the entire database of 100,000 chunks?

Cross-Encoders pass the query and document together through a full Transformer network, which is highly accurate but computationally expensive. Using fast Bi-Encoder (`pgvector`) + BM25 to narrow 100,000 chunks down to 25 candidates in 15ms, and then reranking only those 25 chunks in ~60ms, gives you the best of both speed and accuracy.

Do we build Hybrid RAG and Cross-Encoder reranking at Uncorp?

Yes—Hybrid Search (BM25 + Dense Vector) and Cross-Encoder Reranking are core hands-on modules in Week 1 of Uncorp's Gen AI Engineering: Advanced (Part 2 Live Cohort).

Written & Reviewed By Uncorp Engineering Faculty

Naitik Tailor & Uncorp Engineering Faculty

Founder & Principal Engineering Mentors (12+ Yrs Enterprise Experience) · VIT CSE '21 · Symbiosis MBA '24 · Ex-Delhivery & Ex-Aditya Birla Capital

About Uncorp

Continue Reading in This Topic Cluster

All 73 Guides