Comparison
RAG vs long context vs fine-tuning: how to choose
What each approach changes, what it costs, where it fails, and a practical order to try them in before you commit to one.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
You have documents, data or a particular way of working, and you want a language model to use them. There are three broad approaches: put the material in the prompt (long context), retrieve the relevant parts per question (RAG), or train the model further on your data (fine-tuning). Teams often pick one based on what they read about last. The choice is easier if you are clear about what each approach actually changes.
The short answer: put the material in the prompt if it fits and rarely changes. Use RAG when it is large, changes often, needs citations or needs per-user access. Use fine-tuning for behaviour, format or style, not for facts. Try them in that order, and let an eval on your own questions decide.
What each approach changes
Long context changes what the model sees for one request. You paste the documents in; the model reads them and answers. Nothing persists after the request.
RAG (retrieval-augmented generation) also changes what the model sees per request, but selectively. A search step picks the passages most relevant to the question and only those go into the prompt.
Fine-tuning changes the model itself. You train it further on examples, and the result is a new model version that behaves differently on every request, with no documents in the prompt.
That distinction answers most questions. If the problem is “the model does not know our facts”, you want the facts in front of it at answer time: long context or RAG. If the problem is “the model does not behave the way we need” (format, tone, a narrow classification), fine-tuning is a candidate.
Comparison
| Long context | RAG | Fine-tuning | |
|---|---|---|---|
| Best for | A small, stable set of documents | Large or changing collections; citations; per-user access | Consistent behaviour, format or style; narrow tasks at scale |
| Freshness | As fresh as what you paste | As fresh as the index | Frozen at training time |
| Citations | Possible (quote from the prompt) | Natural (each passage has a source) | Hard; the knowledge is in the weights |
| Setup effort | Lowest | Moderate: chunking, embeddings, search, evaluation | Highest: datasets, training runs, evaluation, hosting |
| Per-request cost | High if the context is large (reduced by prompt caching) | Low to moderate | Low prompts; training and possibly hosting costs |
| Access control | Whatever you choose to paste | Filter at retrieval time per user | Everyone who uses the model gets everything it learned |
| Typical failure | Detail lost in a huge context | Right passage not retrieved | Learns the style, invents the facts |
Long context: underrated for small problems
Current models accept very large inputs, up to a million tokens for several of them, and providers cache repeated prompt prefixes so the same documents are much cheaper on later requests. If your material is a handbook, a contract set or a product’s documentation that fits comfortably, putting it in the prompt is the fastest thing to try and often good enough.
Watch for two limits. Quality: recall of specific details gets less reliable as the context grows, so very long prompts can miss things that a focused prompt would catch. Cost and latency: every request pays for every token you include, even with caching.
RAG: the default for knowledge at scale
RAG is the standard approach when the corpus is too large to include, changes often, or must respect who can see what. The model only sees what retrieval returns, so the quality of the system is mostly the quality of the search: how documents are split, how chunks are embedded and ranked, whether keyword search backs up semantic search for exact terms.
Its typical failure is quiet: the right passage is not retrieved, and the model answers from whatever it got, or from general knowledge. That is why RAG systems need retrieval measured separately from answers. Our RAG fundamentals tutorial covers the pipeline, and Embeddings and vector search builds hybrid search in Postgres.
Fine-tuning: for behaviour, not facts
Fine-tuning shines when you need the model to do one thing very consistently: always produce a particular structure, classify into your categories, write in a house style, or match a larger model’s quality on a narrow task with a smaller, cheaper model. Techniques such as LoRA make it affordable to train adapters for open-weight models on modest hardware.
It is a poor way to teach facts. A fine-tuned model learns the shape of your answers more readily than their content, so it may produce confident, well-formatted answers that are wrong. It also freezes knowledge at training time, cannot cite sources, and gives every user access to everything it absorbed.
Before fine-tuning, make sure you have tried a better prompt with good examples, and structured outputs if the problem is format. Many fine-tuning projects turn out to be prompting projects.
Combining them
These are not exclusive. Common combinations:
- RAG plus long context: retrieve generously (dozens of passages rather than three) and let the model’s large window sort through them. This reduces the cost of imperfect retrieval.
- Fine-tuning plus RAG: fine-tune a model to follow your answer format and citation style, and use RAG to supply the facts.
- Long context with caching: a fixed set of reference documents at the start of every prompt, cached, plus per-question material after it.
A practical order to try them
- Prompt with the material included, if it fits. Measure quality on 20 to 50 real questions.
- Add retrieval when the material does not fit, changes too often, needs citations or needs per-user filtering. Measure retrieval hit rate and answer quality separately.
- Improve retrieval (chunking, hybrid search, reranking) before touching the model.
- Consider fine-tuning only for a behaviour problem that prompting and examples cannot fix, and only with an eval set that shows the gain.
Whatever you choose, the deciding evidence is an eval on your own questions. Architecture debates are settled faster by twenty labelled examples than by any comparison table, including this one.
Next steps
- See why stuffing the context has limits in context rot.
- Try the third option on a narrow task with fine-tune a small model with LoRA.
- Build a production-shaped version with the RAG pipeline in a day workflow.
Covers
Related
- RAG fundamentals: retrieval before generation
What RAG is and how retrieval-augmented generation works, when it beats long context or fine-tuning, and a minimal working pipeline in about 80 lines of Python.
- Embeddings and vector search, hands on
Embed documents, store them in Postgres with pgvector, index them and run similarity and hybrid search.
- RAG pipeline in a day with Postgres and pgvector
Ingest your documents, answer with citations and measure retrieval against 20 questions written first.
- Retrieval-augmented generation (RAG)
Retrieving relevant documents and adding them to the prompt before the model generates an answer from them.
- Fine-tune a small model with LoRA
Fine-tune a small open model with LoRA using TRL and PEFT, measure it on a held-out set before and after, and decide whether the gain is worth keeping.