Retrieval-Augmented Generation

Retrieval-Augmented Generation

What is RAG?

RAG (retrieval-augmented generation) gives an LLM access to your own data without retraining the model. What is RAG exactly, how does it work technically, and when do you choose it over fine-tuning?

Buzzword with a core

RAG shows up on every AI slide the moment 'AI with your own data' comes up. Almost nobody explains what actually happens under the hood.

Look it up before you answer

RAG first retrieves the relevant pieces from your sources and hands them to the model, so it answers from your data.

The win is in the retrieval

A model with good retrieval answers from your real documents, with fewer made-up facts and a source you can check.

“AI with your own data” usually means RAG

The moment a company wants an AI that knows its own manuals, contracts or tickets, the word RAG comes up: retrieval-augmented generation. It is on every AI conference slide and in every sales pitch about “a chatbot on your documents”. Like AI agents, it sounds big, while the technique behind it is easy to follow.

The reason is a familiar problem. An LLM knows an enormous amount about the world in general and nothing at all about your business. Ask ChatGPT about your own price list, your delivery terms or the status of order 4815 and it can do two things: say it doesn’t know, or invent a plausible answer. Neither is something you can show a customer.

An LLM has read half the world and never seen your intranet. RAG is the simplest way to fix that: let it pick up the source before it answers.

RAG solves this without touching the model. You train nothing again. At the moment of the question you hand the model the right pieces from your data and let it answer from those.

Retrieval, augmented, generation: three steps

The name is literally the explanation. RAG does three things in a row.

1

Retrieval (looking up)

When a question comes in, the system first searches your sources for the pieces of text that matter most: the few passages that contain the answer, rather than the whole archive.

2

Augmented (adding)

It pastes those retrieved pieces next to the question in the prompt. The model gets the question and the relevant source served together in one go.

3

Generation (writing)

The LLM writes the answer from the source you handed it, rather than from its own memory. The material is sitting right there, and the model phrases it cleanly.

The comparison that makes it click: an open-book exam. Without RAG you have the model take the exam from memory and hope it still knows the material. With RAG you put exactly the right page in front of it and ask it to pull the answer from there. The model doesn’t get smarter. It gets the right material at the right moment.

Without RAG you ask the model to do it from memory. With RAG you slide the right page under its nose. Same AI, an entirely different level of trust.

How retrieval works: embeddings and the vector store

The magic is in step one. How does a system find, in thousands of pages, the three passages that match a question? A plain keyword search falls short, because the customer rarely types the exact words that appear in your document. So RAG searches on meaning, and that runs on embeddings.

An embedding is a piece of text translated into a row of numbers that captures its meaning. Texts about the same thing get numbers that sit close together, even when they share no words at all. “How do I cancel my subscription” and “terminate contract” end up next to each other without a single shared keyword. You store those rows of numbers in a vector database, built to quickly find what lies closest together.

1

Chunking

Your documents get split into bite-sized chunks, a few paragraphs each. Too coarse and you retrieve noise, too fine and the context falls away. This chunking shapes more of the quality than people expect.

2

Turning into embeddings

Each chunk goes through an embedding model and becomes a row of numbers that captures its meaning. Done once up front, and again whenever a document changes.

3

Storing in a vector store

All the number rows go into a vector database. It is built to find, at lightning speed, the chunks that lie closest to a question.

4

Searching at question time

The customer's question becomes a row of numbers the same way. The system grabs the few chunks closest to it and hands those to the model.

The first three steps you do up front, once, and you refresh them when your data changes. The fourth happens live on every question. That is the whole mechanism. No consciousness, no model that “learns your business”, just smart search on meaning with an LLM behind it that phrases the retrieved text cleanly.

RAG or fine-tuning the model?

This is the question that goes wrong most often. If you want an AI to know your data, “train the model on it” feels like the logical route. For almost every case that is the wrong tool. Fine-tuning and RAG solve different problems.

📚

RAG gives the model knowledge

Do you want the AI to know your facts, documents and current figures? That is RAG. You add or replace a document and the answer is right immediately, without retraining anything.

🎭

Fine-tuning changes behaviour

Do you want the AI to hold a fixed tone, structure or language, or learn a very specific kind of task? That is fine-tuning. You shift the way the model answers; the facts it has at hand stay the same.

The difference is fresh versus fixed. RAG fetches the source at the moment itself, so keeping data current is a matter of updating the document. A fine-tuned model has the material baked in at training time and falls behind the moment your prices or terms change. For “the AI has to know our knowledge”, RAG is therefore almost always the starting point, and fine-tuning something you might layer on top only later.

Fine-tuning teaches the model a craft. RAG hands it the right folder. Most companies think they need the first and are actually looking for the second.

Where RAG goes wrong: retrieval is everything

RAG sounds simple and you build a demo in an afternoon. The gap between that demo and a system your customers rely on sits entirely in the retrieval. If step one pulls the wrong chunks, the model writes a fluent, convincing and wrong answer. The model is only as good as what you feed it.

✂️

Bad chunking

Chunks that cut a table or a sentence in half deliver context that is only half right. Half of the RAG problems in practice are really a chunking problem.

🕰️

Stale index

The vector store lags behind your real documents. The model confidently retrieves last year's policy. Keeping it current is an ongoing job, not a one-off import.

⚖️

Too much or too little retrieved

Too few chunks and the answer misses context. Too many and the real passage drowns in noise, so the model goes astray anyway.

📊

No way to measure quality

Without a fixed set of test questions you can't tell whether a change made the answers better or worse. Measuring belongs to RAG, otherwise you steer blind.

That is why a proper source citation matters so much: a serious RAG system shows which document an answer came from, so a human can check it. That is exactly the difference with a bare LLM that guesses convincingly. The engineering sits in making the retrieval reliable and keeping it that way, and that is where we do the real work for clients.

A demo convinces anyone. The real question is whether your system still retrieves the right source a year later, while your documents change every week.

RAG, knowledge graphs and agents

RAG rarely stands alone. It is a building block in the larger AI landscape we wrote about before.

Classic RAG searches a vector store for separate text fragments that resemble the question. That works fine as long as the answer sits in one passage. When it is spread across multiple, connected facts, that approach stalls and you arrive at GraphRAG and knowledge graphs: there the system follows the relationships between facts instead of separate snippets of text. In practice you combine them: vector search to quickly find an entry point, the graph to expand the connections from there.

And in an agentic workflow, RAG is simply one of the tools an AI agent can call. Where one tool sends an email and another creates a ticket, the RAG tool answers the question “what do our own documents say about this?” The agent fetches the fact the moment it needs it, uses it in its next step and keeps its answers grounded that way.

When RAG is worth it

RAG pays off the moment the right answer sits in your text and the model just needs to reach it. The rule of thumb is about where the knowledge lives.

Choose RAG

You have a lot of your own text that matters: manuals, policies, contracts, a knowledge base, support tickets. And you want the AI to answer from it, with a source attached, even when those documents change tomorrow.

🚫

RAG is overkill

The answer already sits in general knowledge the model has anyway, or your question needs no source document at all. Then a retrieval step only adds complexity.

Start as simple as possible here too. A good chunking strategy and a clean source citation take you further than the newest vector database. Every layer you add is also one you have to build, measure and maintain.

Conclusion: let the model look it up instead of guessing

RAG becomes clear once you see it as an open-book exam for an AI. You look up the relevant pieces from your data, hand them to the model and let it answer from those. The model doesn’t get smarter. It gets the right material at the right moment.

🔎

Retrieve, augment, generate

Look up the relevant chunks from your sources, paste them next to the question and let the model answer from them. Three steps, no magic.

📚

Your data without retraining

The model stays untouched. You update a document and the answer is right immediately, with a source you can check.

🎯

The win is in the retrieval

Chunking, refreshing and measuring make the difference between a nice demo and a system your customers can rely on.

Start small, get the retrieval right and give your AI a source to draw from. Then it stops guessing convincingly and starts looking things up.

Frequently Asked Questions

What is RAG?

RAG stands for retrieval-augmented generation. It is a technique where, on a question, an AI system first retrieves the relevant pieces from your own sources, hands them to the language model and lets it generate the answer from those. That way an LLM answers from your documents and data, instead of only from the general knowledge it was trained on. The model is not retrained; it gets the right material handed to it at the moment of the question.

How does RAG work technically?

RAG works in three steps: retrieval, augmentation and generation. Up front, your documents are split into chunks, turned by an embedding model into rows of numbers that capture their meaning, and stored in a vector database. On a question, that question is converted the same way, the system finds the chunks closest in meaning (retrieval), pastes them next to the question in the prompt (augmentation) and lets the language model write an answer from them (generation).

What is the difference between RAG and fine-tuning?

RAG gives a model knowledge, fine-tuning changes its behaviour. With RAG the model fetches the right facts from your sources at the moment of the question, so current data is a matter of updating a document. Fine-tuning adjusts the model itself so it holds a fixed tone, structure or task, but it bakes the knowledge in at training time and falls behind as soon as your data changes. For 'the AI has to know our documents', RAG is almost always the starting point; fine-tuning you layer on top at most later.

Why does an LLM hallucinate less with RAG?

An LLM invents a plausible answer when it is unsure of something. RAG reduces that by handing the relevant source along with the question, so the model draws from real text instead of from its memory. A good RAG system also shows which document an answer came from, so a human can check it. The quality does depend entirely on the retrieval: if the wrong pieces are retrieved, the model still writes a convincing but wrong answer.

What is the difference between RAG and GraphRAG?

Classic RAG searches a vector database for separate text fragments that resemble the question and works well when the answer sits in a single passage. GraphRAG retrieves context by walking a knowledge graph and following the relationships between facts, which is needed when the answer is made up of multiple connected pieces of data. In practice they are combined: vector search quickly finds an entry point, the graph expands the connections from there.

When do I need RAG?

You need RAG the moment you want an AI to answer from your own text: manuals, policies, contracts, a knowledge base or support tickets, with a source attached and even when those documents change regularly. If your question needs no source document, or the answer already sits in the model's general knowledge, RAG only adds complexity. The rule of thumb: start as simple as possible and add RAG only when the right answer truly lives in your documents.

An AI that knows your own documents?

We build the layer underneath a reliable RAG system: the chunking, the embeddings, the source citation and the measurement that keep retrieval sharp as your data changes. From first setup to ongoing management.

Let's discuss your project

From AI prototypes that need to be production-ready to strategic advice, code audits, or ongoing development support. We're happy to think along about the best approach, no strings attached.

010 Coding Collective free consultation
free

Free Consultation

In 1.5 hours we discuss your project, challenges and goals. Honest advice from senior developers, no sales pitch.

1.5 hours with senior developer(s)
Analysis of your current situation
Written summary afterwards
Concrete next steps