Home / Articles

Retrieval-Augmented Generation Explained: Fixing LLM Knowledge Gaps

Why LLMs hallucinate and go stale, and how retrieval augmented generation fixes it step by step: chunking, embeddings, retrieval and augmenting the prompt.

Publisher: REACTAPP.TOP5 min read1205 words

This article is published in English.

Sources: What LLMs Often Get Wrong At, And How RAG Cures That

Where LLMs tend to stumble

Think about final oral exams. You cram everything the night before, walk in, talk confidently to the examiner, and hope it goes well. Then the examiner asks, "Why did you choose that particular approach in your project?" Suddenly the room goes silent.

LLMs run into the same wall.

They're built to produce answers that sound convincing. Which means they often don't know how to admit "I don't know."

There's also the issue of stale knowledge.

Imagine that same examiner asking:

"Why did you pick that method when a better one exists now?"

You'd be stuck.

LLMs hit this exact problem whenever the facts they were trained on no longer reflect reality.

So the real question becomes: How do you supply an LLM with the right facts, exactly when it needs them?

Enter Retrieval-Augmented Generation

Don't let the name scare you. It's really just a straightforward workflow: locate the relevant information, hand it to the model, and let the model turn it into an answer.

That's the whole idea.

Let's unpack what actually happens behind that description.

Framing the problem

Suppose you're building an internal AI assistant for a company.

That company has a pile of documents: an employee handbook, internal FAQs, security policies, and so on.

Once the assistant is live, people will naturally start poking at it. Someone types in:

"How many days of parental leave am I entitled to?"

The trouble is, the model has no built-in awareness of your company's specific policies. And you can't just shove hundreds of lengthy documents into the prompt and expect a clean answer — doing so risks overloading the context window, confusing the model, and other issues.

How RAG actually works

Rather than relying on the LLM's internal knowledge to answer, we first pull relevant material from our own knowledge base. That material is then handed to the LLM.

The LLM uses this supplied information to craft its answer.

In other words, the model doesn't need to memorize everything. It just needs the correct information delivered at the correct moment.

Which raises the next question: how do you decide what counts as relevant in the first place?

Retrieval

Sending every document to the LLM for every single question would be wasteful and slow. So instead, you need a way to isolate the relevant fragments first, since scanning everything each time is expensive and inefficient.

To do this, documents get broken into smaller pieces known as chunks. One chunk might cover parental leave rules, a different chunk might describe security procedures, and yet another might lay out how expense reimbursements work.

Locating the correct chunk

A user might phrase their question as: "How much time off can I take after having a baby?"

Meanwhile, the document itself might say: "Employees are entitled to 26 weeks of parental leave."

The wording differs, but the meaning is identical. To bridge this gap, RAG systems rely on embeddings.

What embeddings do

An embedding turns a piece of text into a set of numbers that encodes its meaning. Text with similar meaning ends up positioned close together in this numerical space — measured using something called vector distance, which is basically a way of quantifying how far apart two vectors sit.

These embeddings live inside a vector database. When a new question arrives, it too gets converted into an embedding, and the system searches for the nearest matching chunks.

The result is a set of relevant chunks, which then get forwarded to the LLM as supporting context.

Augmentation

Once the relevant chunks are identified, the next step is combining them.

They get inserted into the LLM's context window together with the original question:

Context:
Employees are entitled to 26 weeks of parental leave.

Question:
How long can I stay away from work after having a baby?

At this point, the LLM has everything it requires to respond accurately.

Generation

Now comes the part the LLM excels at: producing the actual answer.

It reads both the user's question and the retrieved context, then generates a reply:

"You're entitled to 26 weeks of parental leave."

And that completes the cycle: Retrieve → Augment → Generate.

The catch

The LLM can only reason using whatever context gets retrieved. If the wrong chunk gets pulled, the final answer can still be incorrect even though the process worked correctly.

Consider this scenario:

Question: "How long is parental leave?"

Retrieved chunk: "Notify your manager 30 days before taking parental leave."

Resulting answer: the assistant tells the employee that they must inform their manager a full month in advance of starting parental leave — technically related to the topic, but not actually answering how long the leave lasts.

Improving retrieval quality

So how do you ensure the retrieval step surfaces the right material?

A handful of factors matter here:

Chunking strategy: How documents get split affects whether related context stays intact within a single chunk.

Embedding quality: Stronger embeddings make it easier to align a user's question with the content that actually answers it.

Search technique: Combining semantic similarity search with traditional keyword search helps capture both meaning and exact phrasing.

Reranking: Pull in an initial batch of candidate chunks, then apply a second ranking pass to surface the most useful ones.

The underlying goal stays simple: place the correct context in front of the LLM.

Wrapping up

RAG isn't some magical trick.

Locate the right information. Hand it to the LLM. Let the model generate the answer.

That's the entire mechanism.

The LLM was never required to know everything upfront.

It only needs the right context, delivered at the right time.

And that's the core principle behind RAG: garbage in leads to garbage out, and quality input leads to quality output.

Now, whenever someone mentions "RAG this, RAG that," you'll know exactly what they're talking about.