Skip to content

Fine-tuning vs RAG: how to adapt a model to your company data

B2Bnetwork team · · 5 min

Technology and trends

In brief

Choose RAG when the model has to use company knowledge that changes: price lists, procedures, contracts. Choose fine-tuning when the model has to learn a fixed way of working: an output format, a classification, a style. RAG feeds documents to the model with every request and lets you show where an answer came from. Fine-tuning changes the model weights based on hundreds or thousands of examples. In practice you start with a good prompt with examples plus RAG, and add fine-tuning only when tests show that is not enough.

What each method actually changes

The two methods solve different problems, so "which one is better" is usually the wrong question.

RAG (retrieval-augmented generation) means searching for document fragments that match the case and attaching them to the prompt. The model does not change. The text it reads does. The name comes from a 2020 research paper that combined a text-generating model with retrieval over a document collection.

Fine-tuning means further training an existing model on your examples: input and expected output. The weights change, so the model behaves differently even without extra text in the prompt. A popular variant, LoRA, trains only small additional matrices and leaves the original weights untouched, which greatly lowers the cost of training.

RAGFine-tuning
What it changesthe prompt contentthe model weights
What it is forfacts: price list, procedure, contract, manualbehavior: format, classification, style, jargon
Updating knowledgereplace a document in the indexretrain
Source of the answeryou can point to a document fragmentcannot be pointed to
Permissionsa filter at search time by rolethe model knows everything it learned
Input neededthe documents you already havehundreds or thousands of labeled examples

RAG or fine-tuning: business examples

TaskChoiceWhy
answering customers' technical questions from product data sheetsRAGsheets change, the answer must cite its source
checking supplier contract terms against an invoiceRAGevery supplier has a different contract, access only for purchasing
assigning an email to one of 40 ticket categoriesfine-tuning or examples in the promptfixed categories, thousands of labeled emails in history
writing output in a strict format for a systemfirst structured outputs, then fine-tuningformat is behavior, not knowledge
industry jargon and plant abbreviationsa glossary in the prompt or RAG, fine-tuning less oftena glossary is easier to fix than weights

A common mistake is fine-tuning a model on company documents hoping it will "memorize the price list". It will memorize it imprecisely, will not say where a number came from, and after a price change you have to retrain. Facts are what RAG is for, as described in RAG: AI and company documents.

Permissions and GDPR: where the difference is biggest

With RAG, a document stays in the index together with information about who may read it. The search filters results by the user's role or the AI Worker's account, so a sales rep never gets a fragment of an HR contract. Removing a document from the index removes it from answers immediately.

With fine-tuning, data goes into the weights. It cannot later be filtered by role, and a single record cannot be removed. When someone exercises the right to erasure (Article 17 of the GDPR), the only reliable route is retraining without that data. That is why personal data the model does not need stays out of the training set, and examples are anonymized before training. More in Company data and language models.

Cost and time: what you need to prepare

RAG requires preparing documents: splitting them into chunks, tagging them with metadata (department, date, type, permissions), a search index and often a vector database. Most of the work is tidying documents: old versions of procedures, duplicates, scans without text. Running cost grows with prompt length, because every attached fragment means extra tokens.

Fine-tuning requires a set of labeled examples: input and correct output, checked by a person. For classification they can often be pulled from system history, for example emails someone has already assigned to a category. Then comes training, evaluation and maintaining model versions. Every change of the base model means training again.

How to decide: five steps

  1. Write down the task and the metric. For example "assign the ticket category, target: at least 95% agreement with a person's decision".
  2. Build a test set of 200–300 real cases with the correct result. Without it you cannot compare any method, as explained in Evaluating language models.
  3. Try the simplest version. A good prompt, a few examples, structured outputs.
  4. Add RAG if facts are missing. Errors like "it did not know the payment terms for this customer" are solved by retrieval.
  5. Add fine-tuning if behavior is missing. Errors like "it knows, but answers in the wrong format or confuses similar categories" may disappear after training on examples.

The two can be combined: a model tuned for format and classification that takes facts from retrieval.

AI Workers in IT and data from DYNAMINDS Labs use company knowledge through permission-aware retrieval, and we decide on fine-tuning only based on test set results.

Questions and answers

Will fine-tuning stop the model from making things up?

No. Fine-tuning teaches a way of answering, but it does not give the model reliable knowledge of facts. A tuned model can still give a wrong number, only more convincingly. RAG with cited sources, plus a rule that the model answers "I don't know" when no fragment is found, protects better against made-up answers.

How many examples does fine-tuning need?

There is no single number: it depends on the task and the model. Provider documentation recommends writing evals first and measuring the untuned model, because a good prompt is often enough. A training set is best started with fewer, carefully checked examples and expanded after the first evaluation. In a classification with many categories, each category needs enough examples, otherwise the model will confuse it.

Does RAG work on scans and old files?

Only if text can be extracted from them. Scans without a text layer must first be read with OCR or a vision model. Tables and forms are worth converting into structure, because search handles text scattered across a page poorly.

Can you fine-tune an open model in-house?

Yes. Open models can be tuned on your own hardware, for example with LoRA, and training data never leaves the company. You still need to check the model license and size the GPU memory for training, which is larger than for inference alone. See Open source LLMs for business.

Considering a new technology for your system? Talk to an engineer.

Let's talk

Read more: Technology and trends

All in Technology and trends →