Retrieval-Augmented Generation (RAG) combines retrieval and generation: retrieve evidence from your corpus, then generate an answer grounded in that evidence. It matters because knowledge changes faster than model weights, and RAG lets you update knowledge without retraining the model. In practice, strong RAG systems are pipelines, not prompts. The main engineering work is query processing, retrieval quality, context assembly, evaluation, and production operations. Example: for a support assistant, a user asks “What changed in API v2 rate limits?”. RAG retrieves release notes and policy docs first, then the model answers with citations to the exact source sections instead of guessing from stale parametric memory.

Core Flow

flowchart LR
    Q[User Query] --> T[Query Translation]
    T --> R[Retrieval and Fusion]
    R --> RR[Optional Reranking]
    RR --> C[Context Assembly]
    C --> G[LLM Generation]
    G --> V[Groundedness and Citation Checks]

The pipeline runs in order and each stage constrains the next: a query the translation step mangles cannot be recovered by retrieval, and evidence retrieval never surfaces cannot be reranked into the context. This execution order is why RAG is engineered stage by stage rather than tuned as a single prompt.

Operational Baselines

  • Gate every pattern behind a feature flag. Measure retrieval precision, generation faithfulness, latency p95, and cost per query before and after.
  • Set hard iteration caps on looping patterns (iterative, agentic) to bound latency and cost. For corrective/self-reflective patterns, cap retry count and reject unsupported output instead of looping until the answer looks good.
  • Monitor query drift and noise accumulation in iterative patterns. Track semantic similarity between the original query and each iteration’s retrieval query.
  • Cache aggressively: community summaries (GraphRAG), query rewrites, multi-query result sets, contextual chunk enrichments, reasoning chains, and agent tool outputs. See Caching for cache-key risks.
  • Route simple queries to the cheapest path. Most production traffic is simple — do not pay multi-hop costs for single-hop questions.

RAG vs Fine-Tuning

RAG and Fine-tuning optimize different parts of the system. RAG externalizes knowledge into retrievable sources, while fine-tuning changes model behavior in weights. Choosing correctly prevents expensive retraining for problems that retrieval can solve more safely.

Example: if product policy changes weekly, RAG can update by reindexing documents. Fine-tuning would require repeated retraining cycles and still provide weak source traceability.

AxisRAGFine-tuning
Knowledge freshnessHighLow
Source traceabilityHighLow
Behavioral consistencyMediumHigh
Time to first valueFasterSlower
Operational complexityRetrieval and index opsTraining and eval and release ops

Decision rules:

  1. Start with RAG when facts change often or citation is required.
  2. Add fine-tuning when output style or policy behavior remains unstable after prompt and retrieval tuning.
  3. Keep mutable facts in retrieval; keep behavior patterns in fine-tuned weights.

The combined pattern — fine-tune the model for behavior (format, tone, refusal policy) and use RAG for current factual knowledge — keeps updates fast while preserving behavioral control.

Questions

References

9 items under this folder.