Why Pure Vector Search Fails on SKUs & Error Codes (Hybrid RAG with BM25 + pgvector + RRF)
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…
Dense vector search alone often yields inaccurate results when dealing with SKUs, error codes, or other alphanumeric tokens. This occurs because embedding models convert whole paragraphs into dense 1,536-dimensional semantic space, causing rare tokens to cluster together. To address this issue, two-stage hybrid retrieval funnel production RAG systems are employed, which combine both lexical search (using BM25 or tsvector) and dense vector search (using pgvector HNSW).
The results from both methods are then reranked using Reciprocal Rank Fusion (RRF) and a cross-encoder reranker to produce the top 5 relevant chunks. Pure PostgreSQL can efficiently handle this process with a single CTE query, combining semantic and lexical results and applying the RRF formula to determine the final chunk ranking.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to