Skip to content
Raisalon

Artificial Intelligence

RAG vs. fine-tuning: how to choose for your LLM application

RAG changes what a model reads; fine-tuning changes how it behaves. Use five questions, a token-cost calculation and an evaluation plan to pick the right one.

Author
4 min read

Retrieval-augmented generation (RAG) and fine-tuning solve different problems, which is why “which is better?” rarely has a general answer. RAG changes what the model reads at request time: relevant passages are retrieved and placed in the prompt. Fine-tuning changes the model itself by updating its weights on examples. The first is a way to supply knowledge. The second is a way to shape behaviour. Red Hat’s comparison of RAG and fine-tuning

What each approach actually changes

RAG was introduced as a way to combine a language model with a retrievable document index, so answers can draw on text the model never memorized. Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks Fine-tuning trains on input–output pairs. Parameter-efficient methods such as LoRA train small adapter matrices instead of every weight, which makes fine-tuning far cheaper to run and to store. Hu et al., LoRA: Low-Rank Adaptation of Large Language Models

Property RAG Fine-tuning
What changes The prompt, per request The model weights, once per training run
Updating knowledge Re-index the documents Retrain on new examples
Citing sources Natural: the passages are known Not built in
Main cost Extra input tokens on every request Training runs and evaluation
Typical failure Retrieves the wrong passage Confidently wrong, outdated, or overfitted output
Strongest at Facts, freshness, traceability Format, tone, narrow task behaviour

Five questions that settle most decisions

  1. Does the answer depend on facts that change? Prices, policies, documentation and tickets change weekly. Re-indexing a document takes minutes. Retraining a model for every change does not keep up. Choose RAG.
  2. Must users see where an answer came from? In support, legal and internal knowledge tools, a citation is part of the answer. RAG retrieves the passage, so you can show it. Choose RAG.
  3. Is the problem the form of the output rather than the facts? If a well-prompted model knows the content but keeps getting the format, tone, or labelling wrong, examples in the weights help more than more context. Choose fine-tuning.
  4. Is the task narrow, frequent and stable? Classifying support tickets into fixed categories or extracting the same fields from every message are good fine-tuning candidates. A small fine-tuned model can replace long instructions repeated on every request.
  5. Do you need both? A common production pattern uses fine-tuning for behaviour and RAG for facts. They are not mutually exclusive.

One thing neither approach provides is a security boundary. The OWASP Top 10 for LLM applications notes that research shows RAG and fine-tuning do not fully mitigate prompt injection. OWASP LLM01:2025 Prompt Injection That risk needs its own controls, covered in how to defend LLM apps against prompt injection.

Estimate what RAG adds to every request

RAG’s cost is easy to underestimate because it is paid on every request. Each retrieved chunk becomes input tokens. The function below counts the extra tokens per month. It deliberately leaves out prices, which change often: multiply the result by your provider’s current input price.

def monthly_context_tokens(requests_per_month, chunks_per_request, tokens_per_chunk):
    """Extra input tokens RAG adds by placing retrieved chunks in every prompt."""
    return requests_per_month * chunks_per_request * tokens_per_chunk


for chunks in (3, 5, 10):
    extra = monthly_context_tokens(100_000, chunks, 400)
    print(f"{chunks:>2} chunks x 400 tokens: {extra / 1_000_000:,.0f}M extra input tokens per month")
 3 chunks x 400 tokens: 120M extra input tokens per month
 5 chunks x 400 tokens: 200M extra input tokens per month
10 chunks x 400 tokens: 400M extra input tokens per month

Two levers follow directly. Retrieving fewer, better chunks cuts cost linearly, which is why retrieval quality matters before anything else. And a long, stable instruction block repeated on every request is exactly what prompt caching discounts, as explained in how to cut LLM API costs. Fine-tuning moves this cost elsewhere: shorter prompts per request, paid for with training runs and a model you now have to maintain.

Advertisement

Decide with an evaluation, not an opinion

Build a test set before choosing. A few dozen to a few hundred real questions with known good answers is a practical start for comparing approaches. Then measure each approach on its own failure mode.

  • For RAG, measure retrieval first. If the right passage is not retrieved, no prompt can recover it. Recall@k and mean reciprocal rank show this directly; Recall@k vs. MRR walks through both with three queries. Chunking matters as much as the model: repeating PDF table headers can change what retrieval finds.
  • For fine-tuning, compare against prompting. A fine-tuned model has to beat a well-prompted base model on a held-out test set that was never used for training or prompt selection. Report a metric suited to the task, such as macro F1 for imbalanced classes (macro, weighted and micro F1).
  • For both, track cost and latency per request next to quality. A small gain in accuracy can be the wrong trade if it doubles the cost.

A practical default

Start with a strong prompt and RAG. It is quicker to build, easier to update, and shows its sources. Add fine-tuning when evaluation shows a behaviour problem that prompting and retrieval cannot fix, such as a format the model keeps breaking or a narrow task where a small model could replace a large one. When you do, keep RAG for the facts.

Next steps

Write down the questions your application must answer, mark which depend on changing facts and which on consistent behaviour, and build the test set before writing any pipeline code. The document Q&A with RAG and an evaluation suite and fine-tuning an open LLM with LoRA projects follow exactly this plan.

Share

Written by

Advertisement

Advertisement