The Problem: Every Industry Has It
Healthcare systems have 10,000+ clinical protocols. Law firms manage 50,000+ case documents. Banks maintain thousands of compliance policies across geographies. Insurance companies handle hundreds of underwriting guidelines that change quarterly.
The pattern is universal: organizations accumulate thousands of documents authored by different teams, at different times, with overlapping and sometimes contradictory information. Then someone asks a simple question — and the answer is buried across 5 documents, 3 of which disagree.
Vanilla RAG (search → stuff → generate) breaks spectacularly at this scale. This article presents a 9-step production pipeline that works across any document-heavy domain.
Whether it's legal contracts, medical literature, compliance policies, or technical documentation — the architecture is the same. Only the documents change.
End-to-End Architecture
The 9 Steps Explained
Cache Check
Hash + semantic match (cosine ≥ 0.92). Context-aware keying by user role/region. Catches 20–40% of repeat queries instantly.
Intent Classification
Lightweight LLM classifies query type (factual/procedural/comparative) and determines search scope across document tiers.
Multi-Path Search
5 parallel paths: Q&A pairs, document summaries, section vectors, chunk vectors, tier-filtered. Each excels at different query types.
Tiered RRF Merge
Reciprocal Rank Fusion with authority weights: primary docs 1.0x, linked references 0.8x, unlinked 0.6x. Dedup at 80% overlap.
Link Expansion
Pre-built document link graph surfaces referenced material that search missed. Single SQL lookup (~5ms).
Conflict Check
Lookup pre-computed conflict table. Annotate which passages are authoritative when contradictions exist. ~10ms.
LLM Reranking
Top 15 → Top 5–7. Tier-aware, conflict-aware scoring. Produces focused, non-contradictory context window.
Structured Generation
Context fed as [Authoritative] → [Supporting] → [Conflicts]. Every claim traced to a source passage.
Quality Fallback
If quality < 0.70 → re-search with broader scope → re-generate. Self-correcting loop. Fires on <5% of queries.
Where This Applies
This architecture is domain-agnostic. It works anywhere you have:
- Healthcare — clinical protocols, drug interactions, treatment guidelines across specialties
- Legal — contracts, case law, regulatory filings, compliance policies
- Financial Services — underwriting rules, KYC procedures, risk policies
- Manufacturing — SOPs, safety procedures, maintenance manuals
- Government — policy documents, citizen services, inter-department guidelines
- Any enterprise — HR policies, IT procedures, vendor contracts at scale
The common thread: thousands of documents, multiple authors, overlapping topics, periodic updates, and users who need one correct answer fast.
Performance at Scale
Cache hit: ~50ms (instant)
Intent + search: ~600ms (parallel paths)
Merge + expand: ~25ms (in-memory + SQL)
Conflict check: ~10ms (indexed lookup)
LLM reranking: ~800ms (top-15 passages)
Answer generation: ~1500ms (structured prompt)
Quality check: ~300ms (scoring pass)
────────────────────────────────────────────
Total (uncached): ~3.3s p95
Total (cached): ~50ms
Takeaway
Production RAG is not "search + generate." It's a layered intelligence system where each stage refines signal: Cache → Route → Search → Rank → Validate → Generate → Self-correct.
The documents change. The architecture doesn't.