Almost every RAG tutorial starts and ends with dense vector search (ORDER BY embedding <=> query_vec LIMIT 5).
It feels magical in demos—until a real customer types:
"How do I fix ERR_TLS_HANDSHAKE_4091?""Spec sheet for part SKU-8841-BX""Where is validate_idempotency_key() defined?"
Dense embedding models compress whole paragraphs into a smooth 1,536-dimensional semantic sphere. Rare alphanumeric tokens like SKU-8841-BX and SKU-8842-BX land right next to each other in vector space—so vector search cheerfully returns the wrong product!
The Two-Stage Hybrid Retrieval Funnel
Production RAG systems don't pick between lexical search and vector search—they fuse both and rerank:
User Query ├──► 1A. Lexical Search (BM25 / tsvector) ──► Top 50 Exact Keyword Hits └──► 1B. Dense Vector (pgvector HNSW) ──► Top 50 Semantic Hits │ ▼ 2. Reciprocal Rank Fusion (RRF, k = 60) ──► Top 25 Fused Candidates │ ▼ 3. Cross-Encoder Reranker ──► Top 5 Gold Chunks -> LLM Why You Can't Just Average BM25 Scores and Cosine Scores
BM25 scores are unbounded (0.0 to 42.7+), while cosine similarity sits in [-1, 1]. Adding raw scores lets BM25 dominate every query.
Reciprocal Rank Fusion (RRF) solves this in 3 lines of math using rank positions instead of raw scores:
$$\text{RRF}(d) = \sum_{r \in {\text{lexical}, \text{vector}}} \frac{1}{60 + \text{rank}_r(d)}$$
If a chunk ranks #2 in both BM25 and vector search, its score (1/62 + 1/62 = 0.0322) beats a chunk that only ranked #1 in one list (1/61 = 0.0164)!
Single-Query Hybrid RRF in Pure PostgreSQL (pgvector + tsvector)
You don't even need two separate databases—Postgres runs both in one CTE query:
WITH semantic AS ( SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> $1::vector) AS r_vec FROM doc_chunks WHERE tenant_id = $3 LIMIT 50 ), lexical AS ( SELECT id, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(tsv, plainto_tsquery('english', $2)) DESC) AS r_lex FROM doc_chunks WHERE tenant_id = $3 AND tsv @@ plainto_tsquery('english', $2) LIMIT 50 ) SELECT COALESCE(s.id, l.id) AS chunk_id, COALESCE(1.0 / (60 + s.r_vec), 0.0) + COALESCE(1.0 / (60 + l.r_lex), 0.0) AS rrf_score FROM semantic s FULL OUTER JOIN lexical l ON s.id = l.id ORDER BY rrf_score DESC LIMIT 25; Trace Hybrid RAG + Cross-Encoder Reranking Step-by-Step
Want to explore interactive vector geometry, chunking labs, and full Python Hybrid RAG pipelines?
👉 Read the Free Visual Hybrid Search & Reranking Lesson on BigOSlate

