Electrifiedby vlvd.net

RAG vs Fine-Tuning: Which One Does Your AI Product Need?

The short answer to rag vs fine-tuning is this: use retrieval augmented generation (RAG) when your model needs to know something, and use fine-tuning when it needs to behave a certain way. RAG finds the right documents when a question comes in and puts them into the prompt. Fine-tuning changes the model itself with training examples, so it writes in a style or format it would not produce on its own. Most small AI products need RAG long before they need tuning. Many never need tuning at all.

Age of AI Entrepreneur teaches you how to build, launch and grow a business with AI. The lessons are short and hands-on, and each one lists its sources. This post covers one choice inside that work. For the full picture, the AI Product Stack course has three lessons on it:

  • what a model API request costs in tokens
  • how to give a model your own data with retrieval
  • how to choose between big, small, open and closed models

Sign in with your email and an emailed code to open it.

RAG vs fine-tuning in one paragraph: knowledge vs behavior

A language model learns from a fixed pile of text, then stops learning. Everything it "knows" is frozen at that point, and it has never seen your company's files. RAG solves a knowledge problem. You keep your facts outside the model, search them at request time, and hand the best matches to the model as context. Fine-tuning solves a behavior problem. You show the model hundreds or thousands of input and output pairs until it reliably answers in your shape.

The term comes from a 2020 paper, Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. Its authors noted that knowledge stored inside a model's weights is hard to access precisely, hard to trace to a source and hard to update, and paired a model with a searchable index of Wikipedia to fix that.

What retrieval changes: fresh facts, citations and private documents

Retrieval is the right tool when the answer lives in a document the model has never read. Search usually runs on embeddings, lists of numbers that put similar meanings close together. Three things change once you add it.

  • Fresh facts. Update a help article today and the next answer uses it. You do not retrain anything.
  • Citations. You know which chunks went into the prompt, so you can show the user where the answer came from.
  • Private documents. Contracts, tickets, internal wikis. You can also filter by user before searching, so a customer only ever retrieves their own files.

Here is the core of a RAG prompt, in plain words. Your code searches your documents for the user's question, takes the top three passages, and sends something like this:

Answer using only the passages below. If they do not contain the answer, say you don't know. Cite the passage number. [1] ... [2] ... [3] ... Question: How do I export last year's invoices?

That last instruction matters. Retrieval lowers made-up answers but does not remove them. If search returns the wrong passage, the model can still answer confidently. Most RAG problems are search problems, so test your search before you blame the model.

What fine-tuning changes: tone, format and narrow repeated tasks

Fine-tuning earns its cost when you need the same kind of output, in the same shape, over and over. Good fits:

  • Tone. Replies that sound like your brand, every time, without a page of style rules in each prompt.
  • Format. Strict output that a program will read, such as a fixed set of fields or labels.
  • Narrow repeated tasks. Sorting support tickets into your twelve categories. Pulling the same five fields from shipping forms.

A tuned model can also let you use a smaller, cheaper model for a narrow job and send shorter prompts, because the instructions are now built in. What tuning does poorly is add new facts you can rely on. A 2023 study, Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs, found RAG consistently beat unsupervised fine-tuning on knowledge-heavy tasks, both for facts seen in training and for entirely new ones, and that models struggled to learn new facts through that kind of tuning. And even when some facts stick, you cannot cite them, and you must retrain whenever they change. A tuned model can still slip out of its trained voice, so test it on real inputs first.

Cost, speed and upkeep compared for a small team

The two methods spend money in different places.

RAG costs you on every request. Each answer carries extra context tokens. Say retrieval adds 2,000 input tokens per question and you serve 1,000 questions a day. That is 2,000,000 extra input tokens daily. Multiply that by your provider's price per million input tokens and you have the running cost of retrieval. You also pay a little latency for the search step, plus the upkeep of keeping your index in sync with your documents.

Fine-tuning costs you up front and again at every change. You need a clean training set, a training run, and a test that proves the new model is better than the old prompt. When your product changes, you repeat it. Check whether your provider prices a tuned model differently from the base one before you plan around it.

For a team of one to five people, upkeep usually decides it. A folder of documents that anyone can edit is easier to maintain than a training pipeline. Whichever you pick, put the per-request cost into your unit economics. The worked example in contribution margin with an AI product shows how model costs eat into each sale.

A simple decision test: try prompting first, then retrieval, then tuning

Climb this ladder one rung at a time, and stop as soon as the results are good enough.

  1. Write down 30 to 50 real questions and the answers you would accept. This is a small eval set. Without it you cannot tell whether any change helped. The Evals: Shipping AI That Works course covers building one and judging outputs.
  2. Prompt first. Write clear instructions and add three or four examples of good output. Run your eval set.
  3. Add retrieval if answers fail on facts. Wrong numbers, stale policies and "I don't have access to that" all point to a knowledge gap.
  4. Consider tuning if answers fail on shape. The facts are right but the tone wanders, the format breaks, or your prompt has grown so long it is slow and expensive.
Diagram of a four-rung ladder: an eval set, then a prompt, then retrieval for knowledge gaps, then fine-tuning for behavior gaps

The test question at each step is simple: is this failure about what the model knows, or how it acts? Knowledge points to retrieval. Behavior points to tuning.

When to combine RAG and fine-tuning, with a real product example

Take a type of product many small teams build: a reply assistant for a software company's support inbox. It drafts answers that a human agent reviews and sends.

  • The facts change every week: new features, price changes, known bugs. That calls for retrieval over the help center and release notes, with links in each draft.
  • The drafts must match the company's voice and follow a fixed layout: a greeting, a short answer, steps, and a link. If good prompting still gets this wrong too often, that calls for light fine-tuning on a few hundred past replies that agents rated highly.

The tuned model handles the shape. Retrieval supplies the content. You only retrain when the voice changes, which is rare. Facts update whenever someone edits a help article. Build retrieval first, though. You may find that examples in the prompt already fix the voice.

How model choice and API pricing shape the answer

Your model choice moves the line between these methods (more in how to choose an LLM). A large model often follows a long style guide well enough that tuning is not worth it. A small model is cheap and fast per request, but may need tuning to hold a format. Open models you host yourself give you full control over tuning, and you take on running the servers, a trade set out in self-hosted LLM vs API. Closed models through an API are simpler to start with, but you only get the tuning options the provider offers.

Pricing works the same way. If input tokens are cheap on your chosen model, generous retrieval context costs little. If they are expensive, you will want tighter search that sends fewer, better passages.

Frequently asked questions

Is RAG cheaper than fine-tuning?

Usually at the start, because you skip training and data preparation. At very high volume, the extra context tokens on every request can add up, so run the arithmetic with your own traffic and token counts.

Can fine-tuning teach a model new facts?

Somewhat, but not reliably. You cannot see which facts stuck, you cannot cite them, and you must retrain when they change, so retrieval is the better tool for knowledge.

Do I need a vector database to use RAG?

No. Retrieval means finding relevant text, and plain keyword search or a database query can do that for small or well-structured collections. Vector search helps when users phrase questions differently from your documents.

Does a bigger context window replace RAG?

For a small set of documents, you can sometimes paste them all into the context window and skip search. As your documents grow, you pay for every token on every request and answers can slow down, so selecting the right passages still matters.

Get started: learn the full AI product stack in the Age of AI Entrepreneur course

The choice between RAG and fine-tuning is one decision among many: which model, what each request costs, and how to feed it your data. The AI Product Stack course covers all three in lessons of about nine minutes, with questions to check what you learned and sources to read next. Sign in with your email and an emailed code to open it.

Start Age of AI Entrepreneur: short hands-on lessons on how to build a business in the age of AI, with every side of the debate and the sources to read next.

Building a business in the age of AI, from a first project to a company.

Visit aientrepreneur.vlvd.net
Age of AI Entrepreneur on desktop
Age of AI Entrepreneur on tablet
Age of AI Entrepreneur on phone
0 likes

Comments

No comments yet.

or make an account to comment.