Skip to content
coderband

RAG vs Fine-Tuning vs Long Context in 2026: How to Choose

Start with long context and prompt caching, add RAG when the corpus outgrows the window or needs per-user access, fine-tune last. Prices and evidence.

coderband engineering13 min read

If your knowledge fits in the prompt, put it there and cache it: Anthropic, OpenAI and Google all sell models with context windows of about 1 million tokens, and a cached input token lists at $0.10 per million on Claude Sonnet 5.5 and gpt-6.2-sol, against $2 uncached. Add retrieval (RAG) when the corpus outgrows the window, when different users are allowed to see different documents, or when volume makes re-reading everything too expensive. Fine-tune last, and for behaviour, not facts: OpenAI stops accepting new fine-tuning jobs on January 6, 2027, and the Claude API doesn’t offer fine-tuning.

Key takeaways

  • All three providers sell roughly 1 million tokens of context, with different pricing rules. Claude Opus 5.5 and Sonnet 5.5 bill the whole window at the standard rate, while Claude Haiku 5.5 costs five times more above 100K tokens. OpenAI doubles the input price above 272K.
  • Prompt caching is what makes long context affordable. In the worked example below, a 150,000-token knowledge base queried 10,000 times a month costs $3,046 uncached, $325 cached and $136 with RAG, at list prices.
  • Published comparisons favour long context on answer quality and RAG on cost. An EMNLP 2024 study found long context ahead of RAG on average when given enough resources, at a much higher token bill.
  • Long prompts fail in their own way. Models miss facts placed in the middle of the input, and accuracy falls as inputs grow.
  • RAG is the only one of the three that can enforce per-user permissions, because a permission-aware index filters before the model sees anything.
  • Fine-tuning changes behaviour, not knowledge. Use it for format, tone, classification and speed. Hosted options are narrow: OpenAI is closing its platform, the Claude API has none, and Google tunes only Flash-class and 2.5 models.

The three approaches

Long context means sending the model everything it might need on every request: the whole handbook, every contract, the full catalogue. Nothing is built except the prompt, and prompt caching lets the provider reuse the already-processed prefix at a fraction of the input price.

Retrieval-augmented generation (RAG) splits your documents into chunks and indexes them, usually by embedding vectors with keyword search alongside. At question time it fetches the few chunks that look relevant and sends only those. The prompt stays small whatever the size of the corpus. The price is a pipeline: ingestion, chunking, an index, and a retrieval step that can miss.

Fine-tuning is further training of a pretrained model on your own examples, so the behaviour lives in the weights instead of the prompt. There are two routes: a provider’s hosted tuning service, or an adapter such as LoRA on an open-weight model, which trains a small set of added weights and leaves the base model frozen. The tuned model answers without being shown anything, so it’s fast, but it can’t cite what it learned and can’t be updated without another training run.

Context windows and prices in November 2026

List prices per 1 million tokens, read from each provider’s pricing page on November 18, 2026. Context sizes come from the model pages linked above and Google’s Gemini 4 Argon page.

Model Context window Input Cached input Output Long-prompt pricing
Claude Opus 5.5 1M $4 $0.20 $20 None: full window at the standard rate
Claude Sonnet 5.5 1M $2 $0.10 $10 None
Claude Haiku 5.5 1M $0.10 $0.01 $0.50 Prompts over 100K tokens: $0.50 / $0.05 / $2.50
gpt-6.2-astra 1.05M $8 $0.40 $40 Over 272K input tokens: $16 / $0.80 / $60
gpt-6.2-sol 1.05M $2 $0.10 $10 Over 272K: $4 / $0.20 / $15
gpt-6-luna 1.05M $0.10 $0.01 $0.50 Over 272K: $0.20 / $0.02 / $0.75
Gemini 4 Carbon and Argon 1M $2, then $4 from Dec 1, 2026 $0.10, then $0.20 $10, then $20 None listed
Gemini 4 Hydrogen 1M $1.50 $0.075 $7.50 None listed

Three things the table doesn’t show:

For per-task agent costs, embeddings and vector-store prices, see our AI agent cost breakdown.

Fine-tuning: what you can still buy

Where What you can tune Training price per 1M tokens Inference price
OpenAI gpt-4.1, gpt-4.1-mini, gpt-4o, gpt-4o-mini, for existing fine-tuning customers only $25, $5, $25 and $3 gpt-4.1: $3 input, $12 output. gpt-4.1-mini: $0.80 and $3.20
Anthropic Nothing on the Claude API Not offered Not offered
Google Vertex AI Gemini 3.5 Flash, 3.5 Flash-Lite, 3.1 Flash-Lite and the 2.5 family $10, $3 and $3 for the first three (listed per 1,000 tokens) Gemini 3 and later: base model price on the global endpoint, 1.5x in other regions
Together AI, open weights Llama, Qwen, Gemma, gpt-oss and others From $0.34 (Llama 3.1 8B, $4 minimum per job); $2.50 for gpt-oss-120B Dedicated endpoint billed by the minute; one H100 lists at $5.49 an hour

OpenAI is winding its platform down. Its deprecations page says organizations that had never fine-tuned lost access on May 7, 2026, and active customers can create jobs until January 6, 2027. Tuned models serve only while their base model exists, and the same page lists all four base models for shutdown on January 14, 2027.

Anthropic says in its glossary: “The Claude API does not currently offer fine-tuning.” Amazon Bedrock’s fine-tuning table lists one Claude model, Claude 3 Haiku in us-west-2, and Bedrock’s lifecycle page shows that model reached end of life in that region on September 10, 2026.

Google has no tunable model in the Gemini API or AI Studio. Tuning lives on Vertex AI, and the Gemini 4 family isn’t on its list.

Open weights are the durable route. You can keep the base model and the adapter yourself, so no provider’s retirement schedule applies. Training is cheap. Hosting is the bill:

Training (illustrative): 2,000 examples x 1,000 tokens x 3 epochs = 6M training tokens
  Gemini 3.5 Flash-Lite on Vertex:  6M x $3.00 / 1M = $18.00
  Llama 3.1 8B on Together AI:      6M x $0.34 / 1M =  $2.04  (billed at the $4.00 minimum)

Hosting on one always-on H100 (Together AI list price):
  $5.49 x 24 hours x 30 days = $3,952.80 a month

Vertex counts training tokens as dataset tokens multiplied by epochs. The training bill is the smallest line. The real costs are the labelled examples, the evaluation, and repeating both when the base model changes.

What the evidence says

Every study below tested models older than the ones in the price table. Treat the findings as direction and measure on your own data. Every AI Feature Sprint ships with an evaluation harness and an agreed test set for that reason, and our guide to evaluating an LLM feature before you ship it shows how to build one.

Long context against retrieval

  • The EMNLP 2024 comparison found long context ahead of RAG on average across three models, with RAG far cheaper.
  • A later preprint agreed for question answering. Summarization-based retrieval came close to long context, chunk-based retrieval lagged, and RAG did better on dialogue-based questions.
  • A June 2026 preprint ran two small language models on a manufacturing safety benchmark. Long-context prompting scored 73.1% correct against 65.4% for semantic RAG, at 26 times the token cost per query.
  • The LaRA benchmark, with 2,326 test cases across 11 models, found no universal winner: it depended on model strength, context length, task type and the retrieved chunks.

Position and length effects

Lost in the Middle, published in TACL, showed models answer best when the relevant passage sits at the start or end of the input and worse when it sits in the middle. NoLiMa (ICML 2025) tested 13 models on questions that share few words with the passage that answers them. At 32K tokens, 11 of them fell below half of their short-context score, and GPT-4o went from 99.3% to 69.7%. A 2026 workshop paper found accuracy dropped sharply when the evidence was spread across the context. Chroma, a vector database company, tested 18 models and saw performance degrade with input length in every experiment.

Anthropic’s prompting guide has two cheap mitigations: put documents at the top and the question at the end, which improved response quality by up to 30 percent in its tests, and ask the model to quote the relevant passages before answering.

How retrieval fails

An experience report on three RAG case studies lists seven failure points. Two of them can’t happen when the whole corpus is in the prompt: the answer existed but ranked too low to be retrieved, and the right chunk was retrieved but dropped before the prompt was assembled. Retrieving more chunks is not a fix. Two studies (one, two) found answer quality rises and then falls as passages are added, because near-miss chunks mislead the model.

What fine-tuning is good for

OpenAI’s accuracy guide splits the problem in two. If the model lacks knowledge, give it context. If it knows enough but behaves inconsistently or formats output wrongly, tune it. Google’s tuning docs list classification, summarization, extractive question answering and chat as good fits, and its pricing page lists lower latency and cost from shorter prompts as a benefit.

Facts are a different matter. A 2023 study found RAG consistently beat unsupervised fine-tuning at injecting knowledge, both new and previously seen. An EMNLP 2024 paper found that models learn new facts slowly through fine-tuning and hallucinate more as they do. The two combine well: in a case study on agriculture, fine-tuning added over 6 percentage points of accuracy and RAG added 5 more on top.

Freshness, access control, privacy, latency and upkeep

Long context with caching RAG Fine-tuning
Freshness Edit the document and the next request sees it. Each edit forces a cache write, because hits need an identical prefix Re-index the changed document Retrain, and retrain again when the base model is retired
Per-user access None. Whoever can ask can reach everything in the prompt Filter by user or tenant in the retrieval query, on a permission-aware vector store None. Every caller shares the weights
Privacy and deletion Remove the document from the prompt Delete the rows from the index Training text can be extracted by querying a model, and an erasure request means retraining
Latency A long prompt can delay the first token. Caching helps: Anthropic’s launch figures for a 100,000-token prompt were 11.5 seconds to first token uncached, 2.4 cached One extra hop for search, then a short prompt Shortest prompts; a small tuned model can replace a large one
Upkeep A prompt file and a cache-hit metric Ingestion, chunking, embeddings, index, permissions, retrieval tests Training data, evals, retraining, and hosting for open weights

Access control is the row that overrides cost. If two customers must never see each other’s documents, a shared prompt can’t guarantee it, and a system-prompt instruction is not a control. The filter belongs in the retrieval query, enforced server-side.

Hybrid patterns that work

  1. Retrieval plus caching. Put the stable material first (instructions, tool definitions, the documents every question needs) and cache it. Retrieve only the long tail and append it after the cached prefix.
  2. Contextual retrieval. Anthropic’s method prepends a short, model-written note on each chunk’s place in its document before indexing. With keyword search added it cut failed retrievals by 49% (from 5.7% to 2.9%), and by 67% with a reranker, for a one-time $1.02 per million document tokens at that post’s prices. The same post says that below 200,000 tokens you can skip RAG and put the whole knowledge base in the prompt.
  3. Route by question. Self-Route tries RAG first, lets the model say whether the retrieved chunks are enough, and falls back to the full context when they aren’t.
  4. Tune for behaviour, retrieve for facts. RAFT fine-tunes a model to ignore irrelevant retrieved documents and quote the relevant one.

A worked cost comparison (illustrative)

One workload, three designs, list prices. Your token counts, cache-hit rates and traffic will differ.

Assumptions: a support assistant whose instructions and knowledge base total 150,000 tokens (about 83,000 words). 10,000 questions a month in business hours, 300 tokens each, 400-token answers. Claude Sonnet 5.5: $2 input, $4 one-hour cache write, $0.10 cache read, $10 output. The cache is rewritten 220 times a month (10 a day for 22 working days), which is pessimistic because hits refresh it for free.

A. Whole knowledge base in every prompt, no caching
   Input:   10,000 x 150,300 = 1,503M x $2.00  = $3,006.00
   Output:  10,000 x     400 =     4M x $10.00 =    $40.00
                                         Total   $3,046.00

B. Same prompt, one-hour cache
   Cache writes:    220 x 150,000 =    33M x $4.00  = $132.00
   Cache reads:   9,780 x 150,000 = 1,467M x $0.10  = $146.70
   Questions:    10,000 x     300 =     3M x $2.00  =   $6.00
   Output:                              4M x $10.00 =  $40.00
                                              Total   $324.70

C. RAG: 8 chunks of 500 tokens + 500 instructions + 300 question = 4,800 tokens
   Input:   10,000 x 4,800 = 48M x $2.00  = $96.00
   Output:                    4M x $10.00 = $40.00
   Embeddings: (150,000 + 10,000 x 300) = 3.15M x $0.02 = $0.06
                                    Total   $136.06

Embeddings use OpenAI’s text-embedding-3-small at $0.02 per million tokens. The index is 300 chunks of 1,536 dimensions, or 460,800 stored dimensions, inside the 10 million that Cloudflare Vectorize includes on its paid plan.

  • Caching removes 89% of the bill. Going from A to B is a configuration change.
  • RAG saves another $189 a month. That doesn’t pay for many hours of building and maintaining a pipeline. At this size, B wins on total cost.
  • The gap grows with the corpus. With a 600,000-token knowledge base, B becomes 132M x $4 + 5,868M x $0.10 + $6 + $40 = $1,160.80, while C stays near $136.

Surcharges can flip the result. On Claude Haiku 5.5, design B’s 150,000-token prompt lands in the over-100K tier: 33M x $1 + 1,467M x $0.05 + 3M x $0.50 + 4M x $2.50 = $117.85. Design C stays in the cheap tier at 48M x $0.10 + 4M x $0.50 = $6.80.

The decision table

Situation Use Why
Corpus under about 200,000 tokens, and every user may see all of it Long context with caching No pipeline, ahead on answer quality in the published comparisons, cheap once cached
Corpus larger than the window, or heading there RAG Scales past the window, and cost per question stays flat
Users or tenants may see different documents RAG with a permission filter in the query A prompt can’t enforce access
Content changes many times a day RAG, or tool calls against the source system Every edit to a cached prompt forces a cache write
High volume and thin margin per request RAG, often on a small model About 30 times fewer input tokens per question in our example
Questions that need the whole corpus at once, such as summaries and comparisons Long context Retrieval returns fragments, and these answers need everything
Right facts, wrong format, tone or labels, after real prompt work Fine-tune a small model and keep the facts in the prompt Tuning fixes behaviour and shortens prompts
Hard latency budget, or data that must stay in your cloud Open-weight model with LoRA, plus RAG for facts You own the weights and nobody retires them

For most teams the order holds: long context with caching first, RAG when the corpus or the permission model demands it, fine-tuning when a measured behaviour problem survives good prompting. An eval set tells you when to move.

Build it with the numbers attached

The AI Feature Sprint puts one production AI feature in your product in 10 business days for $8,500 fixed, paid 50% to start and 50% on delivery. An assistant over your docs is in scope: the sprint covers an LLM feature, a RAG assistant, an agent workflow or a model integration. We’re vendor-neutral across OpenAI, Anthropic, Google and open-weight models in your own cloud, and we show you the cost and quality trade-off before we pick. Scope, success measure and eval set are frozen in writing in the first two days. On day five you see a working demo on your own data. If it isn’t what you hoped, tell us by the end of the next business day: we stop, your deposit is refunded in full, and the second payment is never due. Delivery includes the evaluation harness, cost and latency telemetry for every request, a runbook, and two weeks of bug-fix support.

For anything larger, get in touch.