Skip to content
AGI Fans

RAG vs fine-tuning vs long context

Three ways to give an AI model knowledge it was not trained on: put it in the prompt, retrieve it on demand (RAG), or fine-tune the model. When each one fits.

Updated · 5 min read · How guides are written

A language model knows only what was in its training data, up to its cutoff date. It has never seen your company’s documents, yesterday’s news or your notes. There are three ways to fix that, and they are often confused:

  1. Long context: paste the material into the prompt.
  2. RAG (retrieval-augmented generation): search your material for the relevant parts and put only those into the prompt.
  3. Fine-tuning: train the model further on your material so it changes the model itself.

The short version: use the first when the material is small, the second when it is large or changes often, and the third when you want to change how the model behaves, not what it knows.

At a glance

Long contextRAGFine-tuning
What it doesPuts all the material in the promptFinds relevant passages, puts those in the promptAdjusts the model’s weights with extra training
Best whenThe material fits in the context windowThe material is large, or changes oftenYou need a consistent style, format or narrow skill
Updating the knowledgeEdit the textUpdate the document collectionTrain again
Can point to its sourcesYesYesNo
Effort to set upAlmost noneModerate: a search system to build and tuneHigh: training data, training runs, evaluation
Cost patternEvery request pays for all the tokensSmall prompts; the search system has running costsTraining cost up front; ordinary requests after

Long context: just put it in the prompt

The simplest approach is the one people overlook. If your material fits in the model’s context window, include it. The model reads everything, so nothing relevant can be missed by a search step.

Anthropic makes this point in its write-up on contextual retrieval: if a knowledge base is smaller than 200,000 tokens, about 500 pages, “you can just include the entire knowledge base in the prompt that you give the model, with no need for RAG or similar methods.”

Two limits apply. You pay for every token on every request, although prompt caching reduces that when the material stays the same. And models do not use very long inputs evenly: accuracy can drop as the input grows. Tokens and context windows covers both.

RAG: look it up first

When the material is too large to paste in, or changes daily, the system retrieves before it generates. The term comes from a 2020 paper by researchers at Facebook AI Research and others, which combined a language model with a searchable index of Wikipedia.

A typical setup works like this:

  1. Prepare. Documents are split into chunks. Each chunk is converted into an embedding, a list of numbers that represents its meaning, and stored in a vector database.
  2. Retrieve. When a question arrives, it is converted the same way, and the system finds the chunks whose embeddings are closest in meaning. Good systems combine this with ordinary keyword search.
  3. Generate. The retrieved chunks are placed in the prompt with the question, and the model answers from them.

What you gain: the knowledge can be huge and can change at any time without touching the model, and the answer can cite the passages it used.

What goes wrong is nearly always retrieval. If the right passage is not found, the model cannot use it, and may answer confidently from the wrong one. Most of the engineering in a RAG system goes into chunking, search quality and re-ranking, not into the model.

Web search in a chat app is the same idea, with a search engine as the retriever.

Fine-tuning: change the model

Fine-tuning continues a model’s training on your own examples, so its weights shift toward the behaviour you want. It is how a general model becomes one that always answers in your house style, follows a particular output format, or handles a specialised task well.

Training every weight of a large model is expensive. A method called LoRA, from a 2021 Microsoft paper, made it practical: it freezes the original weights and trains a small set of additional ones, cutting the cost dramatically. Most fine-tuning of open models now works this way, and the small add-on files it produces are themselves called LoRAs.

Fine-tuning is the wrong tool for facts. A fine-tuned model cannot cite where something came from, cannot be updated without retraining, and may blend what it was taught with what it already believed. It also needs good training examples, which are usually the hardest part to obtain.

With hosted models, fine-tuning is offered for some models and not others. With open-weight models you can do it on your own hardware; tools for it appear in the Releases lane.

Choosing

Ask these in order:

  1. Does the material fit in the prompt? Then put it there. Start here; it takes minutes to test.
  2. Is it too big, or does it change often? Do you need citations? Use RAG.
  3. Is the problem how the model behaves, not what it knows? Consider fine-tuning, after trying clear instructions and a few examples in the prompt, which often solve it.
  4. Still not enough? Combine them. A fine-tuned model can sit behind a RAG system. Many production systems use both.

Where agents fit

An agent blurs these categories. Instead of a fixed retrieval step, the model is given a search tool and decides for itself what to look up, reads the results, and searches again if they are not good enough. Much of what was built as RAG pipelines is moving in this direction, with the retrieval logic handed to the model.

How to read the news

  • A product that “knows your documents” is almost certainly using retrieval, not a model trained on them.
  • “Trained on your data” usually means fine-tuned, or sometimes just retrieval described loosely. Worth asking which.
  • A claim that a larger context window “kills RAG” comes around with every big window. Cost and the way models handle long inputs have kept retrieval useful so far.

For the basics of how a model uses what is in front of it, see What is an LLM?.

Common questions

What does RAG stand for?

Retrieval-augmented generation. The system first retrieves passages relevant to the question from a collection of documents, then gives them to the model to generate an answer from.

Does fine-tuning teach a model new facts?

It can, but poorly and expensively compared with the alternatives. Fine-tuning is better at changing how a model behaves, such as its format, tone or skill at a narrow task, than at giving it reliable access to specific facts.

Does RAG stop a model from making things up?

It reduces it, because the model is working from supplied text instead of memory, and the answer can cite its sources. It does not eliminate it: the wrong passages can be retrieved, and the model can still misread the right ones.