Skip to content
AgentBuildLogGet the app

RAG vs Fine-Tuning (LoRA) vs Long Context: Which Does Your AI App Need?

Three ways to give a language model knowledge it doesn't have, and they solve different problems. A practical guide to choosing, with a simple decision path you can apply to your own project.

ABAgentBuildLog team3 min read

Your AI app needs to know things the base model doesn't: your product docs, your company policies, last week's data. There are three main ways to get that knowledge into the model's answers, and teams regularly pick the wrong one because the names sound interchangeable.

They aren't. Each one changes a different thing:

  • Long context puts the information directly into the prompt.
  • RAG (retrieval-augmented generation) searches your information and puts only the relevant pieces into the prompt.
  • Fine-tuning trains the model further so the behaviour is built into its weights.

Comparison of long context, RAG and fine-tuning by what they're best for, how fresh the knowledge stays, setup effort and cost per question

Long context: just include it

Modern models accept very long prompts. If your knowledge fits comfortably, the simplest option is to paste it in: the whole manual, the full contract, the entire codebase file.

Choose it when: the material is small enough to fit, changes often, and you need the model to consider all of it at once, such as reviewing a document or comparing two contracts.

Watch out for: cost and speed, because you pay for every token on every request (prompt caching, where your provider offers it, softens this a lot). Very long prompts also don't guarantee the model uses everything well; details buried in the middle can be overlooked.

RAG: search first, then answer

RAG splits your documents into chunks, indexes them by meaning (usually in a vector database), and for each question retrieves the handful of passages most likely to contain the answer. The model answers from those passages and can cite them.

Choose it when: your knowledge base is large, changes regularly, or you need answers to point back to a source. Help centres, internal wikis, policy questions and research assistants are classic RAG use cases.

Watch out for: retrieval quality. If search returns the wrong passages, the model answers from the wrong passages, often fluently. Most RAG problems are search problems, so measure retrieval separately from the final answers.

Fine-tuning: change the model itself

Fine-tuning continues training a model on your examples. Today most teams use parameter-efficient methods such as LoRA or QLoRA, which train a small set of extra weights instead of the whole model, so it is far cheaper than it used to be. It's excellent at teaching behaviour: a consistent output format, a house writing style, a specialised classification task, or getting a smaller, cheaper model to perform like a bigger one on one narrow job.

Choose it when: you need a consistent style or format that prompting can't reliably get, you're running a narrow task at high volume and want a smaller model, or you have hundreds to thousands of good examples of the exact behaviour you want.

Watch out for: using it to add facts. Fine-tuning is a poor way to teach a model knowledge. Facts learned this way are hard to update, can't be cited, and can blend with what the model already believed. When your facts change you're back to retraining.

A decision path

Ask these in order:

  1. Can the model already do this with a good prompt and a few examples? Then stop. You need neither RAG nor fine-tuning yet.
  2. Does the needed information fit in the prompt at an acceptable cost? Use long context.
  3. Is it a lot of information, or does it change, or do answers need sources? Use RAG.
  4. Is the problem how the model responds, not what it knows? Consider fine-tuning, once you've collected enough real examples.

They combine well

These aren't rivals. A common mature setup uses all three: RAG to fetch the right documents, a long context window to hold them along with the conversation, and a fine-tuned model to answer in exactly the required format. But teams that start with fine-tuning usually wish they'd started with RAG, and teams that start with RAG usually wish they'd first tried a better prompt.

Start with the cheapest thing that might work, measure it on real questions, and add complexity only when the measurements say so.

Want to see RAG without the magic? Our tutorial Build a RAG System in Python From Scratch builds every step in plain Python.

Weekly briefing

The AI build log, once a week

The news that matters and our newest tutorials. No hype, no spam.

One-click unsubscribe anytime.

More blog

Blog

What Is an AI Agent? Agentic AI Explained in Plain Words

"AI agent" is everywhere, and it means three different things depending on who's selling. Here's a clear definition, the four parts every agent has, and how to tell a real agent from a chatbot with a new label.