RAG vs fine-tuning: Choose the Right System for Work
A practical RAG vs fine-tuning decision guide that covers retrieval quality, retraining costs, and when a prompt with structured extraction is enough.
The model answers 38 support questions cleanly, then on question 39 it invents a refund policy. That's where a prototype turns into engineering work, and choosing between RAG, fine-tuning, or a tighter prompt decides what kind of maintenance you're signing up for.
I haven't shipped a production RAG pipeline or a fine-tuned model myself, so this is a reasoned engineering guide grounded in related work where I had to constrain what a model extraction was allowed to claim. RAG changes the evidence a model sees at request time, fine-tuning changes behaviour through examples, and a narrow prompt with structured extraction changes neither while bounding the job enough for a general model to stay reliable.
Collect the failed requests before picking an architecture
Naming an architecture before diagnosing the failure wastes weeks, so start by logging five to twenty real bad requests with the user input, the available sources, the expected answer, the actual output, and the reason it broke. Saying "the model hallucinated" hides whether the right policy was missing, buried in noisy chunks, or ignored by a loose output schema.
A wrong claim about current refund rules is a context problem because you can't fine-tune every paragraph a legal team edits on a Tuesday; you retrieve the active policy, show the passage, and refuse when no source exists. If the model saw the right paragraph and still returned prose instead of a discriminated JSON object, the output contract failed. If the user typed "chicken wrap, chips, maybe a sauce", the task needs a bounded calorie estimate in a strict schema, without a private document index anywhere in sight.
Retrieval is for evidence that changes and needs a trail
RAG earns its keep when answers depend on material that is too large, private, or changeable to paste into every prompt, such as employee handbooks, billing rules, contract clauses, runbooks, or account records. It hands the model a packet of current evidence and lets the user inspect the citation, which a fine-tune can't do because learned weights hold statistical associations with no revision date.
A vector database still needs strict source boundaries: record which folders, pages, and database rows are allowed in, who owns them, and which version wins when two documents conflict, because semantic similarity won't separate a retired handbook from this month's policy. Extraction breaks silently too when PDFs duplicate headers, scramble columns, detach qualifying footnotes, or hide scanned pages behind missing OCR. Chunking carries the same risk: a 150-word chunk drops the exception two paragraphs down, while a 2,000-word chunk dilutes the match with unrelated text, so split along the document's own sections and test queries that rely on qualifiers.
Evaluate retrieval separately from generation by labelling the passages that support each test question, measuring recall at $k$ and precision, checking whether the citation actually supports the claim, and verifying that the model abstains when sources are missing.
An index needs updates after the first import
The first ingestion pass is easy; keeping the index accurate after someone edits a policy, deletes a page, or moves a folder is the real work. Use a scheduled crawl with content hashes, a webhook, or a database outbox event in the same transaction, and track the source ID, content hash, retrieval timestamp, chunking version, embedding model version, and access rules so any disputed answer can be reconstructed later.
Permissions make broad internal assistants much more expensive than their prototypes, because filtering after retrieval is already too late once restricted HR text hits a prompt or log; the permission predicate belongs in the retrieval query or index partition. Plan for weak search too, since a similarity score isn't a truth meter, and an empty or low-confidence result should show the search terms, link to candidate documents, or route to a person instead of polishing a guess.
Fine-tuning is for repeated behaviour you can show in examples
Fine-tuning makes sense when the base model already has the right context yet consistently misses a stable behavioural target you can demonstrate with clean examples, such as a fixed taxonomy, a house writing style, a predictable tool-call sequence, or compact output formatting. It's the wrong tool for weekly-changing knowledge because training lags behind live edits and strips away citations.
Before training, collect real examples, deduplicate them, and split training, validation, and held-out sets by failure mode instead of a random shuffle that leaks near-duplicates across splits. Compare against a prompt baseline on the same held-out cases; a fine-tune has to move a real product metric like schema validity, classification error, human correction time, or cost at scale. Remember that retraining isn't just a compute job: it means curating examples, scrubbing sensitive data, evaluating, registering, rolling out, and maintaining a rollback path whenever categories or user phrasing shift. Never fine-tune just to get valid JSON when strict schema outputs and application-level validation already solve syntax.
A narrow prompt and structured extraction often win
The closest production system I've shipped is a nutrition tracking app whose AI path uses neither RAG nor fine-tuning. Its text route sends a meal description to an OpenAI-compatible chat-completions endpoint running gpt-4o-mini with strict JSON Schema, extra properties disallowed, and temperature 0.3, returning calories, protein, carbohydrates, fat, and itemised rows for the iOS client to display and save only after the user confirms. Barcode scans skip the model entirely and read published fields from Open Food Facts.
Around that call sit availability and cost controls: a 25-second timeout, 100 daily requests for attested devices and 10 for unattested callers, and 1 MiB JPEG compression before upload. What the shipped Worker still lacks are independent nutritional plausibility bounds, item-total reconciliation, a committed eval set, and token telemetry; I'd fix the prompt and extraction contract long before reaching for retrieval or training.
Build in order:
- Name the decision or action the system supports.
- Collect a small evaluation set that includes cases where the system must decline.
- Pass known facts directly into a prompt with strict structured output.
- Add retrieval only when you need external, changing, or private evidence, and evaluate retrieval on its own.
- Fine-tune only after a prompt baseline fails a stable, measurable behavioural requirement with clean examples ready.
For the runtime controls around the API call itself, see the OpenAI API integration checklist, and for keeping automated changes honest with runnable specifications, read tests as contracts for AI agents.