Building with AI

What is RAG (retrieval-augmented generation)?

In short

RAG (retrieval-augmented generation) is a method where an AI first looks up relevant text in your own documents and then writes its answer based on what it found.

A language model alone only knows what it learned in training. With RAG, the question is used to search a document collection, the best matching passages are added to the prompt, and the model answers from them, often with references. Facts can be updated just by updating the documents.

Mini course

3 short lessons, about 2 minutes in total

  1. Look it up, then answer
  2. How the pieces work
  3. Getting good results

Lesson 1

Look it up, then answer

Retrieval-augmented generation (RAG) gives a language model access to information it was not trained on: your manuals, policies, product sheets and past cases. When a question comes in, the system first searches those documents, picks the most relevant passages, and adds them to the prompt. The model then answers from that material and can cite it.

With RAG, the model reads your current documents instead of guessing from memory

Model aloneModel with RAG
Knows only what it learned in trainingReads your documents when the question comes
Cannot show where an answer came fromPoints to the passage it used
New facts mean a new modelNew facts mean adding a document

It is like letting the model take an open-book exam.

Lesson 2

How the pieces work

Documents are split into chunks, a few paragraphs each. Each chunk is turned into an embedding and stored, usually in a vector database. A question is embedded the same way, and the closest chunks are found. Good systems combine this meaning-based search with keyword search and re-rank the results before passing the best few to the model.

Model + passages
Answer with sources
RAG first searches your own documents for the passages that matter, then gives them to the model so it answers from facts, with sources

Tap a box to open that concept

When content changes, you update the documents, not the model.

Lesson 3

Getting good results

Most RAG problems are search problems: the right passage was never found. Clean, current, well-structured documents matter most. Choose sensible chunk sizes, keep titles and dates with each chunk, and test search on real questions. Tell the model to answer only from the passages and to say when the answer is missing. Respect access rights, so people only get answers from documents they may see.

  1. Customers find youHow customers and AI tools find the companySEOGEOGoogle AI Overviews
  2. AI in daily workTools staff and customers useChatbotAI copilotVoice AI
  3. Building blocksHow AI connects to data and systemsRAG (retrieval-augmented generation)AI agentMCP (Model Context Protocol)
  4. AI modelsThe models that understand and createLarge language model (LLM)Generative AIMachine learning
  5. DataCompany data, gathered and cleanedData warehouseETLData quality
  6. InfrastructureCloud, networks and systems underneathCloud computingDatabaseAPI key
Trust and rulesSecurity, law and control in every layerGDPR and AIEU AI ActAI guardrails
Where RAG (retrieval-augmented generation) sits in a company's AI setup

This website's chatbot is a small RAG system over the site's own pages.

An everyday example

An employee asks "how many vacation days do I get after five years?" and the assistant finds the right section of the staff handbook and answers from it.

How companies use it

Companies use RAG for internal knowledge assistants, customer service bots that answer from product manuals and tools that search contracts.

Frequently asked questions

Is RAG better than fine-tuning?

For facts and documents that change, usually yes. Fine-tuning is better for style and format.

Does RAG stop hallucinations?

RAG reduces hallucinations a lot but does not stop them fully. Showing sources lets people check the answer.

Can RAG respect who may see what?

RAG can respect who may see what, if built so that the search only returns documents the user has access to.

In depth: RAG

The full picture, about 5 minutes of reading

The problem RAG solves

A language model learns from a huge snapshot of text, and then its knowledge is frozen. It has never seen your price list, your staff handbook, last week's product update or the contract you signed in March. Ask it about those things and it has two bad options: say it does not know, or guess. Guessing is where made-up answers, often called hallucinations, come from.

Retraining a model every time a document changes is slow and expensive, and it still would not tell you where an answer came from. RAG takes a simpler route. Instead of changing what the model knows, it changes what the model reads right before it answers. The model gets the relevant pages handed to it, like an employee who checks the binder before answering a customer.

What happens, step by step

First, your documents are prepared. They are split into chunks of a few paragraphs, because a whole manual is too much to hand over at once and a single sentence has too little context. Each chunk keeps its title, date and where it came from.

Second, every chunk is turned into an embedding: a list of numbers that captures what the text means. These are stored in a search index, often a vector database. Many systems also keep a normal keyword index next to it.

Third, when a question comes in, it is turned into an embedding the same way, and the system finds the chunks whose meaning is closest. Good systems combine this with keyword search, so exact terms like product codes are not missed, and then re-rank the results to keep only the best few.

Fourth, those chunks are placed in the prompt together with an instruction such as: answer only from these passages, say so if the answer is not there, and name the source. The model writes the answer, and the user sees which documents it used.

Why it works better than the alternatives

Compared with asking a model directly, RAG answers from your facts instead of from general knowledge, and it can show where each answer came from. That makes answers checkable, which matters more than it sounds: people trust a tool they can verify.

Compared with fine-tuning, which means training an existing model further on your own examples, RAG is cheaper to keep current. When a policy changes, you replace the document and the next answer uses the new version. Fine-tuning is better at teaching a model a style, a format or a narrow skill, and the two can be combined, but for facts that change, RAG is usually the first choice.

Compared with pasting whole documents into a chat, RAG scales. A chat window can hold a lot of text today, but not every document a company owns, and filling it with irrelevant pages makes answers slower, more expensive and often worse.

Where it goes wrong

Most failures are search failures. If the right passage is never found, the model cannot use it, and a polite wrong answer follows. Common causes are messy source documents, several versions of the same file, scanned PDFs without real text, tables that lose their structure when split, and chunks cut in the middle of a thought.

The second group of problems is about instructions. If the model is not told to stay within the passages, it fills gaps from its own knowledge. If it is not told to admit when the answer is missing, it rarely does.

The third is access. A RAG assistant that searches everything can reveal salary data or customer details to people who should not see them. The search step must respect the same permissions as the original systems, so each person only gets answers from documents they are allowed to open.

Finally, RAG reduces made-up answers but does not remove them. Showing sources, testing on real questions and letting users flag wrong answers are what keep quality up over time.

What it takes to build one

A useful first version is smaller than most people expect. Pick one clear area, such as the staff handbook or the product documentation, where questions repeat and answers exist in writing. Clean up the documents first: remove old versions, make sure scanned pages are readable and give each file a clear title.

Then collect 30 to 50 real questions people actually ask, with the correct answers. These become your test set. Build the search, connect a model, and measure how often the right passage is found and how often the answer is correct. Improve the documents and the chunking before you change the model, because that is where most gains come from.

Once it works, decide who owns the content. A RAG assistant is only as current as its documents, so someone must keep them updated. Add a simple way for users to say an answer was wrong, review those cases regularly, and expand to the next document area only when the first one is trusted.

What it means for a small business

For a smaller company, RAG is usually the most practical way to get real value from AI on its own information. Typical first projects are an internal assistant that answers questions about routines and policies, a customer service chat that answers from product sheets and terms, and a tool that finds clauses across contracts.

The benefits are concrete: fewer interruptions for the people who always get asked, faster answers for customers outside office hours and less time spent searching through folders. The risks are also concrete: outdated documents give outdated answers, and poor access control can leak information. Starting small, testing on real questions and keeping a person responsible for the content handles most of that.

The chatbot on this website is a small example of the same idea: it answers from the site's own pages and links to them, instead of answering from general knowledge.

Curious what this could mean for your company? Book a call.

Book a call