DL0085 RAG vs Fine-Tuning

When should you use RAG instead of fine-tuning?

Answer

Reach for RAG when the failure is a knowledge gap, and fine-tune when the failure is a behavior gap. Knowledge gaps look like this: the required facts change (pricing, inventory, incident history), they are private to a tenant, they are too numerous to memorize (millions of documents), or the answer must carry a citation a human can audit. Behavior gaps look different: the model has the right context in the prompt and still emits the wrong JSON schema, the wrong tone, the wrong clinical or legal register, or a malformed tool call. The diagnostic that settles most arguments is a context-injection test: paste the gold document into the prompt by hand, and if the answer becomes correct, you have a retrieval problem, not a weights problem. Update economics reinforce the split, because a corrected fact ships to a RAG system in minutes by reindexing one chunk, while the same correction in a fine-tuned checkpoint means a training run plus a full regression eval, and controlled comparisons have repeatedly found that continued pretraining on new documents injects facts less reliably than simply retrieving them.

(1) Knowledge vs Behavior Test: if hand-pasting the gold document fixes the output, choose retrieval; if the model still misbehaves with perfect context, the deficit is in the weights and only fine-tuning (or better prompting) moves it.
(2) Update Latency And Provenance: RAG updates at index write speed and can return source spans for audit, whereas a fine-tuned model has no pointer back to evidence and its knowledge is frozen at the last training run.
(3) Cost Moves From Training To Serving: retrieval adds a lookup plus k \cdot n_{chunk} prefill tokens on every query, while fine-tuning pays once up front and then serves short prompts, which matters under a tight token budget or a strict p99 latency SLO.
(4) Failure Modes Are Different: RAG fails by retrieval miss or by grounding on a plausible distractor chunk; fine-tuning fails by confidently asserting stale facts and by catastrophic forgetting of general ability.
(5) The Honest Answer Is Often Both: use RAG for the facts and a small LoRA adapter for format, jargon, and the skill of reading retrieved context (including ignoring irrelevant chunks), which is what retrieval-aware fine-tuning trains explicitly.

Flowchart: a failure measured on a held-out eval set fans out into three branches, knowledge gap, behavior gap, and both gaps, which route to RAG updated by reindexing, a LoRA fine-tune updated by retraining, and retrieval-aware fine-tuning that runs both pipelines, with per-query cost notes beneath each option

Figure 1: The decision starts from a measured failure, not from a technology preference: classify the gap first, then accept the update path and per-query cost that come with the chosen option.

The serving arithmetic is worth doing before committing. A 60-token question with k = 5 retrieved chunks of 400 tokens each becomes a 2060-token prefill, roughly 34 times the baseline prompt, plus 20 to 80 ms of vector search and reranking. That is usually cheaper than a training run, but it is a recurring per-request tax, and it is why teams with a small static corpus sometimes skip retrieval entirely and rely on long context with prompt caching. Fine-tuning inverts the profile: one-off data curation and GPU hours, then thin prompts forever. A common production shape is retrieve → rerank → generate on a live index, with a LoRA adapter handling the output contract, so the two mechanisms address the two gaps independently instead of competing.

Mathematical Formulation:
p(y \mid x) = \sum_{z \in \mathcal{Z}_k} p_{\eta}(z \mid x) p_{\theta}(y \mid x, z)
\theta^{*} = \arg\min_{\theta} \mathcal{L}(\theta; \mathcal{D}_{ft})
n_{prefill} = n_{q} + k \cdot n_{chunk}
t_{total} = t_{retrieve} + t_{prefill} + t_{decode}

Where:

  • y is the generated answer and x the user query; the first line is the RAG marginalization, where new knowledge enters through the retrieved set rather than through the weights.
  • z is a retrieved passage from the top-k set \mathcal{Z}_k, scored by the retriever p_{\eta}, and p_{\theta} is the generator; only \mathcal{Z}_k changes when you reindex.
  • \theta^{*} is the fine-tuned parameter set obtained by minimizing loss \mathcal{L} on the curated set \mathcal{D}_{ft}; with LoRA only a low-rank delta is trained, so \theta itself stays frozen.
  • n_{q} is the question length, n_{chunk} the tokens per chunk, and n_{prefill} the per-query context the RAG path must pay for; fine-tuning leaves n_{prefill} = n_{q}.
  • t_{retrieve}, t_{prefill} and t_{decode} are the latency terms; a hard SLO such as t_{total} \leq 300 ms with k = 20 chunks is where retrieval budgets usually break.
Line chart of fact-level answer accuracy over 365 days after a training cutoff: a fine-tuned checkpoint with no retraining decays from 0.88 to about 0.30, quarterly retraining produces a sawtooth that recovers to 0.88 every 91 days, and RAG over a live index stays flat near 0.86

Figure 2: Illustrative fact churn of about 15 accuracy points per quarter: a frozen fine-tuned checkpoint decays, quarterly retraining buys a sawtooth that is stale by construction between runs, and a live index holds accuracy flat with no training at all.

DimensionRAGFine-TuningBoth
Best forChanging, private, or high-volume facts that need citationsOutput format, tone, domain jargon, tool-call syntax, latency cutsGrounded answers in a strict contract, with noisy retrieval
Update pathReindex the changed chunk, minutes, no GPUNew data, training run, regression eval, redeployReindex for facts, retrain only when behavior shifts
ProvenanceSource spans returned with the answerNone; knowledge is diffuse in weightsSame as RAG, with better citation discipline
Per-query costRetrieval latency plus k \cdot n_{chunk} prefill tokensShort prompt only; cheapest at high QPSSame as RAG, plus adapter serving
Main failure modeRetrieval miss, distractor chunks, lost-in-the-middleStale confident facts, catastrophic forgetting, overfit styleTwo systems to version, debug, and evaluate together
Build effortChunking, embeddings, index, reranker, eval setLabeled pairs, hyperparameters, GPU time, eval harnessHighest, so justify it with measured gains over RAG alone

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *