AI Applications
RAG vs Fine-Tuning: When Should You Use Which?
A real fine-tune against retrieval, on the same small model and the same questions: what each one actually teaches, what happens when a fact changes, and how to decide which one a problem needs.
On this page · 15 sections
Two requests reach the support assistant team in the same week.
Billing raises the Pro plan from $25 to $30 a month, and the assistant has to say $30 from tomorrow. And someone wants every answer to end with the article it came from, so customers can check it.
One team member suggests fine-tuning: “Train the model on the help center, then it just knows our product.” Another says the assistant from the last article (opens in a new tab) already retrieves the right articles, so why train anything?
So we did both, on the same small model, with the same questions. After the price change, the retrieval version answered $30 as soon as the changed articles were re-embedded. The fine-tuned version said:
The Pro plan costs $25 per month and includes unlimited projects. Ask for invoice payment through live chat before your first year of payment.
Source: Plans and pricing
The old price, a sentence borrowed from a different answer, and a source line nobody had asked it for in the prompt. Fine-tuning had taught it the habit of ending with a source, and the price as it was on the day of training.
That’s most of this article in one reply. Fine-tuning changes the model’s learned parameters. RAG supplies external information at question time. Fine-tuning can teach a model patterns, and facts too, but facts in the weights are hard to inspect and update. RAG keeps the source material outside the model, where the application can retrieve, replace, and check it. Most decisions between the two get easier once you separate those two jobs.
Try to Understand It This Way
Go back to the new support agent from the last article and their 500-page binder.
A training course changes how the agent works: the tone they use, the steps they follow, the way they end every reply. Weeks later, they still do it without thinking. But if the course also covered prices, they’ll quote the prices from the course, even after the prices change. And details they half-remember come out mixed up, confidently.
Pages on the desk work the other way round. They’re only as good as the pages that get pulled, and the agent has to read them properly. But when a price changes, you change one page, and the next answer is right.
That’s the difference between fine-tuning and RAG. Fine-tuning is the training course: it changes the model itself. RAG is the pages on the desk: it changes what the model is given with each question.
What Each One Actually Changes
RAG changes the input. The generation model’s weights stay exactly as they were (retrieval uses a separate embedding model). For each question, retrieval finds the most relevant documents and puts them in the prompt, as in Article #12. Updating knowledge means updating documents and their embeddings.
Fine-tuning changes the model’s parameters. You train the model further on examples of what you want: here, question-and-answer pairs. Full fine-tuning updates every weight. The common, cheaper method is LoRA, which keeps the base weights frozen and trains added adapter parameters instead. In the LoRA paper’s words, it “freezes the pre-trained model weights and injects trainable rank decomposition matrices”: small extra matrices that are trained while the original model stays untouched. QLoRA goes further and “backpropagates gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters”, so a model can be fine-tuned on modest hardware.
The demo uses QLoRA. The base model is Llama 3.2 1B Instruct, 4-bit, and the adapter trained here has 5.6 million parameters, a small fraction of the model’s roughly one billion. The training run took about 50 seconds on this M4 Pro laptop.
Those 50 seconds are not the cost of fine-tuning, though. The cost is everything around them: creating and checking training data, evaluating every training run, and repeating that process whenever the knowledge stored in the model’s weights is expected to change. We’ll come back to that.
The Experiment
The demo, 02-rag-vs-fine-tuning, uses the same help center (50 articles) and the same test questions as Article #12. It fine-tunes the model on training data written from the help center: 112 question-and-answer pairs covering every article, plus 8 out-of-scope questions with the decline message as the answer. Every training answer ends with a line like Source: Plans and pricing.
None of the 24 test questions appears in the training data. Each test fact has a “twin” in the training data, a training question that covers the same fact in different words:
test question: How long does a teammate have to accept an invitation?
training question: When do invitations expire?
training answer: Invitations expire after 7 days. You can resend an expired invitation from
Settings > Members > Invite.
Source: Inviting teammates
The facts aren’t held out: each one appears in the training data under a different question. What the test holds out is the wording. Asking both wordings separates two things: whether the model reproduces its training answers, and whether it can apply a trained fact when a customer phrases the question differently, which is what customers do. The separate changed-facts test asks something else: what happens with information that wasn’t in the training data at all.
Four conditions, all on the same model:
base the model as downloaded, a one-line system prompt
fine-tuned with the trained adapter, the same one-line prompt
base + rag the model as downloaded, with the 3 retrieved articles and instructions
to answer only from them, ending with a source line
fine-tuned + rag with the adapter, the 3 retrieved articles, and the same instructions
Then five facts change in five articles, as they did for billing: Pro to $30 a month and $300 a year, the password reset link to 2 hours, invitations to 14 days, the Basic plan to 10 members. Five test questions about those facts are asked again.
Implementation note: the exact setup
Machine: Apple M4 Pro (24 GB), on battery power
Libraries: mlx 0.32.4, mlx-lm 0.32.2 (Python 3.12)
Chat model: mlx-community/Llama-3.2-1B-Instruct-4bit, pinned revision 08231374...
Fine-tuning: LoRA rank 8, scale 20, all 16 layers, 5,636,096 trained parameters,
batch 4, learning rate 1e-4, 100 steps (about 3.3 passes over 120 examples),
seed 0, loss on the answers only
Retrieval: Ollama 0.40.16, nomic-embed-text, top 3 by cosine similarity (as in Article #12)
Generation: temperature 0, at most 200 tokens
Runs: trained three times (identical adapter each time), evaluated twice
(identical replies), 2026-11-13
Two choices worth knowing about. The number of training steps was picked from the validation loss (12 extra examples, worded differently from the training data): it was lowest at 100 steps and changed little from there to 300. And a first configuration (LoRA rank 16, scale 20, 600 steps) diverged, so the run uses mlx-lm’s default rank of 8.
The Llama 3.2 chat template writes today’s date into every prompt. The demo fixes it to one date for training and evaluation, so the results don’t depend on the day you run them.
How the replies were graded
The first pass was a key-fact pattern, as in Article #12, and here it was misleading in both directions. The fine-tuned model often put the right number inside a wrong answer:
No. Single sign-on is available on the Basic plan.
The pattern for that question looks for “no” and passed it. Meanwhile “Only the Owners can delete the organization.” failed the pattern for “owner”. So every reply was read and labeled by hand: the 231 replies of one run, which the second run reproduced exactly:
- correct: the key fact is right and nothing in the reply is false.
- partly: the key fact is right, but the reply also says something false, contradictory, or garbled.
- wrong: an answer without the right key fact.
- declined: no answer.
The demo stores each label with a hash of the reply it belongs to, so a changed reply shows up as unlabeled.
The Results
test wording (24) seen training wording (24) not in docs (6)
condition correct partly wrong declined correct partly wrong declined declined
base 0 2 21 1 0 1 22 1 0
fine-tuned 7 6 9 2 14 3 6 1 3
base + rag 10 6 3 5 11 8 2 3 3
fine-tuned + rag 6 7 10 1 7 7 9 1 3
After the five facts changed:
condition new fact new fact, with an error elsewhere old fact other
fine-tuned 0 0 3 2
base + rag 3 2 0 0
fine-tuned + rag 1 0 1 3
And the habit the training data taught, ending with Source: <article title>, counted over the test-wording replies that weren’t declines:
replies with a source line naming an article that answers it
fine-tuned 22 of 22 17 of 22
base + rag 3 of 19 1 of 19
The base + RAG condition was told to end with a source line, in its prompt; one of its three source lines was the placeholder from the instructions, copied as written (“<title of the article …>”). Of the other two, one named the right article and one named the wrong one. The fine-tuned model was never told; it learned it.
No condition here is good enough to ship. This is a 1-billion-parameter model with 120 training examples, and even its best condition had the right answer, with nothing false, for 10 of 24 questions. The point is the shape: where each method helped, and where it didn’t.
What Fine-Tuning Did Well: Behavior
The clearest result is the source line. Every training answer ended with one, and after 100 training steps the fine-tuned model ended every answer with one, whether the answer was right or not. The same model, asked to do it by an instruction in the prompt, managed it in 3 of 19 answers, and named a right article once.
In this experiment, fine-tuning learned a format reliably and improved one part of the procedure: declining questions the help center couldn’t answer. From 8 examples, it declined 3 of the 6 such questions, where the base model declined none. More broadly, fine-tuning can help teach a model how to respond (format, style, tone, procedure) without spending prompt tokens on instructions every time, but whether it learns a behavior reliably has to be measured.
Before reaching for it, though, try the cheaper tools. A capable model often follows formatting instructions without training (see “Prompt Engineering: Beyond Writing Better Prompts (opens in a new tab)”), and a JSON schema can enforce a shape exactly (see “Structured Outputs: Making LLMs Produce Reliable Data (opens in a new tab)”). Fine-tuning earns its cost when the behavior can’t be prompted reliably, as with this small model, or when the instructions get long and you’d rather not pay for them on every request.
Even the learned behavior had limits: 17 of the 22 source lines named an article that answers the question. The others named a related but wrong article, and twice an article that doesn’t exist (“Deleting your project”). The model learned the form of citing a source, not a lookup.
A source line isn’t provenance just because it looks like one. That applies to RAG too: a model asked to name its source can still name the wrong one, as the base + RAG model did. In a RAG application, the application knows which documents it retrieved. It should keep their ids and attach the references itself, or at least validate the model’s citations against them, as Article #12’s application did by letting the model cite only the ids it was given.
What Fine-Tuning Did Badly: Facts
On questions worded like its training data, the fine-tuned model was correct 14 times out of 24. On the same facts in new words, 7 times. It reproduced many of its training answers, but struggled to apply the same facts when the question was phrased differently.
The wrong answers are worth reading, because they show how it fails. It recombined fragments of its training answers:
Q: How long does a teammate have to accept an invitation?
A: A team has to wait 30 minutes or reset the password to unlock it immediately.
Q: How do I link a pull request to a task?
A: Press N, or use the New Task button in any project.
Q: Is single sign-on available on the Basic plan?
A: No. Single sign-on is available on the Basic plan. ...
The first is the locked-account answer from its training data, attached to the invitation question. The second is the keyboard shortcut for a new task. Each sentence sounds like the help center, because it came from the help center. That’s what makes it dangerous: fluent, on-brand, specific, and wrong. And it reversed one fact outright: “Yes. We accept PayPal payment method.”, where its training answer said “No. We do not accept PayPal or cryptocurrency.”
A related result appears in published research, although the training setup is different. Ovadia et al. compared knowledge injection by unsupervised fine-tuning (continued training on raw text) with RAG, and found that “RAG consistently outperforms it, both for existing knowledge encountered during training and entirely new knowledge”, noting that “LLMs struggle to learn new factual information through unsupervised fine-tuning”. They also found that “exposing them to numerous variations of the same fact during training could alleviate this problem”. That finding is about their unsupervised setup; this demo trains on questions and answers. Our training data had about two questions per fact, so more variations per fact is a plausible experiment to try, not a result this run establishes. They would also be more data to write, check, and keep in sync with the help center.
Under the hood: "it was trained on the answer" isn't the same as "it knows the answer"
The training loss fell from 2.52 at the first report to 0.26 at the last: on its training examples, the model became very confident about the next token. The validation loss, on 12 differently worded examples, fell from 5.32 to 1.10 by step 100, then stayed between 1.15 and 1.21 up to step 300. When the training loss keeps falling and the validation loss doesn’t, further training mostly fits the training wording.
Low training loss means the model reproduces the training sequences. It doesn’t mean it will retrieve the right fact from a different question, or keep two similar facts apart (7-day invitations, 30-minute lockouts, 1-hour reset links). LoRA training on 120 examples moves a small number of parameters toward reproducing those sequences. Nothing in that process stores a fact somewhere it can be looked up, checked, or replaced.
What Happens When a Fact Changes
This is where the two approaches are furthest apart.
For RAG, the update was: change five articles and re-embed those five. The base model with retrieval supplied the new value for all five questions, but only three of those replies were free of other errors. The other two added something false (“$300 per year, which is the same as the Basic plan”), a reminder that a small model reading the right page can still misread it, as in Article #12.
For the fine-tuned model, nothing changed, because nothing can change without retraining. It said “1 hour”, “$25 per month”, and “up to 5 members”: the old values, stated as confidently as before. Updating it means editing the training data, retraining, re-evaluating, and redeploying the new adapter, every time a fact changes.
There’s a subtler problem. Asked the reset-link question with the updated article in its prompt, the fine-tuned model still said:
The reset link expires after 1 hour.
Source: Resetting your password
The retrieved article said 2 hours. The trained answer won.
Can You Combine Them?
Yes, and the combination is a common design. But this run shows how it can go wrong. With retrieval added, the fine-tuned model did worse than the base model with retrieval: 6 correct against 10, and 1 of 5 changed facts against 5. It kept answering from its trained fragments, even inventing a price (“$100 per month”) with the real one in its prompt.
The likely reason is in how it was trained. Every training example was a question with no articles in the prompt, so the model was trained to answer from memory, which is exactly the habit you don’t want in a RAG system. One run isn’t proof of the cause. One approach, explored in the RAFT paper, is to train with retrieved documents in the prompt, including irrelevant ones, so the model learns to use relevant context and ignore distractors: “we train the model to ignore those documents that don’t help in answering the question”. This demo doesn’t test that; it’s one of the things to try.
The general rule: if you combine them, fine-tune for behavior with retrieval-shaped training examples, and let retrieval supply the facts. Don’t train facts into the weights and then hope the model prefers the retrieved version.
Choosing Between Them
| The problem | Usually | Why |
|---|---|---|
| The model doesn’t know your facts | RAG | Facts change, need sources, and differ between users |
| Facts change often | RAG | Updating means editing documents, not retraining |
| Answers must cite their source | RAG | Retrieval gives the application the ids of the documents it retrieved; the application can attach those references and validate whether they support the answer. A fine-tuned model can learn citation formatting, but a generated source line alone isn’t provenance |
| Different users may see different documents | RAG | Retrieval can filter by permission before anything reaches the model |
| The model’s format, tone, or procedure is wrong | Prompt first, then fine-tuning | Prompts and schemas are cheaper; fine-tuning when they aren’t reliable enough |
| Long instructions are repeated in every prompt | Fine-tuning, eventually | Trained behavior saves those tokens on every request, but adds adapter management, evaluation, and deployment: compare the total cost |
| A specialized task where examples may improve a small model | Fine-tuning, if evaluation shows a meaningful improvement | A smaller fine-tuned model can be cheaper and faster to serve, but training doesn’t guarantee the capability |
| Both: specific behavior and changing facts | Both | Fine-tune the behavior on retrieval-shaped prompts; retrieve the facts |
The simplest way I think about it: if an answer must change when its source document changes, I’d usually start with retrieval. If the behavior should stay the same no matter which document is retrieved, like a format, a tone, or a procedure, fine-tuning may be appropriate.
What Fine-Tuning Really Costs
The training run was the cheapest part of this experiment. What took the time:
- Writing the training data. 120 examples for 50 short articles, every answer checked against its article. A real help center needs far more, with several wordings per fact, as the results showed.
- Evaluating every version. A fine-tuned model is a new model. It needs the full test set, read by a person where patterns can’t judge, every time it’s retrained. Here, the patterns misgraded answers both ways.
- Retraining on changes. If the fine-tuned model itself is expected to reflect each knowledge change, every price change, policy update, or new feature means new training data, a new adapter, a new evaluation, and a new deployment, with a way to roll back. Some systems batch updates instead, and accept a period of stale knowledge.
- Choosing settings. One of the two LoRA configurations tried here diverged. A diverged or overfitted run looks fine until you test it.
RAG has its own costs: retrieval infrastructure, embedding and index maintenance, prompt tokens for the retrieved text, and Article #12’s retrieval misses and near-miss answers. But the knowledge lives in documents and an index that you can inspect, version, and change without retraining; in this small demo, an update meant re-embedding five articles.
What Breaks
- Stale knowledge in the weights. The fine-tuned model kept the old price. Nothing in its answer showed that the fact might be out of date.
- Fluent recombination. Fine-tuned answers made of real fragments, put together wrongly, sound more trustworthy than a generic invention.
- Citations that aren’t lookups. The fine-tuned source line looked like provenance, but 5 of 22 named the wrong article or one that doesn’t exist. Build citations from the documents the application actually retrieved.
- Fine-tuning that fights retrieval. Trained without context, the model preferred its memory to the article in front of it.
- Checks that grade the wrong thing. Key-fact patterns passed garbled answers and failed correct ones. Evaluate fine-tuned models by reading, not only by matching.
What to Take Away
- Fine-tuning changes the model’s learned parameters; RAG changes what it’s given at question time. Here, fine-tuning taught a format reliably and facts unreliably.
- Knowledge that changes belongs in retrieval. After five facts changed, RAG answered with the new values; the fine-tuned model kept the old ones, even with the new article in its prompt.
- Reproducing training answers isn’t the same as applying the facts. 14 of 24 correct in the training wording became 7 of 24 in the customer’s wording.
- Combine them carefully. Train on the prompts you’ll serve, or the fine-tuned model may ignore what retrieval gives it.
- Try the cheaper tools first. A prompt, a schema, or retrieval; fine-tune when they can’t do the job reliably.
Think About These Use Cases
-
A legal-document assistant: Answers must follow a strict structure and cite clauses. Which parts would you fine-tune, and which must come from retrieval?
-
A support bot for a product that ships weekly: How often would a fine-tuned model need retraining, and what would that pipeline look like?
-
A small model on a device: It must run offline with no retrieval service. What changes about the trade-off, and how would you keep its knowledge current?
-
Brand voice: Marketing wants every answer in a specific tone. Would you start with a prompt, few-shot examples, or fine-tuning, and what would you measure to decide?
-
A combined system: You fine-tune for format and use RAG for facts. How would you build training examples so the model trusts the retrieved documents over its own memory?
If you want to talk one of these through, take it to GPT along with this article. Ask GPT ↗️
Related Sources
- 02-rag-vs-fine-tuning: The companion demo for this article: the training data, LoRA fine-tuning with MLX, the four-way evaluation, the changed-facts test, and the hand labels (Python, Apple silicon).
- LoRA: Low-Rank Adaptation of Large Language Models (Hu et al., 2021): The method used to fine-tune here.
- QLoRA: Efficient Finetuning of Quantized LLMs (Dettmers et al., 2023): Fine-tuning a quantized model with LoRA adapters.
- Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs (Ovadia et al., EMNLP 2024): RAG versus unsupervised fine-tuning for adding knowledge.
- RAFT: Adapting Language Model to Domain Specific RAG (Zhang et al., 2024): Fine-tuning a model with retrieved documents in its training prompts.
- mlx-lm: Fine-Tuning with LoRA or QLoRA: The training library used in the demo, including its data formats and prompt masking.
What’s Next?
In this experiment, retrieval handled changing facts better, but the RAG pipeline in these two articles is still a demo: one retrieval call, no monitoring, and failures you only find by reading replies.
In the next article, we’ll look at Designing a Production-Ready RAG Pipeline: what changes when retrieval, generation, failure handling, and observability have to work every day, not just in a test run.