Skip to content

Guides

Fine-tuning vs RAG vs prompting

Three ways to make a language model do better on your job. They are not rungs on a ladder; they fix different problems. The quickest way to choose is to ask what is going wrong: is the model missing knowledge, or is it not behaving the way you need?

The short answer

  • Prompting first, always. It is fast to try and sets the baseline you measure everything else against.
  • RAG when the model lacks knowledge: your private documents, facts newer than its training, details it can’t be expected to know.
  • Fine-tuning when the model has what it needs but behaves inconsistently, or when you want a smaller, faster, cheaper model to do one job.
  • Combine them when you have both problems. They stack rather than compete.

Two different problems

OpenAI’s guide to LLM accuracy frames this as two separate axes. Context problems happen when the model lacks information because it was never in its training data, is out of date, or is private to you; retrieval and better prompts address them. Behavior problems happen when the model has the information but doesn’t act on it the way you need, such as the wrong format, inconsistent answers or the wrong judgment; prompting and fine-tuning address them. The guide also notes that many of OpenAI’s largest customer deployments use only prompt engineering and retrieval.

How they compare

PromptingRAGFine-tuning
What it changesThe instructions and examples sent with each callThe information sent with each call, fetched for that inputThe model’s weights
FixesUnclear instructions, missing examplesMissing, private or out-of-date knowledgeInconsistent behavior, format, tone; cost and speed via a smaller model
Time to tryMinutesDays, to build and tune retrievalHours to days, once you have examples
Data neededA few examples to put in the promptA searchable collection of your documentsDozens to thousands of input and answer pairs
Keeps knowledge currentOnly what you paste inYes: update the documents, not the modelNo: facts learned in training go stale
Cost per callRises as prompts growAdds retrieval and longer promptsCan fall a lot, with a small model and short prompts

Prompting: start here

  • Write the job down clearly: the input, the possible answers, the rules.
  • Add a few examples of good answers, including tricky cases.
  • Measure on a set of inputs with known answers, so changes are judged by results, not impressions.
  • Watch prompt length. Long-context models let prompts grow, but OpenAI’s guide cautions that models can struggle to keep attention across very large prompts, and every token is paid for on every call.

RAG: when the model needs knowledge

Retrieval-augmented generation, named in a 2020 paper from Facebook AI Research, pairs a model with a searchable store of documents: for each input, the most relevant passages are fetched and given to the model with the question. Because the knowledge lives outside the model, you can update it by updating the documents.

A RAG system can fail in two places: retrieval can fetch the wrong passages, or the model can misuse the right ones. Measure both. If retrieval is right and answers are still off, that is a behavior problem, which is where fine-tuning comes in.

Fine-tuning: when behavior is the problem

Fine-tuning trains a model on examples of inputs and the answers you want. It is the right tool for consistent format and judgment on a repeated job, and for moving that job to a small model that is cheaper and faster on every call. OpenAI’s accuracy guide fine-tunes on a dataset of 50 or more examples to raise consistency in its worked example. See how to fine-tune without an ML team, and when a small model beats a large one.

Using them together

The methods stack. A common pattern retrieves the context, then fine-tunes a model on examples that include it, so the model learns to use your documents the way you want. Another distills a large model that works well with a long prompt into a small fine-tuned one that needs only a short prompt, which cuts cost on every call. See LLM distillation explained.

A quick checklist

  1. Do you have a set of inputs with known answers to measure against? If not, build that first.
  2. Are failures caused by missing or stale knowledge? Add retrieval.
  3. Does the model have the right context but still answer inconsistently? Fine-tune.
  4. Is the job working but too slow or costly at your volume? Fine-tune a smaller model on the good answers.
  5. Is the job open-ended, with no checkable answer? Stay with prompting and a large model.

Questions people ask

Is RAG better than fine-tuning?

They fix different problems. RAG gives a model knowledge it lacks, such as your documents or recent facts. Fine-tuning changes how it behaves, such as format, consistency and judgment on a job. Many systems use both.

Should I start with prompting, RAG or fine-tuning?

Start with a prompt and a way to measure results. Add retrieval if failures come from missing knowledge, and fine-tune if a good prompt with the right context still gives inconsistent answers, or if you want a smaller, cheaper model.

Can fine-tuning teach a model new facts?

Some, but it is a poor way to keep facts current, because they are frozen at training time. Retrieval lets you update knowledge by updating documents.

Can you use RAG and fine-tuning together?

Yes. A common pattern fine-tunes a model on examples that include the retrieved context, so it learns to use that context the way you want.

Sources

Train your first model

Wrap your client and keep calling your model. Sous trains a small one on your calls and switches you over when it’s ready. Every account starts with $20 of credit, and a training that fails costs nothing.

Four steps, from your app’s calls to a small model

  1. 1Make a model and an API keyin the app
  2. 2Wrap your clientSous(OpenAI(), model=…)
  3. 3Use your app as usualSous keeps each call
  4. 4Let it switchwhen a student is ready