AI and GenAI

    RAG vs fine-tuning vs long context: which one your use case needs

    Aby VargheseConversational AI ExpertPublished Last reviewed

    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 and long context compared
    RAGFine-tuningLong context
    What it doesFinds the passages in your documents that answer the question and adds them to the promptTrains a model further on your examples so it behaves differentlyPuts all the material into the prompt on every call
    Good forLarge or changing knowledge: policies, product documents, tickets, contractsFixed output formats, tone, classification and other narrow, repeated tasksA small, fixed set of documents, or one long file analysed at a time
    Keeping facts currentUpdate the documents and the index. No retrainingRetrain to change anythingSend the new version
    Showing sourcesEasy. You know which passages were usedNo. The model cannot show where an answer came fromPossible if you ask the model to quote
    Per-user accessFilter retrieved passages by the user's permissionsNone. Anything trained in can reach any userYou choose what to send for each user
    Main costBuilding and running the index, plus short promptsTraining runs, then the tuned model's price or hostingLarge prompts on every call. Caching cuts the cost of repeats
    Main riskPoor retrieval returns the wrong passagesLearns style but not reliable facts, and goes staleAccuracy drops as input grows. Slow and costly at volume

    Start from your situation

    Which approach to start with
    If your situation isStart withWhy
    Answers must come from internal documents that change oftenRAGYou update documents without retraining anything
    Different users may see different documentsRAG with permission filtersNeither fine-tuning nor a long prompt enforces access per user on its own
    You have thousands of documentsRAGThey will not fit in any context window
    Answers must show their source for auditRAGEvery answer traces back to the passages used
    You analyse one long contract, report or codebase at a timeLong contextA few calls, and no index to build
    The same reference text is used in every callLong context with prompt cachingCached input costs a fraction of normal input
    Output must follow a strict format or fixed labels, and a good prompt is not consistent enoughFine-tuningChanging 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

    1. Does the material fit comfortably in one prompt? If not, use RAG.
    2. How often does it change? Weekly or faster points to RAG.
    3. Must answers show their sources? Then use RAG.
    4. Do users have different access rights? Then use RAG with permission filters.
    5. 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:

    1. Start with a clear prompt and RAG over your documents.
    2. Cache the fixed parts of the prompt, such as instructions and policy text.
    3. 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

    FAQ

    Is RAG better than fine-tuning?

    For adding knowledge, usually yes. A Microsoft research team found RAG consistently outperformed fine-tuning, both for facts the model had seen before and for new ones. Fine-tuning is better for changing behaviour, such as output format or tone.

    Does a 1 million token context window make RAG unnecessary?

    No. Models use long inputs unevenly, cost and response time grow with input size, and a long prompt cannot control which user sees which document. Long context works best for a small, fixed set of material.

    Can I use RAG and fine-tuning together?

    Yes. A common pattern is RAG for facts plus a fine-tuned model for one narrow step, such as classifying requests or producing a strict format. Add fine-tuning only after an evaluation shows a good prompt is not enough.

    How much data do I need to fine-tune?

    OpenAI's accuracy guide suggests starting with 50 or more good examples to improve consistency. What matters more is an evaluation set that proves the tuned model beats a well-written prompt.

    Sources

    Tell us what your AI system needs to know, how often it changes and who uses it.

    Related reading