RAG vs fine-tuning: which one fixes which problem
RAG vs fine-tuning: RAG fixes what a model does not know, fine-tuning fixes how it behaves. A decision table, real costs, and when a long prompt beats both.
- Published
- Reading time
- 14 min read
In short
- RAG changes what a model reads on each request, and fine-tuning changes the model's weights before any request. RAG fixes missing knowledge, and fine-tuning fixes behavior such as format, tone, and accuracy on a narrow task.
- Retrieval adds new facts far better than training does. In a 2023 Microsoft study on questions about recent events, RAG took Mistral 7B from 48.1% to 87.5% accuracy, while fine-tuning on the same text reached 58.8% at best.
- A small, stable corpus needs neither. Put every document at the top of a long prompt and cache that prefix, then move to retrieval when the corpus outgrows the window, changes often, or differs by user.
- A fine-tuned model is tied to one base model and retires with it. As of November 2026, OpenAI is closing its self-serve fine-tuning platform and the Claude API does not offer fine-tuning, so check provider support before planning around a tuned model.
The RAG vs fine-tuning choice depends on what is wrong with the answers you are getting. Retrieval-augmented generation (RAG) fixes what a model does not know: private documents, facts newer than its training data, and details too rare for it to have memorized. Fine-tuning fixes how a model behaves: output format, tone, and accuracy on one narrow task. A team that wants to fine-tune because the model does not know its business has a knowledge problem, and retrieval is the first thing to try.
A third option needs neither a search index nor a training run. When the documents are few and stable, put all of them in a long context window and cache the prefix. That beats both on a small corpus and loses on a large or fast-changing one.
What RAG and fine-tuning are
RAG changes what the model reads at request time. Fine-tuning changes the model's weights before any request arrives.
In retrieval-augmented generation, the application searches a document store for passages related to the request and places them in the context window, the text a model reads on one call, next to the question. The name comes from a 2020 paper by Lewis and colleagues, presented at NeurIPS, which paired a generator's parametric memory (its weights) with a non-parametric memory: a vector index of about 21 million Wikipedia passages. Today the generator is usually an unmodified hosted model, and the retriever uses embeddings (vectors that place similar text close together), keyword search, or both.
Fine-tuning continues the training of a pretrained model on your own examples, which produces new weights. Many services train a small adapter instead of every weight, following LoRA, a 2021 method that freezes the pretrained weights and trains low-rank matrices beside them. On GPT-3 175B, its authors cut trainable parameters by a factor of 10,000 and training GPU memory by a factor of 3. The adapter can be merged into the weights, so it adds no latency at inference.
Where the change lives sets what each approach can do. New facts reach a RAG system when the index is updated, and reach a tuned model only by retraining. Retrieved passages sit in the prompt, so an answer can cite them, while weights carry no pointer back to a document. Access rules can be applied per user at retrieval time, while every caller of a tuned model gets the same weights.
The original RAG paper tested the first of those differences. Its authors built one index from 2016 Wikipedia and one from 2018, then asked about 82 world leaders who had changed in between. With the matching index the model answered 70% and 68% correctly, and with the mismatched one 12% and 4%. Swapping the index updated what the system knew, and nothing was retrained.
RAG fixes what the model does not know
Use RAG when the model lacks a fact, because the fact is private, newer than the training data, or too rare to have been memorized. Studies that test both approaches on the same material find that retrieval adds new facts far better than training does.
A 2023 study by Microsoft researchers gave three 7-billion-parameter models 910 multiple-choice questions about US events from August to November 2023, after their training cutoffs. It compared retrieval with fine-tuning on the source text and on ten paraphrases of each passage.
| Model | Base | Fine-tuned | Fine-tuned on paraphrases | Base with RAG |
|---|---|---|---|---|
| Mistral 7B | 48.1% | 50.4% | 58.8% | 87.5% |
| Llama 2 7B | 35.3% | 21.9% | 39.2% | 58.5% |
| Orca 2 7B | 45.6% | 51.1% | 56.6% | 87.6% |
Fine-tuning on the raw text moved two models by a few points and hurt the third. Paraphrases helped, and RAG still won by a wide margin. Adding RAG to the fine-tuned models scored below RAG on the base models in all three cases. The study has limits. The models were small, and the training was continued next-token prediction on documents, with no question-and-answer pairs.
Later results point the same way:
- Soudani and colleagues tested twelve models on questions about less popular entities. RAG beat fine-tuning by a wide margin, most of all on the least popular facts.
- Gekhman and colleagues, at EMNLP 2024, found that training examples carrying facts new to the model are learned much more slowly than the rest, and that the tendency to hallucinate rises as they are learned.
Retrieval also brings two properties that accuracy scores miss. The passages are in the prompt, so the answer can cite them and a grounding check has something to compare it against. Access control stays in the retrieval layer too. Barnett and colleagues note that fine-tuning bakes your data into the model, while RAG lets you control which chunks each user can reach.
How RAG fails
A RAG system can fail before retrieval, during it, or after it, and only the last kind looks like a model problem. Barnett and colleagues documented seven failure points across three case studies:
- Missing content: the answer is not in the corpus, and the system answers anyway.
- Missed top-ranked documents: the answer ranks below the retrieval cutoff.
- Not in context: the right document was retrieved, then dropped when results were consolidated.
- Not extracted: the answer is in the context, and the model misses it among noise.
- Wrong format: the model ignores a request for a table or a list.
- Incorrect specificity: the answer is too general or too detailed.
- Incomplete: the answer omits information that was in the context.
The first three are corpus and retrieval failures, and fine-tuning the generator does not repair them. Chunking is a common cause. Anthropic's contextual retrieval post points out that a chunk cut from a financial filing may no longer say which company or quarter it describes. Adding that context to each chunk, combining embeddings with BM25 keyword search, and reranking cut its top-20 retrieval failure rate from 5.7% to 1.9%.
Failures four and seven are context failures. More passages are not safer, because each one is a possible distractor, and the Microsoft study found no number of retrieved chunks that was best across its tasks. Failures five and six are behavior failures.
Barnett's team concluded that a RAG system can only be validated in operation. Log the identifiers of the retrieved passages with everything else you record on a request, so a bad answer can be traced to the half that caused it.
Fine-tuning fixes how the model behaves
Use fine-tuning when the model has the facts and the instructions and still produces the wrong kind of output, consistently. Format, tone, and skill at a narrow repeated task are behavior, and behavior lives in the weights.
OpenAI's guide to optimizing accuracy gives two reasons to fine-tune: to raise accuracy on a specific task by showing the model many correct examples, and to reach the same accuracy with fewer tokens or a smaller model. Google's supervised tuning docs describe the same territory: specific output structures, terse or verbose behavior, and labeled tasks such as classification. In practice it fits when:
- The output must keep a format, schema, or house tone that prompting and structured outputs do not hold reliably.
- A narrow task, such as classifying tickets or extracting fields, needs higher accuracy than a prompt reaches.
- A large model does the task well and costs too much. Distillation, as in Amazon Bedrock, trains a smaller student model on a larger teacher's responses.
The OpenAI guide works through a behavior problem, correcting grammar in Icelandic sentences. GPT-4 with few-shot examples reached a BLEU score of 70, a fine-tuned GPT-3.5 Turbo reached 78, and a fine-tuned GPT-4 reached 87. Adding RAG to that model lowered its score to 83, because the retrieved examples were noise for a model that had already learned the task.
Which providers still offer fine-tuning
As of November 2026, fine-tuning is available for Gemini models on Google Cloud, for a set of models on Amazon Bedrock, and for any open-weight model. OpenAI is closing its self-serve platform, and the Claude API does not offer fine-tuning.
- OpenAI: per its deprecations page, job creation closed to organizations new to fine-tuning on May 7, 2026, and ends for active customers on January 6, 2027.
- Anthropic: the Claude API does not offer fine-tuning. Amazon Bedrock lists Claude 3 Haiku as tunable.
- Google: supervised fine-tuning covers Gemini 2.5 Pro, 2.5 Flash, 2.5 Flash-Lite, 3.1 Flash-Lite, 3.5 Flash, and 3.5 Flash-Lite, billed by training tokens (dataset tokens times epochs).
- Amazon Bedrock: fine-tuning covers Amazon Nova, Meta Llama 3.1 to 3.3, and Claude 3 Haiku models, and distillation is offered too.
- Open-weight models: LoRA or full fine-tuning on your own GPUs or through a host. Together AI defaults to LoRA and serves the result on a dedicated endpoint.
A tuned model is tied to one base model and retires with it. OpenAI's fine-tuning docs state that fine-tuned versions of GPT-4.1 and GPT-4.1 mini shut down with their base models on January 14, 2027. A retrieval index survives a change of generator and needs re-embedding only when the embedding model changes.
Training also needs labeled examples. The same docs accept as few as 10 and recommend starting with 50, and the Icelandic example used 1,000.
How to tell which problem you have
Sort your failed answers into knowledge failures and behavior failures before choosing a technique. OpenAI's guide puts prompt engineering first and suggests an evaluation set of at least 20 questions with reference answers. It then sorts failures by an exam analogy: a knowledge failure is one an open textbook would fix, and a behavior failure is one only practice would fix. LLM evaluation covers how to build the set.
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong or vague answers about your products, policies, or data | Facts that were never in the training data | RAG, or the whole corpus in the prompt if it is small |
| Answers that were right last quarter and are stale now | Documents changed after training | RAG, with the index refreshed on every change |
| Errors on rare names, part numbers, or niche topics | Long-tail facts the model saw too rarely | RAG, with keyword search for exact identifiers |
| Users need sources, or may not all see the same documents | Weights carry no citations and no access rules | RAG, with cited passages and a filter at retrieval |
| The right passage was retrieved and the answer is still wrong | Too much context, or the model does not use it | Retrieve less and rerank, then consider tuning on prompts that include passages |
| Output breaks the required format, or tone drifts, despite examples | Behavior | Structured outputs for format first, then train on approved examples |
| A narrow task works on a large model and costs too much | Efficiency | Distill or fine-tune a smaller model |
Whether to use RAG or fine-tuning is then a count of rows. If your failures sit in the first four, training is the slow and expensive way to fix them.
The third option: a long context window with a cached prefix
If the whole corpus fits in the context window and rarely changes, skip retrieval and training. Place every document at the top of the prompt and cache that prefix. Nothing can fail to be retrieved, because nothing is retrieved.
Anthropic's contextual retrieval post, from September 2024, advised putting a knowledge base under 200,000 tokens, about 500 pages, in the prompt whole, with prompt caching to make it affordable. Google's long context guide says many Gemini models now accept 1 million tokens or more and calls context caching the primary optimization for this pattern. At Anthropic's standard rates a cache read costs 0.1 times the input price on most models, and prompt caching lists each provider's terms.
On long context vs RAG, the published evidence favors long context on quality and RAG on cost. An EMNLP 2024 study from Google DeepMind compared them on nine datasets, and long context scored higher on average with all three models tested, while RAG read far fewer tokens. The authors' hybrid, Self-Route, answers from retrieved chunks when the model judges the question answerable and sends the rest to the full context. More than half of the queries stopped at the first step on every model, and on GPT-4o the hybrid scored about the same as long context while using 61% of the tokens.
The long cached prompt stops winning under any of these conditions:
- The corpus outgrows the window.
- The documents change often. Caches match exact prefixes, so an edit to one document turns everything after it into a full-price write.
- Traffic is sparse. Anthropic's default cache entry lives five minutes, renewed on each hit, so a request every ten minutes always pays the write price.
- Users may not all see the same documents. A shared prefix cannot be filtered per user.
- Accuracy falls with length. Context rot sets in well before the window is full, and Google's guide says accuracy drops when a request needs several facts from a long context instead of one.
A long prompt also raises time to first token on a cache miss. The KV cache explains why a hit is so much cheaper, and context engineering covers where the documents belong in the window.
What each choice costs
RAG costs engineering to build and tokens on every request. Fine-tuning costs labeled data up front and retraining later. The long cached prompt costs almost nothing to build and the most per request.
| RAG | Fine-tuning | Long cached prompt | |
|---|---|---|---|
| Build | Ingestion, chunking, an index, a retriever, and usually a reranker | Labeled examples, training runs, and a held-out test set | Order the prompt and set a cache breakpoint |
| Per request | A search step, plus input tokens for the retrieved passages | The shortest prompt. Some hosts need a dedicated endpoint for a tuned model | The whole corpus on every call, at the cached rate on a hit |
| Maintenance | Re-index when documents change, and watch retrieval quality | Retrain when the facts, the task, or the base model changes | Edit the documents and pay for a new cache write |
| How it is evaluated | Retrieval and generation, scored separately | Against the base model on held-out examples, plus a check for regressions elsewhere | The same answer set, run at increasing input lengths |
A Microsoft study on agricultural question answering rated the initial cost of fine-tuning as high, because of the work needed to train on new data, and RAG's as low. It also found that tuned models answered more succinctly, while RAG made prompts larger and output more verbose. Budget for the examples as well as the training run, since someone has to write or approve each one.
LLM evaluation names the metrics for each half of a RAG system. On routes where the same questions repeat, a semantic cache can skip retrieval and the model call together, as long as its entries expire when the index changes.
When to combine RAG and fine-tuning
Combine them when your evaluation shows both kinds of failure: knowledge that changes, and behavior that prompting cannot fix. Add the second technique only after measuring the first, because the combination does not always help.
The Microsoft agriculture study is the case for combining. GPT-4 scored 75% on its question set, 80% with RAG, 81% fine-tuned, and 86% with both. RAFT goes further and trains the model on questions paired with retrieved documents, some of them distractors, so that it learns to ignore the unhelpful ones and quote the relevant passage. That targets failure point four.
The case against combining by default is also above. In the current-events study, RAG on a tuned model scored below RAG on the base model, and in OpenAI's Icelandic example, adding RAG lowered a tuned model's score.
Build retrieval first. If behavior failures remain, train on prompts that already contain retrieved passages, which is how OpenAI's guide ends its example pipeline. You then carry both costs: an index to keep fresh and a model to retrain when its base is retired.
Frequently asked questions
What is the difference between RAG and fine-tuning?
RAG retrieves relevant passages at request time and adds them to the prompt, leaving the model unchanged. Fine-tuning trains the model on examples, so its weights change before any request is made. RAG is the tool for missing or changing knowledge, and fine-tuning is the tool for format, tone, and narrow tasks.
Is RAG better than fine-tuning?
For adding knowledge, yes. In a 2023 Microsoft study on questions about recent events, RAG raised Mistral 7B from 48.1% to 87.5% accuracy, while fine-tuning on the same text reached 58.8% at best. For changing behavior, such as holding a strict output format or a consistent tone, fine-tuning is the better tool.
When should you fine-tune an LLM instead of using RAG?
Fine-tune when the model already has the information it needs and still gets the output wrong in a consistent way: the wrong format, the wrong tone, or too many errors on a narrow task such as classification. It also fits when a smaller, cheaper model could do the task after training on a larger model's outputs. Try prompt changes and structured outputs first.
Can you use RAG and fine-tuning together?
Yes. In one Microsoft study the gains added up: GPT-4 scored 75% alone, 80% with RAG, 81% fine-tuned, and 86% with both. The combination can also hurt when the task is purely behavioral, so build retrieval first and add fine-tuning only if behavior failures remain.
Does a long context window replace RAG?
For a small, stable corpus it can. Anthropic advised in 2024 that a knowledge base under 200,000 tokens, about 500 pages, can go into the prompt whole, with prompt caching to keep the cost down. That stops working when the corpus outgrows the window, changes often, or differs by user.
Sources
- 01Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksarXiv:2005.11401
- 02Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMsarXiv:2312.05934
- 03RAG vs Fine-tuning: Pipelines, Tradeoffs, and a Case Study on AgriculturearXiv:2401.08406
- 04Fine Tuning vs. Retrieval Augmented Generation for Less Popular KnowledgearXiv:2403.01432
- 05Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?arXiv:2405.05904
- 06LoRA: Low-Rank Adaptation of Large Language ModelsarXiv:2106.09685
- 07Seven Failure Points When Engineering a Retrieval Augmented Generation SystemarXiv:2401.05856
- 08Introducing Contextual RetrievalAnthropic
- 09Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid ApproacharXiv:2407.16833
- 10Optimizing LLM accuracyOpenAI API docs
- 11DeprecationsOpenAI API docs
- 12About supervised fine-tuning for Gemini modelsGoogle Cloud docs