Use RAG when the model needs facts it does not have: fresh, private or frequently changing information. Use fine-tuning when you need consistent style, format or behaviour that prompts cannot fix. RAG changes what the model reads at run time; fine-tuning changes the model's weights. Many projects start with prompts, add RAG, and fine-tune last.
On this page
Fine-tuning vs RAG in one viewWhat RAG changes: the contextWhat fine-tuning changes: the weightsDecision table by needA 5-question checklist before you fine-tuneFrequently asked questionsThis page is for a student or developer who has a language model that answers badly and needs to know which fix to try first. The decision logic follows OpenAI's guide on optimizing LLM accuracy, read on 1 December 2026, plus a decision table and a checklist written for this hub. No model names or prices are given, because both change; where cost matters, the table tells you what to compare, and you should read the vendor's own pricing page that day.
Background pages: what is RAG for how retrieval works, what is a large language model for weights and training, and what is prompt engineering for the step that comes before both.
Fine-tuning vs RAG in one view
RAG gives the model new information in the prompt. Fine-tuning changes the model itself. OpenAI's guide frames these as two different levers rather than a linear path: context optimisation is needed when the model lacks knowledge, its knowledge is out of date, or it needs proprietary information, and it maximises accuracy of facts. LLM optimisation, which includes fine-tuning, is needed when output is inconsistent in format, wrong in tone or style, or reasoning is not followed consistently, and it maximises consistency of behaviour.
A simple rule follows: if the problem is what the model knows, use retrieval. If the problem is how the model behaves, consider tuning. If you cannot say which, you have not looked at enough failed examples yet.
What RAG changes: the context
In retrieval-augmented generation the model's weights stay the same. A search step finds relevant text and your code pastes it into the prompt. The demo below does retrieval with word counts and cosine similarity over four short policy lines. Real systems use learned embeddings and a vector index, but the shape is identical: score every chunk against the question, take the best, build a prompt.
import numpy as np
docs = [
"refund requests are accepted within 7 days of delivery",
"orders ship in 2 to 4 working days across india",
"students can pause the subscription once per year",
"invoices are emailed after each successful payment",
]
words = sorted({w for d in docs for w in d.split()})
def vec(text):
v = np.zeros(len(words))
for w in text.split():
if w in words:
v[words.index(w)] += 1
return v
M = np.array([vec(d) for d in docs])
def top(q, k=2):
qv = vec(q)
sims = M @ qv / (np.linalg.norm(M, axis=1) * np.linalg.norm(qv) + 1e-9)
for i in np.argsort(-sims)[:k]:
print(f"{sims[i]:.2f} {docs[i]}")
return docs[int(np.argmax(sims))]
q = "how many days for a refund"
best = top(q)
print("--- prompt sent to the model ---")
print(f"Answer using only this context:\n{best}\nQuestion: {q}")
0.47 refund requests are accepted within 7 days of delivery
0.22 orders ship in 2 to 4 working days across india
--- prompt sent to the model ---
Answer using only this context:
refund requests are accepted within 7 days of delivery
Question: how many days for a refundThe toy has a real weakness you can see: the question says days and refund, and the word overlap finds the right line only because those words appear in it. A question phrased as how long do I have to return something would score zero on every line. That is why production retrieval uses embeddings, and why you must evaluate retrieval separately from the answer.
What fine-tuning changes: the weights
Fine-tuning continues training a pretrained model on your own examples so its internal numbers, the weights, move. The toy below has one weight. Training moves it from 1.0 to 3.0, and every later prediction changes without any new input. Real models have billions of weights, but the principle is the same: the behaviour is now stored in the model.
import numpy as np
# A one-weight "model": y = w * x. Fine-tuning changes w. RAG would only change the input x.
x = np.array([1.0, 2.0, 3.0])
y_target = np.array([3.0, 6.0, 9.0])
w = 1.0
print("before: w =", w, "prediction for x=4:", w * 4)
for _ in range(50):
grad = np.mean(2 * (w * x - y_target) * x)
w -= 0.05 * grad
print("after fine-tuning: w =", round(w, 3), "prediction for x=4:", round(w * 4, 2))
before: w = 1.0 prediction for x=4: 4.0
after fine-tuning: w = 3.0 prediction for x=4: 12.0Full fine-tuning updates all weights and needs a lot of memory. Hugging Face's PEFT library documentation describes parameter-efficient fine-tuning as adapting large pretrained models without fine-tuning all of their parameters, training only a small number of extra parameters, which lowers computing and storage cost. LoRA is one such method. Hosted services also offer tuning through an API, in which case you upload examples and the vendor runs the training.
Two consequences matter. First, knowledge put into weights is frozen at the time of training and is hard to update or delete, so fine-tuning is a poor way to store facts that change. Second, tuning data must be clean and consistent, since the model will copy mistakes as faithfully as good examples.
Decision table by need
| Need | Favours | Why |
|---|---|---|
| Fresh or frequently changing knowledge | RAG | Update the documents; no retraining. Tuned weights go stale |
| Answers must cite a source | RAG | You know exactly which text was supplied, so you can show it |
| Consistent tone, format or house style | Fine-tuning (after trying prompts) | Behaviour is learned from examples instead of long instructions in every prompt |
| Strict output structure, such as a fixed schema | Prompts and structured-output features first, then fine-tuning | Cheaper options often already work; tune if failures remain |
| Cost per request | Depends: compare both | RAG adds input tokens on every call. Tuning has a one-off training bill and may allow a shorter prompt or a smaller model. Read current vendor pricing before deciding |
| Latency | Fine-tuning can help; RAG adds a search step | Retrieval adds time and tokens. A tuned smaller model may respond faster. Measure both |
| Privacy of documents | Depends on where each runs | RAG keeps documents in your store and sends excerpts per request. Tuning sends the data to the training job. Check each vendor's data terms |
| Evaluation | Both need a test set | Score retrieval (did it fetch the right chunk) and the final answer separately for RAG. Hold out examples for tuning |
The two can be combined: tune for tone and format, retrieve for facts. Start with the cheapest lever, which is almost always a better prompt.
A 5-question checklist before you fine-tune
- Is the failure about knowledge or behaviour? Collect 20 failed answers and label each. Mostly missing facts means RAG. Mostly wrong style or format means tuning is a candidate.
- Did you try a stronger prompt, examples in the prompt and retrieval? If not, you have not earned a tuning job. See prompt engineering.
- Do you have at least a few hundred clean, consistent input and output examples? Vendors state their own minimums and formats on their fine-tuning pages. Read them for the service you plan to use.
- Do you have a test set the model has never seen? Without it you cannot tell whether tuning helped or only memorised.
- Who will retrain when the base model or the data changes? Tuning is a maintenance commitment, not a one-time task.
If you answered no to question 2, 3 or 4, do that first. To practise the retrieval half in a project, see AI and ML projects for beginners, and for free model access to experiment with, see free LLM APIs for developers.
Frequently asked questions
What is the difference between fine-tuning and RAG?
Fine-tuning continues training a model on your examples so its weights change and it behaves differently. RAG leaves the model alone and adds retrieved text to the prompt so it can answer from your documents. Fine-tuning shapes behaviour; RAG supplies knowledge at the moment of the question.
When should I fine-tune an LLM?
Fine-tune when prompts, examples in the prompt and retrieval have been tried and the model still gives inconsistent format, wrong tone or style, or ignores a pattern you need. You also need clean examples and a held-out test set. If the problem is missing facts, use RAG instead.
Is RAG cheaper than fine-tuning?
It depends. RAG has no training bill but adds input tokens and a search step to every request. Fine-tuning has an upfront training cost and may let you use a shorter prompt or smaller model. Compare both on current vendor pricing pages with your own request volume.
Can I use RAG and fine-tuning together?
Yes. A common pattern is to fine-tune for tone, format or domain vocabulary and use RAG for facts that change. Evaluate each part separately so you know whether a bad answer came from poor retrieval or poor model behaviour.
Does fine-tuning teach a model new facts?
It can, but it is an unreliable way to do it. Facts stored in weights cannot be easily updated, deleted or cited, and the model may still blend them with wrong information. For facts that change or need sources, retrieval is the safer design.
What is LoRA fine-tuning?
LoRA is a parameter-efficient method: it trains a small set of added weights instead of all the model's weights, so it needs less memory and storage. Hugging Face's PEFT library documents methods like it. The base model stays frozen and the small adapter is loaded alongside it.
Learn this with mentors
AI and machine learning programmes with admissions open: live classes, mentors and project work.

