Using AI well
Fine-tuning vs RAG vs prompt engineering: which should you use?
Three ways to make an AI model do what you need: better prompts, RAG or fine-tuning. What each one changes, what it costs, when to use it, and how LoRA makes fine-tuning cheap.
Short answer
Start with prompt engineering, add when the model needs facts it doesn't have, and fine-tune only when you need to change how the model behaves. Prompting changes the instructions, RAG changes what the model can read when it answers, and fine-tuning changes the model's weights by training it on examples. LoRA is a cheap way to fine-tune that trains a small add-on instead of the whole model.
The short version
Think of a new employee. Prompting is giving them clear instructions. RAG is handing them the right binder before each question. Fine-tuning is sending them on a training course so the skill sticks.
- Prompt engineering changes: the instructions. Cost: minutes. Good for: almost everything, first.
- RAG changes: what the model reads when it answers. Cost: some setup and a search index. Good for: private, changing or citable facts.
- Fine-tuning changes: the model's weights. Cost: example data, a training run and evaluation. Good for: consistent style, strict formats, specialist tasks, smaller cheaper models.
1. Prompt engineering: always try this first
A clear prompt with a role, context, the exact output format and a couple of examples (few-shot prompting) solves more problems than people expect. It costs nothing, you can change it in seconds, and it works with any model.
Its limit: the model still only knows what it learned in training, and long, complicated prompts get expensive and fragile. Our prompt engineering guide has templates to start from.
2. RAG: when the model needs your facts
If the answer lives in documents the model has never seen, such as your product manual, last week's prices or internal policies, use retrieval-augmented generation. The system searches your documents and puts the best passages in the prompt. You can update the knowledge just by adding a file, and answers can cite their sources.
RAG doesn't teach the model new habits, though. If it writes in the wrong tone or ignores your format, more documents won't fix that. Full explanation: what is RAG.
3. Fine-tuning: when you need new behaviour
Fine-tuning continues training a model on your own examples, usually hundreds to thousands of input and ideal-output pairs. The model's parameters shift so the behaviour becomes the default, without long instructions.
Fine-tuning is worth it when you need:
- A consistent voice or format, every time, such as a strict JSON layout or a house style.
- A narrow skill done well, like classifying support tickets or extracting fields from invoices.
- A smaller, cheaper model that matches a big one on your one task. This is related to knowledge distillation.
It's a poor way to add facts. Models learn facts from fine-tuning unreliably and can mix them up, and you'd have to retrain every time something changes. It can also make a model worse at things you didn't train on, so you need an eval to check.
What is LoRA? Fine-tuning on a budget
Fully fine-tuning a model with billions of parameters needs lots of GPU memory. LoRA (low-rank adaptation, from a 2021 Microsoft paper) freezes the original model and trains a pair of small extra matrices next to some of its layers. Those adapters are often well under 1% of the model's size, so training is far cheaper and the result is a small file you can swap in and out.
QLoRA (2023) goes further: it stores the frozen model in 4-bit quantisation and trains LoRA adapters on top, which made it possible to fine-tune large models on a single GPU. The efficient fine-tuning lesson walks through both.
Using them together
These aren't rivals. A strong production system often uses all three: a fine-tuned model that reliably follows the format, RAG to supply current facts, and a carefully written prompt holding it together. Build in that order, and measure at each step whether the next one is worth it.
Key takeaways
- Prompt engineering: change the instructions. Fastest and free.
- RAG: give the model the right documents at answer time. Best for facts.
- Fine-tuning: train the model on examples. Best for style, format and narrow skills.
- LoRA and QLoRA make fine-tuning affordable on a single GPU.
Learn it properly, free
- Fine-tuning on a budget: LoRA & quantisationAdvanced 路 6 min
- RAG & AI agentsAdvanced 路 7 min
- Talking to AI: prompting wellBeginner 路 6 min
- Distillation and the rise of small modelsAdvanced 路 7 min
Terms in this post
Questions
What is the difference between fine-tuning and RAG?
RAG gives a model relevant documents to read at the moment it answers, without changing the model. Fine-tuning trains the model on examples, changing its weights so it behaves differently. RAG is better for facts; fine-tuning is better for style, format and narrow skills.
When should I fine-tune an LLM?
Fine-tune when good prompts and RAG still don't give consistent results: you need a fixed format or voice every time, a specialist task done reliably, or a smaller, cheaper model that matches a bigger one on one job.
What is LoRA in AI?
LoRA (low-rank adaptation) is a cheap way to fine-tune a large model. It freezes the original weights and trains small add-on matrices, so it needs much less memory and produces a small adapter file.
Is prompt engineering enough?
Often, yes. Clear instructions, context and a few examples solve many tasks. Add RAG when the model needs information it doesn't have, and fine-tuning only when behaviour still isn't consistent.
Sources and further reading
- LoRA: Low-Rank Adaptation of Large Language Models 路 Hu et al. (Microsoft), 2021
- QLoRA: Efficient Finetuning of Quantized LLMs 路 Dettmers et al., 2023
- Hugging Face LLM Course 路 Hugging Face 路 Free course