Zohreh Razavi
Pixel portrait of Zohreh Razavi

NOTES

What Is RAG? A Simple Explanation of Retrieval-Augmented Generation

By Zohreh Razavi

AI assistants can answer many questions, but what happens when you want an AI to answer questions about your own information?

For example, imagine you have a company website with information about your products, services, prices, and policies. You want visitors to ask questions and get answers based only on your company’s information.

This is where RAG comes in.

RAG stands for Retrieval-Augmented Generation. It is a way to connect an AI model to your own data.

In simple terms:

RAG finds the right information first, then gives it to the AI so the AI can answer the question.

Why Do We Need RAG?

An AI model already knows a lot of information because it was trained on a large amount of data.

But it does not automatically know:

  • Your company’s internal documents
  • Your latest product information
  • Your company’s policies
  • Your private PDFs
  • Your customer-specific information

For example, imagine you have this sentence in your company document:

“Customers can return a product within 30 days of purchase.”

A normal AI model may not know this specific company policy.

With RAG, we can give the AI access to your documents.

Then, when someone asks:

“How many days do I have to return a product?”

The RAG system searches your information, finds the relevant sentence, and gives it to the AI.

The AI can then answer:

“You can return the product within 30 days of purchase.”

How Does RAG Work?

A simple RAG system has three main parts:

Your Data → Search → AI

But there are several steps behind this simple flow.

Let’s look at them one by one.

Step 1: Start With Your Data

First, we need some information.

This could be:

  • PDF files
  • Word documents
  • Website content
  • Product information
  • Company policies
  • FAQs
  • Internal documents

For example, imagine we have this document:

Company Return Policy Customers can return products within 30 days of purchase. The product must be unused and in its original packaging. Customers need to provide their receipt.

This is normal human-readable text.

The computer can store it as text, but that is not the best format for an AI system to search.

So we process it.

Step 2: Split the Data Into Smaller Pieces

Large documents are usually divided into smaller pieces called chunks.

For example, our document could be divided into:

Chunk 1

Customers can return products within 30 days of purchase.

Chunk 2

The product must be unused and in its original packaging.

Chunk 3

Customers need to provide their receipt.

Why do we do this?

Because when a user asks a question, we usually do not need the entire document.

We only need the parts that are relevant to the question.

Step 3: Turn Text Into Numbers

This is one of the most important parts of RAG.

Computers do not understand text in the same way humans do.

So we convert each piece of text into a group of numbers called an embedding.

For example:

“Customers can return products within 30 days of purchase.”

could become something like:

[0.21, -0.45, 0.78, 0.12, -0.33, ...]

This list of numbers represents the meaning of the text.

Another sentence:

“Products can be returned within one month.”

might become another list of numbers:

[0.20, -0.43, 0.75, 0.15, -0.31, ...]

The numbers are not meant to be read by humans.

They are used to represent the meaning and relationships between pieces of text.

Because these two sentences have similar meanings, their embeddings will also be relatively close to each other.

Step 4: Store the Embeddings in a Vector Database

Now we need somewhere to store these embeddings.

This is where a vector database is used.

For example, we can store:

Text Embedding
Customers can return products within 30 days. [0.21, -0.45, 0.78, ...]
Product must be unused and in original packaging. [0.14, -0.20, 0.61, ...]
Customers need to provide their receipt. [0.30, -0.15, 0.42, ...]

The vector database allows us to search these numbers based on their similarity.

So instead of searching only for exact words, we can search for similar meaning.

Step 5: A User Asks a Question

Now imagine a customer asks:

“Can I send the product back after three weeks?”

The question is also converted into an embedding.

For example:

"Can I send the product back after three weeks?"



[0.22, -0.44, 0.76, ...]

The system compares this embedding with the embeddings stored in the vector database.

It may find that this question is very similar to:

“Customers can return products within 30 days of purchase.”

That information is retrieved.

Step 6: Give the Retrieved Information to the AI

Now we have the relevant information.

Instead of asking the AI:

“Can I send the product back after three weeks?”

we give the AI both the question and the information we found:

Relevant information: Customers can return products within 30 days of purchase.

Question: Can I send the product back after three weeks?

The AI can now generate an answer based on the retrieved information:

“Yes. You can return the product within 30 days of purchase, so three weeks is within the allowed return period.”

This is the Generation part of Retrieval-Augmented Generation.

The Complete RAG Flow

The whole process looks like this:

YOUR DOCUMENTS

Split into chunks

Create embeddings

Store in vector database


USER ASKS A QUESTION

Create an embedding for the question

Search the vector database

Find the most relevant information

Send the information + question to the AI

AI generates the answer

USER GETS THE ANSWER

A Simple Real-World Example

Imagine a company has 500 PDF documents.

One document contains this information:

“Employees can work remotely up to two days per week.”

The company creates a RAG system using these documents.

An employee asks:

“How many days can I work from home?”

The RAG system does not search for exactly the same sentence.

Instead, it looks for information with a similar meaning.

It finds:

“Employees can work remotely up to two days per week.”

Then the AI receives this information and answers:

“Employees can work remotely up to two days per week.”

The user does not need to know where the information came from or how the vector database works.

They simply ask a question and get an answer.

Why Not Just Give All the Documents to the AI?

This is an important question.

Imagine you have 10,000 documents.

You could try to send all of them to the AI every time someone asks a question.

But this would be inefficient.

There would be too much information, and it would also increase the amount of data the AI needs to process.

RAG solves this problem by finding only the most relevant pieces of information.

Instead of:

10,000 documents → AI

we have:

10,000 documents → Search → Relevant information → AI

This makes the system much more practical.

RAG vs. a Normal AI Chatbot

A normal AI chatbot mainly relies on the knowledge it learned during training.

A RAG chatbot can use external knowledge at the time of the question.

For example:

Normal AI

User:

“What is our company’s refund policy?”

AI:

“I don’t have access to your company’s internal refund policy.”

RAG AI

User:

“What is our company’s refund policy?”

RAG:

Finds the relevant company policy.

AI:

“According to the company policy, customers can request a refund within 30 days.”

The Most Important Idea

You do not need to train the AI model again every time your documents change.

Instead, you can update the information used by the RAG system.

For example, imagine your company changes its return policy:

Old information:

“Customers can return products within 30 days.”

New information:

“Customers can return products within 60 days.”

You can update the relevant data in the knowledge base.

The AI can then retrieve the new information when answering questions.

This makes RAG especially useful for information that changes over time.

In One Sentence

If we want to explain RAG as simply as possible:

RAG is a system that searches your own data for relevant information and gives that information to an AI model so it can generate a better answer.

Or even more simply:

Search first. Answer second.

That is the basic idea behind Retrieval-Augmented Generation.

If you are also choosing between RAG and training a model, read RAG vs. Fine-Tuning: What Is the Difference?.