Lesson 1: Fine-Tune vs. RAG vs. Prompt Engineering
Navigate the decision tree: when prompting is enough, when RAG is the right answer, and when fine-tuning is genuinely necessary. Understand cost, latency, and maintainability trade-offs.
By Bishwambhar Sen • Last updated • 55 min
Fine-tuning is the right tool for fewer situations than most engineers think. Before training, you should be able to articulate exactly why prompt engineering or RAG will not solve the problem.
The Decision Framework
Ask these questions in order. Stop when you find a solution that works:
Approach Selector
Select an approach to see when it fits, what it costs, and a working code example.
Prompt Engineering
- Style or tone can be described in a system prompt
- Output format varies per request (few-shot examples cover it)
- You need to ship today — no data collection time
# Prompt engineering — zero setup cost
from openai import OpenAI
client = OpenAI()
system_prompt = """You are a product data extractor.
Always respond with valid JSON in this exact schema:
{"name": string, "price": string, "features": list[string]}
Never add commentary outside the JSON object."""
def extract_product(description: str) -> dict:
import json
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": description},
],
response_format={"type": "json_object"}, # JSON mode
)
return json.loads(response.choices[0].message.content)
result = extract_product("Sony WH-1000XM5 headphones, $349.99, 30hr battery.")
# → {"name": "Sony WH-1000XM5", "price": "$349.99", "features": ["30hr battery"]}When Fine-Tuning Is the Right Choice
You need every response in a specific JSON schema and prompt-only reliability is 85%. Fine-tuning reaches 99%.
Legal, medical, or brand tone that is too complex for a system prompt but needed on millions of requests.
Moving a 2,000-token few-shot prompt into model weights cuts inference cost by 70% at scale.
Fine-tuning does not reliably implant facts — it changes behavior, not memory. Use RAG for knowledge.
Hallucinations are a probabilistic model property. Fine-tuning on examples may reduce them slightly but won't eliminate them.
Below 200 examples, few-shot prompting usually outperforms fine-tuning. Collect more data first.
In the next lesson, we dive into how supervised fine-tuning works mechanically: what gradient updates happen, what the Alpaca data format looks like, and how the training loop differs from pre-training.