What is RAG? How to Feed Knowledge to Artificial Intelligence

Cezary Klauza
Created at 6/9/2025

A few years ago, chatting with AI was like talking to a very eloquent but kinda clueless friend. It could talk a lot — but not always make sense. The answers? Often made up. Facts? Well… not always reliable. Back then, language models only knew what they were trained on. Nothing more.
But that changed.
Today, we have something way cooler — thanks to a technique called RAG.
RAG? What’s that?
RAG stands for Retrieval-Augmented Generation.
Sounds fancy? Don’t worry, it’s simpler than it looks.
Before, AI only knew what was in its “brain” (the trained model). Now? It can look up info from your own knowledge base — and answer based on what it finds there.
It’s like talking to a consultant who doesn’t have all the answers off the top of their head but does have access to a well-organized archive and knows exactly where to look.
How does it work?
Imagine you have a document. Or a PDF file. Or some data in your database.
For AI to use it, it first needs to understand what it means. And to understand — it has to turn it into something it can analyze.
That something is a semantic vector.

What’s that?
Imagine every sentence is a point in a meaning-space. Two sentences with similar meaning — even if they use different words — will be close together. For example:
“Aww man!” and “Ouch!” — different words, but in the right context, they mean pretty much the same thing. Their vectors will be close, too.
Are these vectors like math vectors?
Well… not quite.
In math, we learn 2D or 3D vectors — up, down, left, right.
In AI, vectors can have hundreds or thousands of dimensions.
Yep, you read that right — a vector with 768 dimensions is common.
Ok, so what happens with the document?
You split the document into smaller chunks — sections. But not just any chunks!
Ideally, each piece has a coherent meaning.
(You don’t want half of one product description mixed with half of another — that would confuse the AI).
Each chunk goes through an embedding model — which turns it into a vector.
These vectors go into a vector database — like Pinecone, Weaviate, or even PostgreSQL with pgvector extension.
When a user asks a question, it’s also turned into a vector.
The system searches the database to find chunks whose vectors are closest to the question’s vector.
The found chunks are passed to a language model (like GPT), which builds a sensible answer based on them.
Simple, right?
Real-life example
Someone asks your AI:
“What shipping options do you offer?”
The model doesn’t know the answer offhand. But it queries the knowledge base, finds the section about shipping prices and rules, and replies:
“We offer courier delivery within Poland within 1–2 business days. You can also pick up your order personally in Krakow.”
Boom. AI just helped your customer — using your own knowledge.
How to improve this process?
Instead of chopping text every 250 words blindly, it’s better to split it semantically — so each chunk makes sense. You can even use another AI to do that.
Really.

Split text → embed → save to database → quick context lookup → accurate answer.
And because you return only the necessary chunks, it works faster, cheaper, and with less token usage.
To sum up:
RAG is a way for AI to access knowledge it wasn’t explicitly trained on.
And most importantly — to avoid making stuff up by citing trusted sources instead.
If you’re building AI assistants, website bots, or smart document search — RAG is your best friend.