RAG vs Fine-Tuning: Which One Your Task Actually Needs
You are about to fine-tune a model on your documents, and there is a good chance that is the wrong job. Fine-tuning teaches a model how to behave. It does not reliably teach it what your documents say. This is the companion tutorial to Train Your Own AI, Episode 4: the honest test that separates knowledge problems from behavior problems, and verified builds for both sides on a single 24 GB GPU.
The core distinction: knowledge vs behavior
Knowledge is facts: your prices, your policies, your product specs, what changed last Tuesday. Behavior is patterns: tone, format, structure, the shape of a good answer.
Fine-tuning changes behavior. It rewires the model's defaults by training on examples, so the pattern gets baked into the weights. Retrieval-augmented generation (RAG) changes knowledge at query time. The model stays exactly as it is; before it answers, it looks up the relevant pages from your documents and answers from those pages, with sources you can check.
Think of two different exams. Fine-tuning is training an employee until the house style is instinct. RAG is handing that employee an open book: look it up, every time, and show your work. A fine-tune cannot cite a page it half-remembers. A retrieval system cannot learn your house style by looking things up.
When RAG wins: fresh, private, citable
- Your facts change. Prices move, policies update, inventory turns over. With retrieval, you swap the document and the next answer is correct. With a fine-tune, every update means another training run.
- Your facts are private. Support tickets, internal wikis, and contracts were never in the base model's training data. Retrieval puts exactly the right pages in front of the model at the moment it needs them.
- You need receipts. A retrieval answer can point at the chunk it came from. A fine-tuned answer can only say "trust me." In support and compliance, that citation is the whole product.
If your failure mode sounds like "the model does not know, knows something outdated, or invented a fact that exists in our files," that is a knowledge failure. Build retrieval first.
When fine-tuning wins: style, format, narrow tasks
- Wrong format. Free-form text where you need strict JSON or a fixed structure. Retrieved pages do not teach response shape; examples do.
- Wrong voice. Tone and style wrong on every answer, no matter what context you supply.
- High volume. Millions of short, repetitive calls (classification, routing, extraction), where a small fine-tuned model beats a big general model with a long retrieved prompt on cost and latency.
- Domain language. Jargon and document shapes so specialized that the base model keeps misreading them. Training teaches fluency that lookup never will.
If your failure mode sounds like "right facts, wrong form," that is a behavior failure. Train.
The honest test: decide in 20 questions
Take twenty real questions your system must answer, with the answers you would accept. Run them three ways:
- Base model alone, no help.
- Base model with retrieval, your documents chunked and searched.
- Read the failures, not the scores. For each remaining failure, ask: would more training examples fix this, or is the right page simply missing?
If the base model fails because it does not know your facts and retrieval fixes it, ship RAG and skip the training bill. If retrieval surfaces the right page and the model still answers in the wrong shape, that residue is your fine-tuning case, now small and well-defined. If the base model already passes, ship nothing. Run the test before you rent the GPU.
Build RAG: chunk, embed, retrieve, answer
Four steps, all comfortable alongside a 7B model on a single 24 GB GPU, because the heavy parts are tiny. Chunk at about 800 characters with 120 characters of overlap, embed with a small model (BGE small is a solid current default), index in FAISS, and answer from the top four chunks only:
pip install sentence-transformers faiss-cpu
from sentence_transformers import SentenceTransformer
import faiss, numpy as np
embed = SentenceTransformer("BAAI/bge-small-en-v1.5")
# chunk: ~800 chars, 120 overlap (step = 800 - 120)
chunks = [doc[i:i+800] for doc in docs
for i in range(0, len(doc), 680)]
vecs = embed.encode(chunks, normalize_embeddings=True)
index = faiss.IndexFlatIP(vecs.shape[1])
index.add(np.array(vecs, dtype="float32"))
# retrieve top 4, then answer from context only
q = embed.encode([question], normalize_embeddings=True)
_, hits = index.search(np.array(q, dtype="float32"), 4)
context = "\n\n".join(chunks[i] for i in hits[0])
prompt = f"Answer using ONLY this context, cite the chunk.\n{context}\n\nQ: {question}"
Quality lives and dies on two dials: chunk size, and whether the right chunk actually ranks in your top four. Tune those before you tune anything else.
Build the fine-tune: when behavior is the bug
The stack from episode 1, aimed only at behavior. Unsloth loads Qwen2.5-7B in 4-bit, PEFT attaches a rank-16 LoRA adapter, and TRL's SFT trainer runs your behavior examples:
pip install unsloth trl peft datasets
from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTConfig
model, tokenizer = FastLanguageModel.from_pretrained(
"unsloth/Qwen2.5-7B-Instruct",
max_seq_length=2048, load_in_4bit=True)
model = FastLanguageModel.get_peft_model(
model, r=16, lora_alpha=16, lora_dropout=0,
target_modules=["q_proj","k_proj","v_proj","o_proj",
"gate_proj","up_proj","down_proj"])
trainer = SFTTrainer(model=model, tokenizer=tokenizer,
train_dataset=behavior_examples, # shape, not facts
args=SFTConfig(per_device_train_batch_size=2,
gradient_accumulation_steps=4, learning_rate=2e-4,
optim="adamw_8bit", output_dir="outputs"))
trainer.train()
Notice what is not in that dataset: your documents. Do not train the model to memorize facts it can look up. Train the shape of the answer, then let retrieval supply the facts at query time. Evaluate the same twenty questions before and after: format failures should collapse while knowledge failures stay flat. That split is the proof it worked.
The hybrid, and what is next
Serious systems usually need both: fine-tune for voice and format, retrieve for facts. The combination has a name, retrieval-augmented fine-tuning (RAFT). Start with retrieval, because it is reversible and live today. Add the fine-tune only for the failures retrieval cannot touch, and prove each step on the same twenty questions.
Next in the series: DPO basics, preference-tuning after SFT, teaching your model which of two good answers is the one you actually want.
Find the cheapest GPU for your next run
Live pricing, hardware specs, and availability across 30 GPU clouds, neoclouds, and bare-metal providers.
Open the Directory