Skip to content
AI for Beginners

What is RAG?

Intermediate4 min read

RAG is a way of giving AI a reference library to check before it answers, so it works from real documents rather than memory alone. In this guide you will learn what it is, how it works at a high level, and why it makes AI answers more trustworthy.

In this guide, you will learn what RAG is, how it works in plain terms, and why it makes AI answers more reliable. This one takes a little time to click, so read it once, then come back if you need to.

The problem it solves

By now you know that a large language model, the engine behind chat tools, answers by predicting likely text from everything it read during training. That makes it fluent, but it has two weak spots. It does not know anything that happened after its training, and it has no reference to check itself against, so it can produce a confident answer that is made up entirely, a slip known as a hallucination.

Imagine asking a very well-read colleague about your company’s own refund policy. They are brilliant in general, but they have never seen your policy, so they give you a plausible-sounding guess. The problem is not their intelligence. It is that they are working from memory instead of the document that actually holds the answer.

The idea: give it a reference library

Here is the fix. Before the AI answers, you let it look things up in a collection of documents you trust, and you ask it to base its answer on what it finds there. In short, you give the AI a reference library to check before it speaks. This approach is called Retrieval-Augmented Generation, or RAG.

The name spells out the two halves. “Retrieval” is the looking-up step: finding the handful of relevant passages from your library. “Generation” is the familiar part: the AI writing an answer. RAG stitches them together, so the AI writes its answer using the passages it just pulled, not from memory alone.

Going back to the colleague: instead of asking them to recall your refund policy, you hand them the actual policy document, ask them to read the relevant section, and answer from that. Same colleague, far more trustworthy answer.

How the looking-up works

The clever part is how the system finds the right passages. It cannot read your whole library for every question, so it needs a fast way to match your question to the passages most likely to answer it.

To do this, both your documents and your question are turned into a kind of numerical fingerprint that captures their meaning, something called an embedding. Passages that mean similar things end up with similar fingerprints, so the system can quickly grab the ones that sit closest to your question. Those become the reference material the AI reads before answering. The next guide unpacks embeddings properly, so do not worry if that part is still hazy.

Why it makes answers more trustworthy

RAG helps in two clear ways. Because the AI is answering from real documents you chose, it is far less likely to invent things, which cuts down on hallucination. And because you control the library, you can keep it current and specific: your policies, your product manuals, this month’s figures.

It also brings a quiet bonus. A good RAG system can point to which document an answer came from, so you can check the source yourself. That shift, from “trust me” to “here is where I got this”, is a large part of why RAG is so widely used in serious tools.

Try it yourself

You can experience the heart of RAG by hand, without any special software. Find a document you know well, a policy, a manual, a long email thread, and paste a chunk of it into an AI chat tool along with a question:

Using only the text below, answer this question: what is the deadline for
returns? If the answer is not in the text, say so rather than guessing.

[paste the relevant section of your document here]

By giving the AI the source and telling it to answer only from that, you are doing in miniature what a RAG system does at scale. Notice how much more you trust an answer you can trace back to the text in front of you.

A useful clarification

A common misunderstanding is that RAG retrains or changes the AI itself. It does not. The model stays exactly as it was. All that changes is what you place in front of it at the moment you ask, the retrieved passages, which is why RAG can work with a fresh document five minutes after you write it.

If you would like to explore building something like this yourself, the hardest part is often finding good source material. Our sister site rag-repo.org keeps a curated directory of open data sources to get you started.

Next steps

The one piece we glossed over is how text gets turned into those meaning-based fingerprints that make the looking-up fast. That is the idea of embeddings, and it is genuinely fascinating once it clicks. We turn to it next.

Try it yourself

Put this into practice with a ready-made prompt.

AnalysisBeginner

Document Summariser

Turn a long document into a clear summary at the length, focus, and reading level you need, so you can grasp the key points fast.

Use this prompt →

Next upWhat are embeddings?