Architecture
Building an enterprise-grade Retrieval-Augmented Generation (RAG) pipeline requires coordinating text ingestion, chunking, dual-embedding indexing, hybrid retrieval fusion, and cross-encoder re-ranking into a deterministic execution pipeline.
1. Mathematical Score Normalization: Reciprocal Rank Fusion (RRF)
Standard vector similarity scores (e.g., Cosine Distance) and lexical search scores (e.g., BM25 TF-IDF) operate on different scale distributions. Combining them directly leads to biased ranking.
Reciprocal Rank Fusion (RRF) normalizes search ranks without requiring arbitrary score calibration:
Combines rank positions across dense vector search and sparse lexical search into a unified relevance score.
2. Architecture Comparison: Vector Search vs. Lexical vs. Hybrid RAG
| Architecture Option | Primary Best-For Case |
|---|
Decisions
| Decision | Required evidence | Review trigger | |---|---|---| | Use Reciprocal Rank Fusion (RRF) for hybrid search score normalization. | Benchmark evaluation showing improved top-5 recall over single vector search | Keyword lookup accuracy dropping below 90% | | Enforce cross-encoder re-ranking top-K filter on candidate pools. | Latency budget audit confirming re-ranking latency $\le 30\text$ | P99 query response latency exceeding SLA | | Combine dense HNSW vector index with BM25 sparse keyword index. | Query retrieval evaluation confirming exact SKU and technical term precision | Unhandled technical jargon search failures |
Alternatives and trade-offs
Pure dense vector search provides strong semantic discovery but fails on specific alphanumeric identifiers. Hybrid search with RRF fusion resolves exact keyword lookup failures at a modest latency cost (+6ms). Adding a cross-encoder re-ranker increases precision significantly but adds GPU inference overhead to the query path.
Failure modes
- Fixed-size chunking splitting mathematical equations or code blocks across chunk boundaries.
- Single-vector search missing exact product SKUs or serial number queries.
- Re-ranker timeouts under high concurrent request spikes degrading retrieval to raw vector ordering.
Operational checklist
- [ ] Chunking parser respects markdown headers and sentence boundaries.
- [ ] Dual-embedding pipeline generates HNSW dense vectors and BM25 sparse tokens concurrently.
- [ ] RRF smoothing constant is configured to $k = 60$.
- [ ] Cross-encoder re-ranking top-K is capped at 10 items to preserve low-latency response times.
Connected practice
- Labs: /labs/rag-chunking-vector-search
- System breakdowns: /systems/inside-vllm
Sources
langgraph-repoanthropic-effective-agentsanthropic-trustworthy-agents
