The Full Industrial RAG Pipeline: Build, Retrieve, Evaluate, and Operate
Most RAG tutorials stop at the toy loop. This walkthrough names the exact parameters, failure modes, and production safeguards — from OCR routing to cache isolation — that turn a demo into a system that won't silently leak permissions or hallucinate probabilities.
The minimal RAG loop — extract, chunk, vectorize, cosine retrieval — breaks the moment it meets scanned PDFs, sentences cut in half, or queries phrased differently than the stored text. A production system splits into an offline build pipeline (parsing, cleaning, splitting, vectorizing, indexing) and an online retrieval pipeline (query transformation, multi-path recall, rerank, Top-K selection), with evaluation metrics continuously feeding badcases back into rebuild decisions.
Build-phase parameters like chunk size, overlap, and whether to concatenate metadata into the vector text determine how data enters the store; changing any one requires a full rebuild. Retrieval-phase parameters — Top-K, similarity threshold, weighting — are adjustable per query. Multi-path recall combines vector search with BM25 keyword matching and metadata filtering, fused via Reciprocal Rank Fusion, then a cross-encoder reranker does fine-grained scoring on the top candidates.
Production wraps this in four cross-cutting layers: PII desensitization before chunking, semantic caching with isolation dimensions to prevent permission leaks, intent routing and multi-turn rewriting on the query side, and an operations flywheel that monitors hit rates, latency, and token cost while feeding badcases back into the test set. Semantic caching trades a 10ms embedding call for a full second-level retrieval+generation, but the similarity threshold must be ≥0.95 to avoid silently returning wrong answers for near-identical queries with opposite meanings.
The article's central distinction — build parameters require a full database rebuild when changed, retrieval parameters are adjustable per query — is a practical cost boundary that most RAG guides never state explicitly.
Moving HyDE-style hypothetical question generation from retrieval time into the build phase (indexing pre-generated questions) is a design tradeoff that trades storage and upfront LLM cost for near-certain recall at query time.
The three-layer answer to "where does probability scoring live" — retrieval metadata boost, rerank weighting, and generation-time structured scoring rules — exposes that vector DBs are evidence finders, not reasoning engines; the reasoning must be explicit and auditable.
The semantic cache isolation design (scope + kb_version as part of the cache key) solves both the permission-leakage problem and the cache-invalidation problem in one mechanism, which is cleaner than maintaining separate invalidation logic.
The article treats evaluation not as a one-time gate but as a continuously growing closed loop where online badcases become test cases, making the test set itself a living artifact that improves with usage.