Fine-Tuning vs RAG vs Prompting: Choosing the Right Tool
From the course Fine-Tuning and Customizing Open-Source LLMs: LoRA, QLoRA and Self-Hosting
Built-in AI Professor Exclusive
Ask anything about the lesson and get an instant answer. The AI Professor knows the course content and helps you learn more effectively.
Before you touch a single line of training code, you need to answer a deceptively simple question: does your problem actually require fine-tuning at all? A large share of "we need a custom model" requests are solved faster, cheaper, and with less operational risk by better prompting or by retrieval-augmented generation (RAG). Fine-tuning is powerful, but it is also the option with the highest ongoing cost in engineering time, data curation, and maintenance. This lesson gives you a decision framework so you deploy the right tool for the right job.
The three techniques, precisely defined
Prompting (including few-shot examples and structured system prompts) changes model behavior purely through the input context. You do not modify any weights. You steer the model with instructions, examples, output-format specifications, and role framing. It is instant to iterate on and requires zero training infrastructure.
RAG (retrieval-augmented generation) adds an external knowledge source at inference time. You embed your documents into a vector store, retrieve the most relevant chunks for a given query, and inject them into the prompt. The model reasons over facts it was never trained on. RAG is the standard answer to "the model does not know my private or fresh data."
Fine-tuning updates the model weights (fully, or with parameter-efficient adapters such as LoRA) on your own examples. It changes the model's behavior and style durably: tone, formatting conventions, a domain-specific reasoning pattern, a niche output schema, or a language/register the base model handles poorly. It does not, by itself, reliably teach new facts.
The mental model that resolves most debates
Use this heuristic:
- Prompting changes how you ask.
- RAG changes what the model can see.
- Fine-tuning changes how the model behaves by default.
A frequent and expensive mistake is trying to fine-tune facts into a model. If your requirement is "the assistant must answer questions about our 4,000-page internal policy handbook and stay current as it changes weekly," that is a RAG problem, not a fine-tuning problem. Fine-tuning on those documents will produce a model that confidently paraphrases and hallucinates, and every handbook update would force a retrain. RAG lets you update the knowledge base by re-indexing, with no training at all.
Conversely, if your requirement is "every response must follow our strict clinical-note format, in a terse professional register, even under adversarial input," prompting may get you 90% of the way but drift on edge cases. Fine-tuning bakes the behavior in so you no longer spend hundreds of tokens per request re-teaching format, which also cuts latency and cost per call.
Comparison table
| Dimension | Prompting | RAG | Fine-tuning |
|---|---|---|---|
| Changes weights? | No | No | Yes |
| Teaches new/fresh facts | Weakly | Strongly | Poorly |
| Teaches style/format/behavior | Moderately | Weakly | Strongly |
| Time to first result | Minutes | Hours to days | Days to weeks |
| Upfront cost | Very low | Medium | High |
| Per-request token cost | High (long prompts) | High (retrieved context) | Low (behavior is internal) |
| Inference latency | Higher (long context) | Higher (retrieval + context) | Lower |
| Freshness / update speed | Instant | Fast (re-index) | Slow (retrain) |
| Data needed | A few examples | A document corpus | Curated example pairs |
| Best at | Quick steering, prototyping | Grounded factual answers | Consistent behavior, niche tasks |
Cost, latency, and freshness trade-offs
The token economics matter more than people expect. If you rely on a 1,500-token system prompt with ten few-shot examples on every call, you pay for those tokens on every request forever, and they inflate latency. Fine-tuning can move that behavior into the weights, shrinking prompts dramatically. Over millions of requests, the training cost amortizes quickly. This is a classic reason to fine-tune even when prompting "works."
Freshness is the mirror-image argument. RAG wins decisively when data changes often, because updating the index is cheap and immediate. A fine-tuned model freezes knowledge at training time; the moment your facts change, the model is stale and possibly wrong. Never fine-tune volatile facts.
Latency has three contributors here: prompt length (prompting and RAG inflate it), retrieval round-trips (RAG only), and model size. Self-hosting a smaller fine-tuned open model can beat a large general model on both latency and unit cost for a narrow task.
Combining them (the usual production answer)
These techniques are not mutually exclusive; strong systems combine all three. A common, robust architecture is: fine-tune a compact open model so it reliably produces your output format and domain tone and calls tools correctly; use RAG to feed it fresh, private facts at inference; and keep a lean system prompt for final guardrails and per-request instructions. Fine-tuning reduces prompt length and improves format adherence; RAG supplies grounded facts; prompting handles the last mile.
Measure before and after, always
None of these decisions should be made on intuition alone. Build a small, representative evaluation set of real inputs with known-good outputs before you change anything, and score your current baseline on it. Then, when you try improved prompting, add RAG, or fine-tune, re-score against the same set and compare. Without this discipline you cannot tell whether a change helped, hurt, or merely shifted the failure modes. A common trap is to "feel" that a fine-tune improved quality while an honest evaluation shows regression on cases the base model handled fine, a symptom of overfitting to your narrow training distribution or of catastrophic forgetting of general capability.
A worked example and common anti-patterns
Consider a support assistant that must answer product questions in a fixed JSON envelope. The knowledge (product specs, prices) changes weekly, so those facts belong in RAG. The strict envelope, the terse tone, and the refusal behavior on out-of-scope questions are stable, so they are fine-tuning candidates once prompting proves inconsistent under load. The anti-pattern is the reverse: teams often try to fine-tune the product catalog into the weights (guaranteeing stale, hallucinated prices) while relying on a fragile prompt to enforce the JSON envelope on every call. Matching each requirement to the right technique is the whole game. A second frequent anti-pattern is jumping straight to fine-tuning to avoid the "effort" of prompt engineering, only to discover that the same weak prompt now sits underneath an expensive, hard-to-update model.
Decision checklist
Work through this in order and stop at the first honest "yes":
- Have you exhausted prompting? Rewrite the system prompt, add few-shot examples, specify the output schema explicitly. If quality is now acceptable, ship it. Do not fine-tune yet.
- Is the gap about knowledge the model lacks (private, proprietary, or fresh facts)? Use RAG. Do not fine-tune.
- Does the knowledge change frequently? Strongly favor RAG; fine-tuning would go stale.
- Is the gap about consistent behavior, style, format, tone, or a narrow skill the base model does inconsistently? This is where fine-tuning earns its cost.
- Are per-request prompt tokens or latency a real business cost at your volume? Fine-tuning to shorten prompts can pay for itself.
- Do you have (or can you build) at least a few hundred high-quality, consistent examples? If not, you are not ready to fine-tune; fix the data first.
- Can you commit to maintenance (re-training as requirements evolve, evaluation, versioning)? If not, prefer RAG/prompting.
If you reach step 4 or 5 with a "yes," fine-tuning is likely justified. Everything that follows in this course assumes you have honestly worked through this checklist and concluded that adapting the weights is the right investment.
Sequencing the three techniques in a greenfield project
When you start a new AI feature, resist the urge to pick a technique on day one. Sequence them so each decision is informed by evidence:
- Week 1 — prompt baseline. Write the best system prompt you can, add few-shot examples, specify the output schema, and score it on your 20-example eval set. This is now your baseline; you will compare everything against it.
- Week 1-2 — add retrieval if the failures are knowledge-shaped. If the errors are "the model does not know our facts," stand up a minimal RAG pipeline and re-score. If retrieval closes the gap, you may be done — no training required.
- Week 2-3 — consider fine-tuning only for residual behavior gaps. If, after good prompting and retrieval, the remaining failures are about format, tone, consistency, or a narrow skill, and the volume justifies it, gather examples and run a cheap LoRA. Re-score against the same set.
The discipline is that each step is cheap relative to the next, and each is validated before you escalate. Teams that invert this order — fine-tuning first, prompting last — routinely spend weeks training a model to do something a better prompt would have solved in an afternoon, and they end up maintaining an expensive artifact they did not need. The sequence protects both your time and your budget, and it produces a written trail of evidence you can show stakeholders when they ask why you chose the approach you did.
Token economics: a worked example
Intuition about "prompting is cheap" breaks down at volume, so make the arithmetic explicit. Suppose a classification endpoint uses a system prompt of roughly 1,500 tokens (detailed instructions plus twelve few-shot examples) and the user turn adds another 200 tokens. Every single call therefore pays to process about 1,700 input tokens before the model emits its short answer. At one million calls per month, that is 1.7 billion input tokens just to re-teach the model what it should already know by default.
Now fine-tune a compact open model so the behavior lives in the weights. The system prompt collapses to perhaps 150 tokens of guardrails, and the few-shot block disappears entirely. You now process roughly 350 input tokens per call instead of 1,700 — a reduction of about 80% on the dominant cost driver, plus lower latency because the model reads far less context. The one-time training cost (a few GPU-hours for a QLoRA run) is trivially amortized against 1.7 billion tokens per month. This is the canonical "prompting works but fine-tuning is still correct" situation: the deciding factor is not capability but recurring unit economics at scale.
Two cautions keep this honest. First, this only pays off when volume is high and the behavior is stable; for a low-traffic internal tool, the engineering and maintenance cost of a fine-tune outweighs the token savings. Second, always verify current per-token pricing at the provider or your own infrastructure cost — do not treat any specific number here as a live quote; treat the structure of the calculation as the transferable skill.
Three extended scenarios and the right call
Scenario A — Clinical note formatter. A hospital wants dictated notes reshaped into a rigid SOAP structure with a controlled vocabulary and a terse register, and the behavior must hold even on messy, adversarial input. The knowledge (medical facts) already lives in the base model and in retrieved guidelines; the gap is durable formatting behavior. Verdict: prompt first, and if edge-case drift persists under load, fine-tune the format. Keep RAG for the guideline citations that change.
Scenario B — Internal policy chatbot. Employees ask questions over a 4,000-page handbook that legal revises weekly. The gap is fresh, private knowledge, not behavior. Verdict: RAG, unambiguously. Fine-tuning here would freeze last week's policy into the weights and hallucinate confidently. If, additionally, you want a specific answer format and refusal style, a light fine-tune can sit on top of RAG — behavior in the weights, facts in the context.
Scenario C — High-volume support triage. A model routes millions of tickets into 40 categories and drafts a first reply in a fixed JSON envelope. Categories and tone are stable; product facts change. Verdict: fine-tune the classification-and-envelope behavior into a small open model for cost and latency, feed current product facts via RAG, and keep a lean prompt for per-ticket instructions. This is the "combine all three" architecture in production form.
When RAG and fine-tuning genuinely conflict
Occasionally teams try to solve the same gap with both and get worse results. If you fine-tune heavily on domain documents and retrieve them, the model can start to trust its (stale, memorized) version over the retrieved (fresh) version, producing contradictions the user can spot. The clean separation of concerns avoids this: fine-tune for how to behave, retrieve for what is true right now, and never fine-tune the volatile facts you also retrieve. When behavior and knowledge are cleanly separated, the two techniques reinforce rather than fight each other.
Ready-to-use decision template
Copy this into your design doc and fill it in before writing any training code:
- Problem statement (one sentence): ______
- Is the gap knowledge or behavior? knowledge / behavior / both
- Does the knowledge change faster than monthly? yes -> RAG; no -> either
- Have we exhausted prompt + few-shot + schema? yes / no (if no, stop and do that)
- Volume per month and per-request prompt length: ______ (compute token cost)
- Do we have >= a few hundred consistent, high-quality examples? yes / no
- Can we own maintenance (retrain, eval, version)? yes / no
- Chosen approach and why (one paragraph): ______
- Baseline eval score before any change: ______
If the last two data fields are blank, you are not ready to fine-tune — you are ready to build an evaluation set and gather data.
Early-warning signals that you chose the wrong tool
Reversing a bad choice is cheap early and expensive late, so learn the signals:
| Symptom in production | Likely wrong choice | Corrective move |
|---|---|---|
| Answers cite outdated facts weeks after a source changed | Facts baked via fine-tuning | Move facts to RAG; retrain only behavior |
| Format breaks under unusual or adversarial input | Relying on prompt alone for critical format | Fine-tune the format; keep prompt for guardrails |
| Latency and bill dominated by huge system prompts at scale | Over-reliance on prompting | Fine-tune to shorten prompts |
| Model contradicts the retrieved context | Fine-tuned on the same volatile documents you retrieve | Stop fine-tuning those facts; trust retrieval |
| Every requirement change needs a retrain | Behavior and knowledge fused into weights | Separate concerns: RAG for knowledge, weights for behavior |
The pattern is consistent: when weights and knowledge are entangled you get stale, contradictory, expensive systems; when they are cleanly separated each layer stays cheap to update. Diagnose by asking a single question about any failure — "is this a knowledge problem or a behavior problem?" — and route the fix to the matching layer.
Common mistakes recap
- Fine-tuning to inject facts (produces confident hallucination and forces retrains).
- Skipping prompt engineering because fine-tuning "feels" more serious, then discovering the weak prompt now sits under an expensive model.
- Fine-tuning volatile data that goes stale within days.
- Changing prompting, RAG, and weights at once so you cannot attribute which move helped.
- Never building a baseline eval, then "feeling" that quality improved while it silently regressed.
Mini-lab
Take one real task from your own backlog. Write its one-sentence problem statement, classify the gap as knowledge or behavior, and predict the right technique using the checklist — before reading ahead. Assemble twenty representative inputs with known-good outputs as a first evaluation set. You will reuse this exact set at the end of the course to prove whether your fine-tune actually helped. Everything that follows assumes you have honestly worked through this framework and concluded that adapting the weights is the right investment.
**[Easy]** Which technique modifies the model's weights?
Enjoyed it? All 30 lessons look like this.
You just read a complete lesson, exactly as it appears in the platform. Create your account in under a minute and pick the option that fits you best:
Up next in the course
Unlock all 30 lessonsEverything you'll learn in this course
1 When to Fine-Tune: Foundations & Decision Framework 3 lessons
- Fine-Tuning vs RAG vs Prompting: Choosing the Right Tool Reading now 50 min
- Anatomy of an Open-Source LLM 52 min
- The Open-Source Licensing Landscape 48 min
2 Data: The Foundation of Fine-Tuning 3 lessons
- Dataset Design: Formats, Structure, and Chat Templates 52 min
- Data Quality, Curation, and Synthetic Data 51 min
- Legal and Ethical Fine-Tuning Data 50 min
3 Parameter-Efficient Fine-Tuning (PEFT): LoRA 3 lessons
- How LoRA Works: Low-Rank Adaptation Explained 52 min
- LoRA Hyperparameters: Rank, Alpha, Target Modules, Dropout 51 min
- Full Fine-Tuning vs PEFT: Trade-offs 48 min
4 QLoRA and Quantized Training 3 lessons
- Quantization Fundamentals and bitsandbytes 50 min
- QLoRA in Practice: Fine-Tuning on a Single GPU 52 min
- Memory Math: VRAM Budgeting for Training 49 min
5 The Fine-Tuning Toolchain 3 lessons
- Hugging Face Stack: transformers, PEFT, and TRL 51 min
- Unsloth: Faster, Memory-Efficient Fine-Tuning 49 min
- Axolotl: Config-Driven Fine-Tuning at Scale 50 min
6 Instruction Tuning & Alignment 4 lessons
- Supervised Fine-Tuning and Chat Templates 52 min
- Preference Optimization: DPO and Beyond 51 min
- Common Pitfalls: Catastrophic Forgetting and Overfitting 49 min
- Reinforcement Fine-Tuning: RLHF, GRPO, and Verifiable Rewards 50 min
7 Evaluation and Quantization for Inference 3 lessons
- Evaluating a Fine-Tuned Model 51 min
- Inference Quantization: GGUF, GPTQ, and AWQ 51 min
- Merging Adapters and Exporting Models 48 min
8 Self-Hosting and Serving 4 lessons
- Ollama: Local Serving Made Simple 49 min
- vLLM: High-Throughput Production Serving 51 min
- TGI and Choosing a Serving Stack 49 min
- Serving Many Adapters: Multi-LoRA and Multi-Tenant Inference 50 min
9 Production, Cost, and Case Studies 3 lessons
- Cost and Hardware Planning 51 min
- Deploying to Production: Monitoring, Scaling, and Safety 52 min
- Case Studies: Real-World Fine-Tuning Projects 50 min
10 Final Quiz — Fine-Tuning Open-Source LLMs 1 lessons
- Final Assessment — Fine-Tuning and Customizing Open-Source LLMs 50 min
Everything you need to learn effectively
Interactive quizzes
Check your knowledge at the end of every lesson with scored quizzes and feedback.
Personal notes
Save notes on every lesson, accessible anytime from your dashboard.
Scheduled reviews
Revisit lessons exactly when it matters, at the right intervals — so you remember for the long term.
Progress & Achievements
Track your progress, unlock achievements, and visualize what you've learned.
Bookmarks
Save the lessons that matter and find them instantly when you need them.
Questions & Answers
Ask questions right on the lesson and get answers from our team.
Good to know before you start
How do I get access to the course?
You can read the first lesson in full for free, right on this page — no account needed. For the rest of the course you create an account, pick the subscription that fits — a single course or a bundle — and get access immediately after your payment is confirmed. Everything happens 100% online.
Can I cancel my subscription anytime?
Yes. Cancel anytime, straight from your account, in just a few clicks. Your access stays active until the end of the period you have already paid for.
What does the subscription for this course include?
All 30 lessons in the course, interactive quizzes, the AI professor built into every lesson (select any passage and it explains it on the spot), personal notes, automatically saved progress, and content updates included.
Is there a fixed learning schedule?
No. You learn at your own pace, on any device. Lessons are structured step by step, and the platform saves your progress automatically, so you can pick up right where you left off — anytime.
Ready to unlock all the content?
Just this course — €49 + VAT / month — or every IT Pro course, with smart quizzes and the full AI Professor, in the bundle at €399 + VAT / month.
