Every enterprise AI project eventually hits the same question: should we retrieve our knowledge at query time, or train it into the model?
The honest answer is that they solve different problems. Retrieval-augmented generation (RAG) gives a model access to facts it was never trained on. Fine-tuning changes how a model behaves: its tone, format and judgement on a narrow task. Confusing the two is the most expensive mistake we see in AI roadmaps.
What each approach actually does
RAG searches your documents for the passages most relevant to a question, then asks the model to answer using only those passages. Fine-tuning continues training a model on examples of the inputs and outputs you want, so the behaviour is baked into its weights.
| RAG | Fine-tuning | |
|---|---|---|
| Knowledge freshness | Update a document, and answers change immediately | Requires retraining to learn new facts |
| Citations | Natural: every answer can link its sources | Hard: knowledge is diffused in weights |
| Access control | Filter retrieval by user permissions | Not possible per user |
| Cost to change | Low: re-index changed documents | Higher: new dataset, training run, evaluation |
| Best for | Policies, product docs, contracts, support knowledge | Tone, structured outputs, classification, domain style |
When RAG wins
- Your knowledge changes weekly or daily: pricing, policies, inventory, tickets.
- Answers must be auditable. Regulated teams need to see exactly which clause an answer came from.
- Different users may see different data. Retrieval can enforce the same permissions as your document system.
- You want to start this month. A solid RAG pilot needs your documents, not a labelled training set.
When fine-tuning wins
- You need a strict output format, such as a JSON schema or a report layout, every single time.
- The task is narrow and repetitive: classifying tickets, extracting fields, routing documents.
- You want a smaller, cheaper model to match a larger one on that one task, at high volume.
- You already have thousands of high-quality examples of the behaviour you want.
A production RAG pipeline, simplified
The core loop is small. What makes it production-grade is everything around it: chunking strategy, permission filters, evaluation and monitoring. Here is the heart of an answer endpoint using PostgreSQL with pgvector:
# Retrieve the most relevant chunks, then answer with citations
import psycopg
from openai import OpenAI
client = OpenAI()
def answer(question: str, user_id: str, k: int = 5) -> dict:
q_vec = client.embeddings.create(
model="text-embedding-3-small", input=question
).data[0].embedding
with psycopg.connect(DB_URL) as conn:
rows = conn.execute(
"SELECT id, title, chunk FROM docs "
"WHERE %s = ANY(allowed_users) " # permission filter
"ORDER BY embedding <=> %s::vector LIMIT %s",
(user_id, q_vec, k),
).fetchall()
context = "\n\n".join(f"[{r[0]}] {r[2]}" for r in rows)
reply = client.chat.completions.create(
model="[MODEL]",
messages=[
{"role": "system", "content": "Answer only from the context. Cite sources as [id]. Say 'I don't know' if unsure."},
{"role": "user", "content": f"{context}\n\nQuestion: {question}"},
],
)
return {"answer": reply.choices[0].message.content,
"sources": [r[1] for r in rows]}Model names are placeholders; we pick the model per project after evaluation. The same pattern works with Claude, Gemini or an open model.
Evaluate before you ship
Whichever approach you choose, build a golden dataset of 50 to 200 real questions with approved answers before launch. Grade every change against it: retrieval hit rate, answer faithfulness to sources, and refusal behaviour when the answer isn’t in the documents.
If you can’t measure whether an answer is right, you can’t tell whether fine-tuning helped.
The hybrid we usually recommend
Start with RAG to ground answers in your current, permissioned knowledge. Once you have production logs, look for repeated failures of behaviour, not knowledge: wrong format, wrong tone, poor routing. That is where a small, targeted fine-tune pays for itself.
- RAG adds knowledge; fine-tuning shapes behaviour.
- Choose RAG for fresh, cited or permissioned information.
- Choose fine-tuning for strict formats and narrow, high-volume tasks.
- Build an evaluation set before you build either.