How do you implement hybrid search combining dense and sparse retrieval in RAG?
Hybrid search merges BM25 (sparse/keyword) with dense vector retrieval for superior recall. Implementation: run both retrievers in parallel, normalize scores to [0,1] range, then combine using reciprocal rank fusion (RRF) or weighted linear combination. RRF formula: score = sum(1/(k + ranki)) where k is typically 60. For weighted combination, start with 0.7 dense + 0.3 sparse and tune on your evaluation set. Architecture in practice: store documents in both a vector database (Pinecone, Qdrant, pgvector) and a search engine (Elasticsearch, OpenSearch). With pgvector and PostgreSQL, use tsvector for BM25-style search alongside vector columns in one database. Key insight: sparse search excels at exact keyword matching (product names, error codes, acronyms), while dense search handles semantic similarity and paraphrasing. Hybrid consistently outperforms either method alone by 10-15% on retrieval benchmarks like BEIR. For production, implement query classification to dynamically adjust weights based on query type.