RAG vs fine-tuning vs long context: which one your use case needs
Use RAG when the model needs facts from your own documents that change often or are too large to send every time. Use long context when the material is small enough to send whole and the same set is reused, ideally with prompt caching. Use fine-tuning only to change how the model behaves, such as a fixed output format, tone or a narrow repeated task, not to add knowledge. Most production systems combine RAG with a well-written prompt and never need fine-tuning.
The three options side by side
| RAG | Fine-tuning | Long context | |
|---|---|---|---|
| What it does | Finds the passages in your documents that answer the question and adds them to the prompt | Trains a model further on your examples so it behaves differently | Puts all the material into the prompt on every call |
| Good for | Large or changing knowledge: policies, product documents, tickets, contracts | Fixed output formats, tone, classification and other narrow, repeated tasks | A small, fixed set of documents, or one long file analysed at a time |
| Keeping facts current | Update the documents and the index. No retraining | Retrain to change anything | Send the new version |
| Showing sources | Easy. You know which passages were used | No. The model cannot show where an answer came from | Possible if you ask the model to quote |
| Per-user access | Filter retrieved passages by the user's permissions | None. Anything trained in can reach any user | You choose what to send for each user |
| Main cost | Building and running the index, plus short prompts | Training runs, then the tuned model's price or hosting | Large prompts on every call. Caching cuts the cost of repeats |
| Main risk | Poor retrieval returns the wrong passages | Learns style but not reliable facts, and goes stale | Accuracy drops as input grows. Slow and costly at volume |
Start from your situation
| If your situation is | Start with | Why |
|---|---|---|
| Answers must come from internal documents that change often | RAG | You update documents without retraining anything |
| Different users may see different documents | RAG with permission filters | Neither fine-tuning nor a long prompt enforces access per user on its own |
| You have thousands of documents | RAG | They will not fit in any context window |
| Answers must show their source for audit | RAG | Every answer traces back to the passages used |
| You analyse one long contract, report or codebase at a time | Long context | A few calls, and no index to build |
| The same reference text is used in every call | Long context with prompt caching | Cached input costs a fraction of normal input |
| Output must follow a strict format or fixed labels, and a good prompt is not consistent enough | Fine-tuning | Changing behaviour is what fine-tuning is for |
Why fine-tuning is rarely the way to add knowledge
Fine-tuning changes how a model behaves. It is a poor way to teach it facts. A Microsoft research team compared the two on knowledge-heavy tasks and found that RAG consistently outperformed fine-tuning, both for facts the model had seen in training and for new ones. The same study found that models struggle to learn new facts through fine-tuning.
Vendor guidance draws the same line. OpenAI separates problems of missing, outdated or proprietary knowledge, which need better context, from problems of format, tone and consistency, which need changes to the model. Microsoft's Azure OpenAI guidance says to start with RAG when you want to add knowledge from outside the model's domain.
Fine-tuning also has an upkeep cost. When the base model is updated or retired, you train again.
Why a bigger context window does not replace RAG
Context windows are now very large. Google's documentation describes Gemini models with windows of 1 million tokens or more. Size is not the same as reliable use:
- A study published in 2024 found that models answer best when the relevant information sits at the start or end of the input, and noticeably worse when it sits in the middle.
- Chroma tested 18 models in July 2025 and found that performance became less reliable as input length grew, even on simple tasks.
- Every call pays for every token sent, and long prompts take longer to process.
- A long prompt has no access control. Whatever you send, the model can repeat to that user.
Long context works well when the material is small, fixed and reused. Send what the question needs, not everything you have.
What each option costs to run
Prices change often, so compare how each option is charged, not list prices.
- RAG: embedding your documents, storing them in a vector or search index, and a short prompt per question. Cost grows mainly with the number of questions.
- Long context: you pay for the full input on every call. Caching helps when the same text repeats. On Anthropic's API, reading from the cache costs 10% of the normal input price on most models, and Google recommends context caching for repeated long inputs.
- Fine-tuning: data preparation and training runs, then the tuned model's price or hosting, and retraining when the base model changes.
A five-question test before you build
- Does the material fit comfortably in one prompt? If not, use RAG.
- How often does it change? Weekly or faster points to RAG.
- Must answers show their sources? Then use RAG.
- Do users have different access rights? Then use RAG with permission filters.
- Is the problem what the model knows, or how it answers? Knowledge points to RAG or long context. Behaviour points to better prompts first, then fine-tuning.
Whatever you choose, build an evaluation set from real questions first and agree the pass bar before you build. It is the only way to tell whether a change helped. Pilots that skip this step tend to stall, as we explain in why AI pilots stall before production.
Using them together
Most production systems combine them. A common order:
- Start with a clear prompt and RAG over your documents.
- Cache the fixed parts of the prompt, such as instructions and policy text.
- Fine-tune a small model later for one narrow step, such as classifying requests or producing a strict format, once your evaluation shows prompting is not enough.
When the knowledge lives in a live system rather than in documents, such as a CRM, ERP or ticketing tool, connect the model to that system instead of copying the data into an index. See MCP server development.
How AMT can help
- To build retrieval over your documents with access control, see RAG development.
- For assistants, summarisation and content generation on your data, see generative AI development.
- To add AI features to an existing product, see AI product engineering.
- If you have a pilot that works in a demo but not in production, see AI pilot to production.
- For a RAG chatbot we built, see the conversational AI product case study.
- To add AI engineers to your team, see hire AI engineers.
FAQ
Is RAG better than fine-tuning?
Does a 1 million token context window make RAG unnecessary?
Can I use RAG and fine-tuning together?
How much data do I need to fine-tune?
Sources
- Ovadia et al., Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs, EMNLP 2024
- Liu et al., Lost in the Middle: How Language Models Use Long Contexts, TACL 2024
- Chroma, Context Rot: How Increasing Input Tokens Impacts LLM Performance, July 2025
- OpenAI: Optimizing LLM accuracy
- Microsoft Learn: When to use Azure OpenAI fine-tuning
- Google: Gemini API long context
- Anthropic: Claude API pricing, prompt caching
Tell us what your AI system needs to know, how often it changes and who uses it.