RAG or fine-tuning?
9 min read
Three ways to change what a model does
When a model gives a bad answer, the cause is one of two things. Either it did not know something it needed, or it knew enough and behaved the wrong way. The two problems need different fixes, and mixing them up is the most common and most expensive mistake.
You have three tools, and they cost very different amounts:
- A better prompt. You change the instructions. It costs nothing and takes a minute.
- Retrieval. You look up the right text and add it to the prompt. This is Retrieval-augmented generationA method where an app searches sources at question time and adds selected passages to the model's context. Updated information can inform later answers once it is available to retrieval, but the results and answers still need checking.. It needs a search step, and the model stays as it is.
- Fine-tuning. You Model fine-tuningAdditional training of an existing model using new data. It updates model or adapter parameters to change performance or behaviour for a task; the result must be evaluated. on your examples. It needs data, a training run and a new set of Model weightsThe numbers inside a model. Training sets them, and everything the model knows is stored in them..
The first two change the input to the model. Fine-tuning is the only one that changes the model.
What each one is good at
A better prompt
A clear prompt fixes more than most people expect. If the model ignores a rule, the rule may be buried or vague. Say it once, say it plainly, and add one example of the answer you want.
Retrieval
Retrieval is for facts. At question time the app searches your documents, adds the relevant passages to the prompt and asks the model to answer from them.
- Fresh. Change a document and the next answer changes. No training run is needed.
- Checkable. The app can show the source passage, so a reader can verify the answer.
- Less guessing. A model that reads the answer in front of it is less likely to AI hallucinationAn answer that sounds confident but is false. The model wrote text that fits the pattern instead of text that is true..
Fine-tuning
Fine-tuning is for behaviour. After enough examples the new habit becomes the model's default, and you stop repeating it in every prompt.
- Style and tone. The model writes in your house voice.
- Format. The model returns the exact shape your app expects, every time.
- A narrow task. The model does one job more reliably than a general prompt can make it.
Fine-tuning is a poor way to teach facts. Knowledge that ends up in the weights is hard to inspect, hard to correct and frozen on the day you trained. If your price list changes on Monday, a fine-tuned model still quotes last week's prices until you train it again. It can also state a half-remembered fact with full confidence.
The same problem, two inputs
The sketch below shows what each tool hands to the model. It uses plain Python and needs no library.
import json
policy = "Refunds are accepted within 30 days of delivery."
question = "Can I return my order after 20 days?"
# Retrieval: the fact travels inside the prompt. The weights stay the same.
rag_prompt = f"Answer using only this policy.\nPolicy: {policy}\nQuestion: {question}"
# Fine-tuning: the example teaches a habit. The reply holds the voice, not the policy.
training_example = {
"prompt": question,
"completion": "Thanks for asking! Your order is eligible, and I have started your return.",
}
print(json.dumps(training_example))If the policy changes, you edit one string and the next prompt is correct. If the voice changes, you collect new examples and train again. Facts change often and voice rarely, so each one goes where it is cheapest to update.
A checklist for choosing
Ask one question first: what is wrong with the answer?
- The information is missing or out of date. Use retrieval.
- The information is right but the tone, format or reliability is off. Consider fine-tuning.
- The model ignores a rule, or you are not sure what is wrong. Start with a clearer prompt.
Then work in order of cost: a clearer prompt, then retrieval, then fine-tuning. Each step costs more than the one before, and each one often turns out to be enough.
Using retrieval and fine-tuning together
The two tools do not compete. Many products use both, and each one does the job it is good at.
Take a support team that wants an assistant to explain its refund policy in a calm, consistent voice. The policy changes every few months, so the facts belong in retrieval. The voice never changes, so a small fine-tune on a few hundred approved replies can lock it in. Retrieval keeps the answers current. Fine-tuning keeps them sounding like the team.
Which fix fits this problem?
Your assistant gives correct shipping information, but it replies in long chatty paragraphs. Your app needs exactly three short bullet points every time.
The facts are right, so nothing is missing. The behaviour is wrong, and that is what fine-tuning on example replies is good at changing.
How should the assistant stay current?
Your pricing page changes every Monday, and the assistant must always quote the current prices.
Facts that change belong in documents, not in weights. With retrieval, updating the page updates the next answer, with no training run.
What should you try first?
Your assistant sometimes ignores your rule to never promise a delivery date. The rule is one short line near the end of a long prompt, and you have not tried anything else yet.
A prompt change costs nothing and often solves the problem. Retrieval and fine-tuning cost more, so try them only after a clearer prompt has failed.
Your reading position is saved
0 of 36 complete
Lesson complete
RAG or fine-tuning?
Up next