Naive RAG vs Production RAG

Naive RAG proves possibility. Production RAG proves reliability. The gap between the two is where most real engineering work lives.

Naive RAG (demo-grade)

User Question
|
Embed + Top-K Search
|
Stuff chunks into prompt
|
LLM generates answer
No reranking
No permission checks
No citation tracking
No fallback/abstention
No freshness guarantees
No evaluation loop

Production RAG

User Question + Auth Context
|
Query Rewrite + Intent Detection
|
Hybrid Retrieval + ACL Filter
|
Rerank + Freshness Check
|
Prompt Assembly + Grounding
|
Generate + Cite + Abstain if weak
|
Log + Evaluate + Feedback Loop

Production RAG Scorecard

LayerCheckWhy it matters
RetrievalRelevant documents appear and rank wellWithout evidence recall, the answer starts from a weak base
GroundingResponse cites supporting passages correctlyPrevents fluent unsupported claims
FallbackSystem abstains when evidence is missingSafer than forcing confident guesses
OperationsLatency and freshness stay inside targetGrounded systems still need product-grade reliability

Single-Hop vs Multi-Hop Retrieval

Single-hop finds evidence in one pass. Multi-hop gathers evidence iteratively when the answer depends on connecting multiple facts.

Single-Hop

Question
->
One retrieval
->
Answer
Example: "What is our PTO policy?"
One search -> finds the PTO document -> answers.
Simple Fast 1 retrieval call

Multi-Hop

Complex Question
|
Retrieve #1 -> sub-fact
|
Retrieve #2 using sub-fact
|
Combine -> Final Answer
Example: "Who manages the team that built Project Alpha?"
Search #1: "Who built Project Alpha?" -> Team Bravo
Search #2: "Who manages Team Bravo?" -> Jane Smith
Complex Slower 2-5 retrieval calls

Trade-off: Multi-hop improves coverage for complex questions but raises orchestration complexity and error compounding. Each hop can introduce noise, latency, and points of failure.


Hallucination Reduction Strategies

Hallucination is often a retrieval and prompting problem before it is a decoding problem. If the context is wrong, thin, stale, or noisy, the generator will sound confident anyway.

Interactive Checklist: Hallucination defense layers

Click each item to check it off. A production RAG system should implement most of these.

Retrieval layer

Generation layer

Defense coverage:
0/10

The hallucination pipeline: where things go wrong

Bad Retrieval
Wrong docs retrieved, relevant docs missed, or noisy chunks selected
Stale Data
Outdated documents that no longer reflect reality
Weak Prompt
No grounding instructions, no citation requirements, no abstention rules
Model Confabulation
LLM fills gaps with plausible-sounding but unsupported information

Citations and Provenance

Provenance is not just a UX feature. It is a control mechanism that increases trust, simplifies debugging, and makes human review faster.

Interactive: Grounded answer with source attribution

Generated Answer
Employees are entitled to 20 days of paid time off per calendar year. Unused PTO can be carried over up to a maximum of 10 days. Requests must be submitted at least 5 business days in advance for planned absences.
[1] Leave Policy v3.2, Section 1 [2] Leave Policy v3.2, Section 2 [3] Leave Policy v3.2, Section 3
Hover over highlighted text to see the source
Each highlighted span maps to a specific passage in the retrieved documents. Users can verify claims, and auditors can trace every statement back to evidence.
Why citations matter
Trust -- Users can verify the answer is not hallucinated
Debugging -- When wrong, you can see which source caused the error
Compliance -- Required in legal, medical, and enterprise contexts
Feedback -- Users can flag incorrect citations, improving the system

Knowledge Staleness and Freshness

Freshness should be handled in the data layer. If the system cannot guarantee freshness, it should communicate uncertainty.

Document freshness timeline

Documents have different freshness requirements. Price lists may go stale in hours; architecture docs may be valid for months.

Staleness risks

Answering with outdated pricing or policies
Citing deprecated APIs or procedures
Conflicting information from multiple document versions
False confidence in stale evidence

Freshness controls

Ingestion schedules -- Automated crawl/sync pipelines
Document versioning -- Track which version was indexed
TTL metadata -- Per-document time-to-live tags
Staleness warnings -- Surface doc age in responses

Agentic RAG

Agentic RAG extends retrieval beyond one fixed lookup. The system may rewrite queries, choose tools, perform multiple retrieval steps, and decide whether more evidence is needed.

Agent loop diagram

User Question
->
Agent Loop
Plan: decompose question
|
Search
Knowledge Base
Call
API / Tool
Query
Database
|
Evaluate: enough evidence?
No -> loop back | Yes -> answer
->
Grounded Answer
with citations

When to use agentic RAG

Question requires connecting facts from multiple sources
Answer depends on live API data (prices, availability)
User intent is ambiguous and requires clarification
Complex multi-step workflows (e.g. "compare product A and B")

When NOT to use it

Simple factual lookups (one retrieval is enough)
Latency-critical applications (each loop adds ~1-3 seconds)
When error compounding across hops is unacceptable
Cost-sensitive environments (more LLM calls per query)

Key insight: Show restraint. Agentic RAG is powerful when the question requires decomposition or tool use, but it can add latency and failure paths for simple tasks. The best engineers know when the simpler approach is sufficient.


Caching Layers in Production RAG

Caching reduces latency and cost by reusing expensive results. But cached answers must respect freshness and permissions.

Cacheable stages in the RAG pipeline

Query Embeddings
Cache the embedding of repeated/similar queries. Saves embedding model call.
Low risk
TTL: hours to days
Retrieval Results
Cache top-K docs for identical queries. Must invalidate when corpus changes.
Medium risk
TTL: minutes to hours
Reranked Candidates
Cache reranker output. Saves expensive cross-encoder inference.
Medium risk
TTL: minutes
Final Answers
Cache the full generated response. Maximum savings, maximum risk.
High risk
TTL: seconds to minutes

Danger zone: cache + permissions

A fast cached answer that is stale or leaked across user scopes is worse than a slower uncached answer. Cache keys must include the user's permission scope. Never serve User A's cached answer to User B if the underlying documents have different ACLs.


Permissions and Access Control in RAG

A RAG system should never retrieve documents the current user is not allowed to see. Security lives in the retrieval layer too.

Where ACLs must be enforced

User Query
+ identity/role
->
ACL Filter
ENFORCE HERE
->
Vector Search
within permitted set
->
Safe Results

Pre-filter (recommended)

Filter by permissions BEFORE vector search. Only permitted documents enter the ANN index query. Prevents leakage through generation.

Secure by default

Post-filter (risky)

Run vector search first, then remove unauthorized results. Can leak information through the model's reasoning even if docs are removed from display.

Potential leakage

Per-tenant indexes

Separate vector indexes per tenant/org. Strongest isolation but highest operational cost and complexity.

Maximum isolation

Interactive: See permission filtering in action

Select user role:

Evaluating Production RAG: Offline vs Online

Evaluation should separate retrieval errors, prompt errors, and generation errors. Otherwise the team cannot tell where to intervene.

Offline Evaluation

Run on curated test sets before deployment.

MetricWhat it measures
Recall@KAre relevant docs in the shortlist?
GroundednessIs the answer supported by retrieved evidence?
Citation accuracyDo citations point to the right passages?
Answer qualityIs the answer correct, complete, coherent?
Abstention rateDoes it correctly refuse when evidence is weak?

Online Evaluation

Monitor with real traffic after deployment.

MetricWhat it measures
User satisfactionThumbs up/down, CSAT scores
Task completionDid the user accomplish their goal?
Answer acceptanceDid the user use the answer or reformulate?
Correction rateHow often do users override the answer?
Escalation rateHow often does the system hand off to humans?

Interactive: Diagnose where the failure is

Click each scenario to see which component failed and how to fix it.


When NOT to Use RAG

Strong engineers know when not to introduce a more complex architecture. The best solution is the one that is adequate, controllable, and maintainable.

Do NOT use RAG when...

Stable procedural logic -- The task is deterministic (math, formatting, code generation from specs). Retrieval adds noise, not value.
Structured data access -- The data lives in a database with a clean API. SQL is more reliable than vector search for structured queries.
Too-noisy documents -- If the corpus is contradictory, poorly structured, or unreliable, RAG will amplify the noise.
Search + templates suffice -- If the problem is just "find a document," a traditional search UI with templated results is simpler and more maintainable.

DO use RAG when...

Knowledge-intensive Q&A -- The answer requires synthesizing information from multiple documents into a coherent response.
Frequently updated content -- Knowledge changes faster than you can retrain models. RAG decouples knowledge from model weights.
Audit/compliance needs -- You need citations, provenance, and the ability to trace every claim back to a source document.
Private/proprietary data -- The LLM was not trained on your data. RAG is the way to ground it in your organization's knowledge.

Interactive: Should you use RAG?