$10K cash or $15K in credits. Enter by 15 Dec →

What is RAG (retrieval-augmented generation)?

First published

Reviewed by Matt Swulinski, Head of Growth at Viktor on

The short answer

Retrieval-augmented generation, or RAG, is a way to look up facts for an AI model, the software that writes a reply. Software finds source text and sends the useful parts with the question. The model then has facts beyond its training, the process of learning patterns from examples. A business can use RAG to answer from a changed rule without training the model again.

How does a document become part of an answer?

A new hire asks whether a trip to a client site needs sign-off. A useful answer needs the firm's travel rules, not a guess. The model needs to read the rule and the cases where it doesn't apply.

Some work happens before the question arrives. Other work happens when someone asks. A setup that searches stored files can work like this:

  1. Prepare the files. Software pulls out readable text and splits long files into smaller parts called chunks. A rule should stay close to the cases where it doesn't apply. Each chunk needs a route back to its source.
  2. Make the text searchable. An embedding model turns each chunk into a list of numbers called a vector. The numbers represent features of the text's meaning. Software stores these vectors in an index, a structure built for lookups.
  3. Find possible matches. Software turns the question into a vector in the same form and searches for nearby chunk vectors. That can match a question about travel permission with text about sign-off, even without the same words.
  4. Choose what to supply. A system can combine meaning-based matches with keyword matches, which help find exact terms. A further scoring step, called reranking, can move more useful chunks ahead of weaker matches.
  5. Write from the source text. Software adds the chosen chunks to the question and rules sent to the model. The model writes an answer from that input. The system can include source links so a person can open the file behind the reply.

Those are separate retrieval and generation stages: finding text, then writing from it. The vector helps find text. The text itself supplies the facts the model can use.

RAG doesn't always need vector search. Keyword search and combined search methods can fetch text too. A search tool becomes part of RAG when the text it finds feeds the model's answer.

The model has a limit on how much input it can receive at once, called its context window. Fetching focused chunks leaves room for the question and rules. A missing exception can change the answer, so check which chunks reach the model.

When a policy changes, the searchable copy and its vectors need updating. Ask when that happens before relying on an answer about a changed rule.

What is the difference between RAG and fine-tuning?

A revised travel rule changes what the model needs to read. A set style for travel replies changes how you want the model to write.

RAG looks up outside facts, while fine-tuning trains a model further using examples. Fine-tuning changes some or all of the model's learned settings, called parameters. Adding source text to a request doesn't, by itself, change those settings.

Question

RAG

Fine-tuning

What changes?

The source material supplied for an answer

The model's learned settings

When does that happen?

During retrieval for a request

During a training process

What could it help with?

Looking up the current approval rule

Learning a required reply style from examples

What needs maintenance?

Searchable sources and retrieval

Training examples and the trained model

Both can work together. A fine-tuned model can still receive text from a travel policy. For a rule that changes, start by checking whether the right current text reaches the model.

Memory keeps facts for later use, while retrieval finds facts to supply now, which can include saved memories.

Where can RAG give the wrong answer?

A search can find an old travel policy that looks much like the current one. The model can then write a clear, well-sourced answer using the wrong rule.

The search and the answer need separate checks. First, did the right text reach the model? Then, did the model use that text correctly? A citation, a link to a source, helps locate proof but doesn't show that the source supports every part of the reply.

Chunks can also lose meaning. If software splits a rule from the exception beneath it, a search can return only the rule. Large chunks can bring in text about other topics instead. Keep a test question whose answer depends on an exception when checking how files are split.

RAG cannot make a model error-proof. The source text can be wrong or lack needed facts, and the model can still write a claim without proof. For a missing rule, an answer that admits the gap is more useful than a guess.

Private files add an access problem. The search system must enforce who can read each source. Without those checks, an answer can expose facts the person asking wasn't allowed to see.

Source text can also contain harmful instructions planted by an attacker. Access controls and source checks are still needed when files feed an AI response. A useful match doesn't make a source safe to trust.

What would RAG look like in a new hire's first week?

In a made-up example, a team lead asks for a draft reply to a new hire planning a customer visit. The new hire wants to book travel directly.

The system searches the travel policy and finds a passage requiring approval before booking. It also retrieves the nearby exception for urgent visits. The draft explains the approval rule and links to the policy instead of inventing permission.

Now change the test. Remove the exception passage and ask about an urgent visit. Does the reply flag missing information, or confidently apply the ordinary rule?

Then replace the searchable policy with an older version. Check whether the draft identifies which version supports its advice. These tests expose different faults: a missing passage and an outdated source. Neither calls for a better writing style.

How does Viktor use sources?

Viktor searches the web and answers with sources.

Viktor's product overview

Common questions

What is agentic RAG?

Agentic RAG can use a model to plan what to look up before writing an answer. A multi-query retrieval design can split a hard question into smaller searches, then bring the results together. That extra planning can add waiting time compared with a single search.

Does RAG require a vector database?

No, RAG needs useful source text, but keyword search can supply it too. A vector database stores and searches vectors to find matches in meaning. Keyword search helps match exact terms. A system can combine both methods before supplying text to the model.

Does RAG train the model on my documents?

No, sending source text for an answer doesn't itself train the model on those files. Looking up facts and training are separate processes. That doesn't tell you a service's privacy policy: check the provider's data terms before sending private files.

What Viktor can do

Get Started for Free