Every LLM project starts with the same architecture question: improve the prompt, add retrieval, or fine-tune the model. Use a practical decision rule to choose the next layer.
Your company is adding an AI workflow to a real product. The model can already answer general questions, but the product needs more than general fluency: it needs the right facts, the right format, the right tone, and reliable behavior under messy user requests.
That's where the first architecture decision appears. Do you write better prompts, build retrieval, or fine-tune on your data? The clean rule: prompts steer the current request, retrieval supplies fresh evidence, and fine-tuning changes stable behavior.
Three approaches can make an LLM better at your task:
| Approach | What changes |
|---|---|
| Prompt engineering | You change how the task is framed through instructions, examples, and context inside the request. The model itself doesn't change |
| Retrieval-Augmented Generation (RAG) | You change what the model can access at query time. The pipeline retrieves relevant documents from your knowledge base and injects them into the prompt before generation, so the frozen model can answer questions about private data[1] |
| Fine-tuning | You change the learned parameters used at inference. Training examples teach formats, labels, style, or stable task behavior[2] |
These approaches aren't mutually exclusive. A fine-tuned model can still use retrieval, and a RAG pipeline still needs good prompts. The useful question is sequence: which measured failure should you fix next?
Sequence rule: Establish a prompt-only baseline first unless the task already requires private, changing, or citation-sensitive evidence.
You write a system prompt, add examples when needed[3], and make the output contract clear. For reasoning-heavy tasks, chain-of-thought style prompting can improve performance, though production systems usually hide or summarize the reasoning trace rather than exposing it directly.[4] Mechanically, the model's weights stay frozen. Adaptation lives in the input tokens.
In standard dense-attention Transformers, self-attention scales as O(N²) with respect to sequence length N[5], so giant prompts increase latency and token spend. Long prompts also have their own failure mode: research shows models can miss facts buried in the middle of context[6]. Some frontier APIs now offer 1M-token-class windows[7], but "paste the corpus" still doesn't give you indexing, access control, source attribution, or selective retrieval.
The useful pattern is simple: keep stable instructions small, include only examples that change behavior, and put the current input where the model can find it. Long static prefixes can sometimes be amortized with provider-side prompt caching[8], but caching doesn't add citations, permissions, or retrieval semantics.
You build a pipeline that finds relevant documents and injects them into the prompt context. During indexing, you chunk documents, embed them, and write vectors plus metadata into a search index. At query time, you embed the user question, run approximate nearest-neighbor search, optionally rerank candidates, and inject the top chunks into the prompt.[9][10][11]
The architecture below shows both time scales in one vector space. Indexing turns chunks into searchable points ahead of time. Each request adds a query vector, selects a small neighborhood, and passes only those chunks into generation:
The model itself is unchanged. You're putting the right information in front of it at query time.[9] That can lower hallucination risk on knowledge-heavy tasks, but only if retrieval recall, ranking, and grounding instructions are good. Bad retrieval still produces bad answers.
You train the model on your specific dataset so some learned parameters change. In full fine-tuning that means updating the base weights directly. In PEFT methods such as LoRA, it usually means learning attached adapter weights while the base model stays frozen. Either way, the behavior shift lives in the model stack itself rather than only in the request context.
Most teams start with Parameter-Efficient Fine-Tuning (PEFT) instead of full fine-tuning. LoRA (Low-Rank Adaptation) freezes the pre-trained weight matrix and learns small adapter matrices:
W = W0 + ΔW = W0 + BA
For a 4096-by-4096 projection with rank 16, LoRA trains 16 * (4096 + 4096) = 131,072 adapter parameters while the 16.8M frozen base weights stay unchanged. In the original LoRA paper, this cut trainable parameters by orders of magnitude and reduced GPU memory requirements by about 3x relative to full fine-tuning in their experiments[2].
Fine-tuning is usually a poor fit for fast-changing factual knowledge. It can help the model speak more fluently in a domain, but once those facts change you need another training cycle, and you still don't get explicit source attribution the way you do with retrieval.
Ovadia et al. tested this directly and found that for knowledge injection, RAG consistently outperformed unsupervised fine-tuning, including on entirely new facts. Combining the two didn't beat RAG alone in their experiments[12]. Fine-tuning is strongest when teaching behavior, style, or a stable input/output mapping, not facts you expect to update.
Production fine-tuning commonly uses Hugging Face peft and supervised fine-tuning trainers.[13] A full run still needs clean examples, GPU memory, held-out evaluation, and model-specific chat-template handling.
Use this as a first filter, not as an accuracy scoreboard. Prompting is cheapest and fastest when the caller can provide all relevant facts. RAG adds ingestion, indexing, retrieval evaluation, and latency, but it's the strongest default for fresh or private knowledge. Fine-tuning costs more upfront and needs ML discipline, but it can be best for stable style, labels, format, or narrow behavior once the task is well measured.
The right layer depends on the failure you can measure:
That split tells you whether better instructions solve the task, retrieval missed the evidence, the generator ignored good evidence, or tuning introduced behavior drift.
MRR means Mean Reciprocal Rank and nDCG means normalized Discounted Cumulative Gain. Both ask whether the right chunk appears near the top of the retrieval list rather than somewhere deep in it.
Start with a prompt-only baseline unless the task needs retrieval or training. Keep improving the prompt when facts are present and the output mostly needs clearer structure. Add RAG when facts are missing, private, changing, or citation-sensitive. Test fine-tuning when evidence is present but format, labels, tone, or policy behavior fail repeatedly. If both facts and stable behavior are missing, use a hybrid: retrieval handles evidence, tuning handles habits.
Long context moved the threshold for when you need retrieval, but it didn't erase RAG. If a small, mostly static document set fits comfortably, long context can be the first version. Advertised capacity still isn't retrieval semantics: facts buried in the middle can be missed[6], and longer inputs raise cost, latency, and degradation risk.[14]
Retrieval also became more agentic. Instead of one search-then-generate pass, an agent can decide whether to retrieve, split a question into sub-queries, read results, and search again[15]. Use that pattern only when the question needs iteration, because it adds model calls and evaluation complexity.
Three mistakes cause most bad decisions:
Production systems often combine layers. The default for knowledge-heavy products is RAG plus good prompts: retrieval supplies evidence, and prompting controls output quality and format. Add fine-tuning when the model must follow a stable domain format while still citing fresh evidence. Add routing when volume is high and task difficulty varies.
Hard-coded dollar figures go stale fast, so think in terms of where effort shows up. Prompting is cheap until brittle prompts create review work; RAG adds ingestion, retrieval evaluation, and extra context tokens; and fine-tuning can look cheap at inference time while data curation, held-out evaluation, and refresh cycles dominate.
Distill the trade-offs into two measured gaps after a prompt baseline. Move right as the model needs more external or changing knowledge. Move up as outputs need more stable learned behavior.
Re-plot after each change. If neither gap remains but cost is too high, optimize routing instead of adding capability.
Evaluation rule: Compare every added layer against the same held-out task set. Keep the simpler path when retrieval or tuning doesn't improve the target metric enough to justify its cost and failure modes.
Use one final self-check: if the assistant writes in the right tone but misses policy facts that change weekly, add RAG. If it sees the right policy text but keeps returning the wrong routing label, test fine-tuning. If both fail after a prompt baseline, combine them.
Next useful articles: Production RAG Pipelines, LoRA and Parameter-Efficient Fine-Tuning, and Instruction Tuning.
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.
Lewis, P., et al. · 2020 · NeurIPS 2020
LoRA: Low-Rank Adaptation of Large Language Models.
Hu, E. J., et al. · 2021 · ICLR
Language Models are Few-Shot Learners.
Brown, T., et al. · 2020 · NeurIPS 2020
Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.
Wei, J., et al. · 2022 · NeurIPS
Attention Is All You Need.
Vaswani, A., et al. · 2017
Lost in the Middle: How Language Models Use Long Contexts
Liu, N.F., et al. · 2023 · TACL 2023
1M context is now generally available for Opus 4.6 and Sonnet 4.6
Anthropic · 2026
Prompt caching
OpenAI · 2026
Retrieval-Augmented Generation for Large Language Models: A Survey.
Gao, Y., et al. · 2023
Efficient and Robust Approximate Nearest Neighbor Using Hierarchical Navigable Small World Graphs.
Malkov, Y. A., & Yashunin, D. A. · 2018 · IEEE Transactions on Pattern Analysis and Machine Intelligence
Billion-scale similarity search with GPUs.
Johnson, J., Douze, M., & Jégou, H. · 2019 · IEEE Transactions on Big Data
Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs
Ovadia, O., Brief, M., Mishaeli, M., & Elisha, O. · 2024 · EMNLP 2024
TRL Documentation: SFT Trainer.
Hugging Face · 2026
Context Rot: How Increasing Input Tokens Impacts LLM Performance
Hong, K., Troynikov, A., & Huber, J. · 2025
Building Effective Agents
Anthropic · 2024