RAG vs fine-tuning vs prompt-cached long context: pick the right architecture
Teams still spend weeks fine-tuning a model on internal docs only to watch it hallucinate updated prices, or stand up a vector database for a 40-page handbook that fits in one cached prompt for $9.04 per 1,000 queries. Picking the right pattern comes down to three numbers: how big your corpus is, how often facts change, and whether you are teaching new facts or strict output behavior.
- Unsupervised fine-tuning fails on changing facts: across 3 models on 910 post-cutoff questions, plain fine-tuning moved mean accuracy from 43.0% to 41.1% (-1.9 pp), whereas RAG jumped to 77.9% (+34.9 pp).
- For static docs under 30K to 50K tokens, prompt-cached long context (CAG) beats RAG on both multi-hop HotPotQA accuracy (79.51% vs 76.76% at 21K tokens) and 1,000-query input cost ($9.04 vs $10.20 on Sonnet 4.6, or $3.54 vs $6.80 on Sonnet 5.5).
- Past 64K to 85K tokens or under frequent edits, CAG drops behind Sparse Top-5 RAG (74.07% vs 75.35% at 85K tokens) and cache-thrashing rewrites spike 150K-token input spend 29.9x ($304.95 vs $10.20 per 1,000 queries).
The 30-second decision matrix
Most architecture debates pit RAG against fine-tuning while ignoring prompt-cached long context, also called Cache-Augmented Generation (CAG). Match your workload to the row below before writing a chunker or launching a training job.
| Workload shape | Best default | Verified benchmark & cost signal | Main failure trap |
|---|---|---|---|
| Static handbook or codebase docs (<30K to 50K tokens) | Prompt-cached long context (CAG) | Zero chunking or vector DB; 79.51% vs 76.76% RAG at 21K tokens and $9.04 vs $10.20/1k queries on Sonnet 4.6 ($3.54 vs $6.80 on Sonnet 5.5). | Dynamic timestamps or shuffled tools bust the prefix cache. |
| Large (>50K tokens), permissioned, or daily-changing docs | Hybrid RAG (BM25 + vector + RRF) | 77.9% vs 41.1% fine-tuning on unseen facts; flat $10.20/1k input cost vs $304.95 when 150K docs thrash cache. | Dense-only search misses exact SKUs and error codes without BM25. |
| Strict tone, compact JSON schema, or rubric compression | LoRA / QLoRA fine-tuning | Bakes behavioral rules into weights; trimming 3,800 rubric tokens saves $11.40/1k uncached calls ($25 breaks even at 2,193 calls). | With 0.10x prompt caching on, break-even stretches 10x to 21,930 calls. |
| Domain shorthand or strict citations over live records | RAFT hybrid (citation fine-tune + RAG) | Trains the model to quote oracle chunks and ignore distractors, lifting HuggingFace APIBench from 42.59% (naive SFT + RAG) to 74.00%. | Standard QA-only SFT + RAG hurts context reading (-18.47 pp on HuggingFace). |
Why fine-tuning fails on changing facts
Gradient updates reshape how a model formats answers, follows rubrics, and speaks domain shorthand, yet they are a weak way to store new facts. Ovadia et al. (EMNLP 2024, arXiv:2312.05934) tested Mistral-7B, Llama2-7B, and Orca2-7B on 910 multiple-choice questions about events that happened after every model's pretraining cutoff.
Standard unsupervised fine-tuning on those Wikipedia articles (FT-reg) lowered 3-model mean accuracy from 43.0% to 41.1% (-1.9 pp), with Llama2-7B dropping 13.4 percentage points. Even rewriting every article 10 different ways with GPT-4 (FT-par) reached only 51.5%, while off-the-shelf RAG hit 77.9% (+34.9 pp) without training a single weight.
| Model (Ovadia et al. Table 2) | Base | FT-reg | FT-par (10x) | Base + RAG | FT-reg + RAG |
|---|---|---|---|---|---|
| Mistral-7B | 48.1% | 50.4% (+2.3 pp) | 58.8% (+10.7 pp) | 87.5% (+39.4 pp) | 81.0% |
| Llama2-7B | 35.3% | 21.9% (-13.4 pp) | 39.2% (+3.9 pp) | 58.5% (+23.2 pp) | 32.6% |
| Orca2-7B | 45.6% | 51.1% (+5.5 pp) | 56.6% (+11.0 pp) | 87.6% (+42.0 pp) | 82.0% |
| 3-model mean | 43.0% | 41.1% (-1.9 pp) | 51.5% (+8.5 pp) | 77.9% (+34.9 pp) | 65.2% |
Fine-tuning pays off when you compress a long behavioral spec rather than volatile facts: shrinking a 4,000-token rubric and 12-shot schema prompt down to 200 tokens saves $11.40 per 1,000 uncached calls on Sonnet 4.6 ($3.00/MTok), paying back a $25 LoRA run in 2,193 calls. Once you turn on 0.10x prompt caching ($0.30/MTok), that same prompt compression saves $1.14 per 1,000 calls and pushes break-even out to 21,930 calls.
When prompt-cached context beats RAG
RAG pipelines fail whenever a chunk boundary splits a table or top-k retrieval misses one hop of a two-part question. Chan et al. (WWW 2025, arXiv:2412.15605) showed on Llama-3.1-8B that preloading the entire knowledge base into a reusable KV cache beats both BM25 Sparse Top-5 and OpenAI Dense Top-3 RAG on HotPotQA at 21K tokens (79.51% vs 76.76% and 75.82%, generating in 0.85s vs 9.32s uncached) and 43K tokens (78.21% vs 76.33%).
Provider prefix caching makes small static CAG cheaper than RAG too. On a 25,000-token handbook with 4 cold 5-minute cache writes and 996 cache hits across 1,000 queries (400 query tokens), Sonnet 4.6 costs $9.04 vs $10.20 for Top-6 RAG (3,000 retrieved tokens), while Sonnet 5.5 ($0.10/MTok cache reads) drops CAG to $3.54 vs $6.80 and stays cheaper than RAG up to 54,745 static tokens.
| Corpus & traffic scenario | CAG HotPotQA | RAG HotPotQA | Sonnet 4.6 / 1k | Sonnet 5.5 / 1k |
|---|---|---|---|---|
| Small static docs (21K to 25K tok, 4 writes/1k) | 79.51% (0.85s) | 76.76% Sparse / 75.82% Dense (1.49s) | $9.04 CAG vs $10.20 RAG | $3.54 CAG vs $6.80 RAG |
| Medium static docs (43K to 50K tok, 4 writes/1k) | 78.21% (1.41s) | 76.33% Sparse / 74.32% Dense (1.37s) | $16.89 CAG vs $10.20 RAG | $6.28 CAG vs $6.80 RAG |
| Large static corpus (85K tok, 64 docs) | 74.07% (2.26s) | 75.35% Sparse / 74.09% Dense (1.35s) | RAG wins accuracy & decode speed | RAG wins accuracy & decode speed |
| Dynamic 150K docs (500 edits/1k queries) | Prefix invalidated every 2 calls | Re-index only edited chunks | $304.95 CAG vs $10.20 RAG (29.9x) | $195.80 CAG vs $6.80 RAG (28.8x) |
Where long context breaks and hybrid wins
Stuffing bigger or rapidly edited corpora into long context fails on three fronts at once: attention dilution, decode latency, and cache-write thrashing. At 85K tokens (64 HotPotQA docs), CAG accuracy drops from 79.51% down to 74.07% (falling behind Sparse Top-5 RAG's 75.35%) while generation latency climbs 2.66x from 0.85s to 2.26s, and editing a 150K-token doc set every 2 queries (500 5-minute cache writes per 1,000 calls) drives Sonnet 4.6 input spend to $304.95 vs $10.20 for Top-6 RAG (29.9x higher).
When you need both domain-specific output style and live retrieved facts, avoid bolting RAG onto a standard QA fine-tune at test time. Zhang et al. (COLM 2024, arXiv:2403.10131) showed on Llama2-7B that naive domain SFT plus RAG (DSF + RAG) cuts HuggingFace APIBench accuracy from 61.06% down to 42.59% (-18.47 pp), whereas RAFT (training on oracle passages mixed with distractors and verbatim quotes) reaches 74.00% on HuggingFace and 35.28% on HotPotQA.
1. Start under 50K static tokens with CAG
Put your static handbook or schema docs in one frozen system block with cache_control. You skip chunking bugs, embedding drift, and vector database ops while paying $3.54 to $9.04 per 1,000 queries.
2. Switch to Hybrid RAG past 50K or on live edits
Once docs pass 50K to 85K tokens, require per-user access control, or change every few minutes, index chunks with BM25 plus dense vectors fused via RRF so only edited records get re-embedded.
3. Reserve LoRA for behavior, never volatile facts
Fine-tune weights when you need strict output formatting, domain shorthand, or latency gains from cutting a 4,000-token rubric down to 200 tokens, and re-check the 21,930-call break-even against cached prompts.
4. Train with distractors (RAFT) when combining both
Never bolt RAG onto a plain QA fine-tune at test time: on HuggingFace APIBench, naive SFT + RAG drops accuracy from 61.06% to 42.59%, whereas RAFT training with distractor chunks reaches 74.00%.
Scope note: Unseen-fact accuracy figures come from Ovadia et al. Table 2 (arXiv:2312.05934), HotPotQA BERTScore and latency figures come from Chan et al. Tables 1 to 3 (arXiv:2412.15605), RAFT domain benchmarks come from Zhang et al. Table 1 (arXiv:2403.10131), and 1,000-query input costs use deterministic token math on official Anthropic Prompt Caching rates checked on 2026-11-30 (400 query tokens, 3,000 retrieved Top-6 RAG tokens, excluding output tokens and vector hosting fees).
Once you pick your architecture, prevent silent prefix bugs that drop prompt cache hit rates to 0%, fuse BM25 with dense embeddings when vector search misses exact error codes and SKUs, separate retrieval misses from generation misses, keep long multi-turn threads from rotting on bad early drafts, and size 4-bit QLoRA activations and fused cross-entropy on a 24 GiB GPU. Browse all 22 breakdowns on the guides index.
Study RAG, LoRA fine-tuning, and KV caching without losing your main thread
Comparing vector retrieval, LoRA adapters, and prefix KV caching inside one endless chat gets messy fast whenever you ask a side question on a benchmark or pricing formula. Topic Breakdown generates a structured chapter roadmap and lets you highlight any concept to open an isolated side-by-side chat right next to the chapter.
Or enter RAG, fine-tuning, and prompt caching on the home page.
Sources
Checked 30 November 2026Table 2 evaluates 910 post-cutoff current-events questions across Mistral-7B, Llama2-7B, and Orca2-7B: 3-model mean accuracy rises from 43.0% to 77.9% (+34.9 pp) with RAG, drops to 41.1% (-1.9 pp) under standard unsupervised fine-tuning (FT-reg), and reaches 51.5% with 10x paraphrased fine-tuning.
Tables 1 to 3 benchmark Llama-3.1-8B on HotPotQA across 21K, 43K, and 85K tokens: preloaded KV-cache CAG beats Sparse Top-5 RAG at 21K (79.51% vs 76.76%, 0.85s vs 9.32s uncached ICL) and 43K (78.21% vs 76.33%), then crosses below Sparse Top-5 RAG at 85K (74.07% vs 75.35%, 2.26s generation).
- Anthropic Claude API Docs: Prompt Caching Pricing and Prefix Rulesplatform.claude.com
Documents 1.25x 5-minute cache writes, 2.0x 1-hour cache writes, 0.10x cache reads on Claude Sonnet 4.6 ($3.00 base, $3.75 5m write, $0.30 read per MTok), and 0.05x cache reads on Claude Sonnet 5.5 ($2.00 base, $2.50 5m write, $0.10 read per MTok).
- RAFT: Adapting Language Model to Domain Specific RAG (Zhang et al., COLM 2024, arXiv:2403.10131)arxiv.org
Tables 1 and 2 show that naive domain SFT plus RAG drops Llama2-7B accuracy vs standalone SFT on HuggingFace APIBench (61.06% to 42.59%) and HotPotQA (6.38% to 4.41%), while training with oracle quotes and distractor passages lifts accuracy to 74.00% and 35.28%.