Piero Savastano
What Is RAG?

What Is RAG?

July 16, 2025
4 min read
Table of Contents
index

How does GPT, how does artificial intelligence, learn from the PDF we upload to it, from the document, from the web page? That is the same as asking: what is RAG?

RAG stands for Retrieval Augmented Generation. The acronym looks complicated, but it actually tells you everything you need to know.

Start from the language model

Let us start with the language model itself. GPT, Llama, Claude, Gemini, whatever you like, Qwen, DeepSeek. These are trained. They are neural networks, simulations of nervous tissue, and they are trained to do what? To pick the next word, to line words up, to continue the text. That is the best definition, because if you start saying it understands, it converses, it is intelligent, you lose the plot. The best way to look at them, to understand how they work, is to see them as a kind of autocomplete that works extremely well.

And it ends up understanding the text, because to figure out the next word it has to interpret all the previous words deeply. In that sense it comprehends, or better, it compresses. Compression versus comprehension. So that is the language model.

The problem: it cannot know your stuff

Now, if I take this language model, trained on the text that is on the internet, and I hand it a PDF, how do I hand it that PDF? How is it supposed to know that I designed a new galactic toothbrush for NASA? The galactic toothbrush is not on the internet yet. Nobody has ever written about it, on any page, in any book. A model trained on the text that exists on the web simply cannot know it.

So what happens? I insert context data, the extra information I want the language model to take into account. I inject it into the prompt. The prompt is the input that reaches the model. When I ask GPT what budget is planned for the space toothbrush, GPT does not know. If I send it that prompt directly, it has never heard of space toothbrushes, it is a brand new project we are doing for NASA, so it cannot answer. At best it hallucinates and makes something up.

The trick: put the answer next to the question

So what do I do? Before sending the prompt to GPT, I take my question and the conversation so far, and I add a context section to the prompt. I say: you are an intelligent agent, you have to help the user, this is the conversation so far, here is the back and forth between user and AI, and here is the context. And I tell the assistant: when you answer the user, take this context into account. Into that context I slip the space project, so that the prompt reaches the language model with both the question and the potential answer inside it.

People imagine it is far more complicated than this. It really is that simple. The entire industry is moving on this principle of context engineering, which means putting the relevant information into the prompt.

Scaling it up

To take it one step further: how do I make GPT aware of all the company documentation, or of everything on the web the way Perplexity does, answering through content that lives online? Same principle. That is RAG. Retrieval Augmented Generation. Generation is what the language model does, it generates text. Augmented means the generation is boosted by something, made better by something. By what? By retrieval. I go and fish relevant content out of a database or a search engine, and then I slip it into the prompt, so the language model has the potential answers right there in the prompt itself. That is Retrieval Augmented Generation.

The Cheshire Cat, a hugely relevant Italian open source project, born right here in front of you but then completely out of control, is one of the first open source RAG projects in the world.