Advanced RAG: Hybrid Dense-Sparse Search & Cross-Encoder Re-Ranking
Overcoming retrieval failures with reciprocal rank fusion and semantic chunking.
Table of Contents (30 Concepts)
1. Dense vs Sparse Embeddings (BM25 + ColBERT)
Dense vectors excel at semantic concepts but miss exact keyword hits. Sparse BM25 matches exact lexical tokens. Combining both with Reciprocal Rank Fusion delivers 95%+ retrieval accuracy.
2. Semantic Chunking & Boundary Optimization
Instead of arbitrary 500-token fixed splits, splitting text at natural semantic paragraph and code block boundaries prevents context fragmentation.
3. Reciprocal Rank Fusion (RRF) Formula & Weighting
Combining rank positions from multiple retrievers using score = 1 / (60 + rank) delivers robust ordering regardless of raw distance metrics.
4. Cross-Encoder Re-Ranking & Context Compression
Bi-encoders encode queries and documents independently for fast cosine search. Cross-encoders examine query-document pairs together for fine-grained ranking.
5. Hierarchical Graph Search (HNSW Index Parameters)
Tuning ef_search and M parameters in HNSW to achieve 99% recall with sub-5ms vector distance lookups.
6. Filtering with Payload Metadata & Pre-Filtering vs Post-Filtering
Pre-filtering vector candidates by tenant ID and timestamps eliminates unnecessary vector distance math.
7. Lost-in-the-Middle Mitigation & Context Window Packing
Placing the most relevant retrieved chunks at the very beginning and very end of the LLM prompt context.
Subscribe to continue reading the full masterclass
You’ve finished the first 7 concepts. Join 120,000+ senior engineers to unlock the remaining 23 concepts, deep-dive trade-off diagrams, and our 120+ edition archive.