IDInternals Decoded
All articles
PlaybooksIntermediate11 min readJun 2026

Fine-Tuning vs RAG vs Prompting: Which Lever When

The decision framework for customizing model behavior, with honest costs for each path.

Prompting, fine-tuning, and retrieval-augmented generation (RAG) are the three levers you can pull to customize an LLM’s behavior. Prompting shapes input at inference time without changing weights. Fine-tuning updates model parameters to internalize domain patterns. RAG injects external knowledge via retrieval. The right choice depends on whether your gap is behavioral, knowledge-based, or both, and on latency, cost, and maintenance constraints.

Most production systems combine all three levers. But the order in which you apply them, exhausting prompts first, then adding RAG, then fine-tuning, is rarely questioned. Skipping fine-tuning entirely can trap you in permanently brittle, expensive prompts and a reliance on ever-larger context windows.

Think of an LLM as a skilled general contractor. Prompting is the instruction you issue on the job site, what to do and how. Fine-tuning is sending the contractor to a specialized course so they internalize your company’s building codes. RAG is handing them a library of blueprints and regulations they can reference at any time. The most reliable construction uses all three.

That mental model maps directly to the real system. Prompting is transient, stateless, and lives entirely within the model’s current context window. Fine-tuning permanently alters the contractor’s (model’s) internal skill set. RAG provides fresh reference material on every job without retraining.

How does prompting steer a fixed model?

Every prompt is a token sequence that modifies the input to a fixed conditional distribution. The model computes each next token by attending to all prior tokens in the context window. When you add instructions, examples, or role specifications, you are altering the activations that bias the logits toward your desired output. No weights change. The model’s ability to perform few-shot learning, inferring a task from a handful of examples, is a side effect of its pretraining on billions of sequences that contain similar patterns.

Few-shot prompting exploits the Transformer’s attention mechanism. When you supply several input-output pairs and then a final prompt, the model’s self-attention layers pick up the pattern and align the next tokens with the demonstrated structure. This is a form of inference-time meta-learning: the model infers a latent task variable and applies it to the new input.

Prompt engineering therefore works best when the model already knows the underlying task and you only need to steer it toward the right part of its latent space. You can shape tone, output format, and reasoning steps. But two hard limits exist. First, prompt engineering cannot add knowledge the model never saw during training. If the model’s pretraining corpus lacked information about your internal policies, prompting will at most produce plausible-sounding fabrications. Second, the context window caps how many instructions and examples you can include. Long prompts increase both latency and cost, and complex policies expressed entirely in text become brittle. A small wording change can push the model out of the region where it behaves correctly.

How does fine-tuning reshape the model’s internal distribution?

Fine-tuning runs gradient descent on a dataset of input-output pairs, updating the model’s parameters to minimize a loss, typically cross-entropy over the assistant tokens. This permanently alters the conditional distribution, so the model produces the desired behavior even with minimal prompting. Instead of pasting 500 tokens of brand guidelines into every request, the model internalizes the voice. Instead of giving eight examples of JSON (JavaScript Object Notation) output, it generates valid JSON by default.

Mechanically, the process is straightforward. You curate a dataset of prompts and ideal responses, often in a conversation format with system, user, and assistant roles. The training loop uses standard optimizers like AdamW. After training, you get a new model identifier (or a set of adapter weights) that you call like any other LLM endpoint.

Parameter-efficient fine-tuning (PEFT) techniques like LoRA reduce the training cost dramatically. LoRA freezes the original weight matrix (W) and trains a low-rank additive update (BA) where (A \in \mathbb{R}^{d \times r}, B \in \mathbb{R}^{r \times k}) with a small rank (r). The effective weight becomes (W' = W + BA). This reduces trainable parameters by orders of magnitude and allows you to maintain multiple adapters on a single base model. For example, you could serve a separate LoRA adapter per customer without spinning up a separate model instance for each.

Fine-tuning is the right lever when the gap is behavioral or stylistic rather than purely factual. It also reduces inference latency and token cost because you can strip away lengthy system instructions and few-shot examples. In some cases, a smaller fine-tuned model can match the task performance of a much larger instruction-tuned model that relies on prompt engineering alone. One study found a fine-tuned model roughly 1,400 times smaller than GPT-3 matched its performance on a domain task.

The tradeoff is stability. Fine-tuning bakes knowledge into the parameters. If your domain data changes frequently, product prices, documentation updates, you must re-run fine-tuning to keep the model current. Overly aggressive fine-tuning can also cause catastrophic forgetting, where the model loses general capabilities. LoRA mitigates this by confining updates to a low-rank subspace, but active adapters still bias all outputs. Many teams use routing logic to only apply adapters for specific queries.

How does RAG inject external knowledge at inference?

RAG leaves model weights untouched and instead augments each query with relevant passages retrieved from an external corpus. The canonical formulation marginalizes output probability over retrieved document subsets:

[p(y \mid x) = \sum_{Z \subset \mathcal{D}} p(Z \mid x) , p_{\text{gen}}(y \mid x, Z)]

In practice, this is approximated by fetching the top-(k) passages with a dense retriever and feeding them to the generator alongside the query.

The pipeline has four stages. Indexing: documents are chunked and embedded using a sentence encoder, then stored in a vector database. Query encoding: the user’s query is embedded with the same (or a paired) encoder. Retrieval: an approximate nearest neighbor search returns the top-(k) chunks. Augmentation: the retrieved passages are concatenated into the prompt, often with delimiters and source metadata. Generation: the LLM reads the augmented prompt and produces an answer grounded in the provided context.

Dense retrieval uses a dual encoder architecture. The query encoder (f_Q) and document encoder (f_D) map queries and documents to a shared vector space. Relevance is scored via dot product or cosine similarity. Embeddings are precomputed for the entire corpus and indexed with algorithms like HNSW (Hierarchical Navigable Small World) or IVF so that searching over millions of vectors takes milliseconds.

RAG decouples knowledge from parameters. Updating the corpus and reindexing takes minutes, not hours of GPU (graphics processing unit) time. This makes RAG the natural lever when the primary requirement is access to up-to-date, proprietary, or verifiable information. Because answers can cite retrieved passages, RAG also supports higher trust and auditability.

The cost is latency and complexity. Each query now requires an embedding call and a vector database search, adding 100-500 ms of overhead survey. Retrieval quality is critical. If the top-(k) passages don’t contain the answer, no amount of prompting will recover it. Dense retrievers can also miss exact phrase matches that a hybrid sparse-dense system would catch. And the generator can still hallucinate over retrieved context if the passages are irrelevant or contradictory.

RAG adds latency but keeps knowledge fresh
100-500 ms
Added latency per query
Minutes
Time to reindex corpus
Retrieval overhead per query vs. reindex time when data changes.

How do prompting, fine-tuning, and RAG compare across the dimensions that matter?

The table below synthesizes the key operational differences. Use it as a quick reference when evaluating which lever (or combination) fits a given constraint.

DimensionPromptingFine-TuningRAG
What changesInput tokensModel parameters (full or adapter)External data fed into prompt
Knowledge recencyStatic (frozen at training cutoff)Frozen until next fine-tune runNear-real-time (corpus update)
Typical latency add0 ms (only LLM inference)0 ms from training (inference same as base model)100-500 ms retrieval overhead
Minimum dataNone (engineer intuition only)~10 examples to start; 50-100+ for reliable improvement OpenAICorpus of documents; retrieval requires at least hundreds of chunks
Update cadenceInstant (change a prompt string)Hours to days (training job)Minutes (reindex corpus)
Best forTask steering when model already knows the domain; output formattingStable behavioral or style shift; removing large prompts; adapting to a narrow domainDynamic knowledge, traceability, and grounding in large or changing document collections
Failure modeBrittle; prompt drift; context window exhaustionCatastrophic forgetting; stale facts; training distribution mismatchRetrieval failure; hallucination over noisy context; embedding misalignment

Fine-tuning reduces your reliance on the other two levers. Prompts become shorter, and you may not need RAG for knowledge if the domain is narrow and stable. RAG reduces the need to stuff all knowledge into the prompt or the weights. Systems that try to solve everything with prompting alone eventually hit context window limits and consistency issues.

When should you combine them?

Most reliable production systems layer all three. Prompt engineering defines the interaction contract and sets safety boundaries. RAG pulls in fresh, grounded evidence. Fine-tuning encodes stable task behavior and domain reasoning so that prompts are minimal and the model processes retrieved context efficiently.

OpenAI’s own optimization guidance outlines a flywheel. Start with prompt engineering and establish solid evals. Identify failure categories. For failures that stem from missing knowledge, add RAG. For failures that persist despite correct retrieval, like stylistic inconsistency or inability to follow a complex output schema, collect those as training examples and fine-tune. Then re-evaluate, tighten the prompts, and repeat.

Concrete hybrid patterns abound. One common architecture: a LoRA adapter fine-tuned to follow a specific citation format, paired with a RAG pipeline that provides the evidence the adapter will format. Another: a RAG system that uses a fine-tuned re-ranker to improve retrieval over domain-specific documents. The levers are composable, not competitive.

An important trap to avoid is using fine-tuning as a substitute for retrieval. Fine-tuning a model on a static snapshot of your knowledge base will inevitably become stale. Instead, let RAG carry the facts and use fine-tuning to carry the behavior: how to read, summarize, and format those facts. This division of labor yields both freshness and style consistency.

Frequently Asked Questions

Q: Can I skip fine-tuning entirely and rely on RAG plus prompting? Yes, when your domain changes are frequent and your retrieval system reliably finds relevant passages. But you will need larger prompts to enforce style and formatting, and you may struggle with output consistency across different query phrasings.

Q: When does fine-tuning reduce inference cost? When it allows you to remove lengthy system messages, few-shot examples, or switch to a smaller model that still matches performance. Fine-tuning a compact model to internalize a domain can cut per-token cost while keeping quality.

Q: How many examples do I need for fine-tuning? API (application programming interface) providers like OpenAI accept as few as 10 examples, but real improvements beyond surface-level formatting usually require 50-100 high-quality, representative examples. For complex reasoning tasks, expect to need hundreds or thousands.

Fine-tuning example counts
10
Minimum examples (API)
50-100+
For real improvements
Minimum vs. practical example counts for meaningful improvement.

Q: Why does RAG sometimes hallucinate despite having retrieved a correct document? The generator may fail to attend properly, especially if multiple passages are concatenated and the correct one is buried. It may also summarize inaccurately or interleave its parametric knowledge. Prompt instructions to only use retrieved content and explicit source tagging help.

Q: Can I use LoRA adapters alongside RAG without conflicts? Yes. A LoRA adapter typically controls style or schema, while RAG provides the factual payload. The adapter sees the augmented prompt and applies its learned transformations. Just ensure your fine-tuning data includes examples with retrieved-context-style inputs to prevent distribution mismatch.

If you found this deep dive on how to actually choose between prompting, fine-tuning, and RAG useful, not just the usual platitudes, you’ll want to subscribe to Internals Decoded. Every week we break down real systems internals, from vector databases to LLM training loops, with the same level of detail. Join at internalsdecoded.com.

Sources

#fine-tuning-vs-rag#customization
More from the library
The Newsletter

Keep up with AI. One email a week.

One thoughtful email each week. Unsubscribe whenever you like.