RAG Explained: Retrieval, Augmentation, Grounding & Long-Context Prompting

Oh ho, the real journey you were waiting for!
We have made the application manually, and using AI as well, where we were just writing prompts and everything was being built automatically using an AI editor.
But it was done using the knowledge AI already had. AI ymeans the encyclopedia of information it was trained on, and that was the central information. If the information is not correct, then what?
Central information means what the company model was trained on.
So, what is RAG? What is this term? Giving AI knowledge? Is AI knowledge not sufficient?
All this we are going to explore now. So, without wasting our time, chaliye shuru karte hain!
Okay, AI has knowledge, we know. But we can also provide knowledge.
First, let me make you understand with a very small, basic example.
Suppose you are hiring a marriage event manager. He manages everything well because he has the knowledge of how to do what, when, and how. He has his own knowledge base of doing things.
But it's your marriage, baba, correct? You know the place, the guests, and all the information that is in your head. You will provide that information to the manager, correct? So that manager can do things and answer specific questions, isn't it?
So, the manager has his own information, which is correct, but you also provide something extra to him to act on. This way, it is similar to giving knowledge to a manager or giving knowledge to AI.
The same goes for a restaurant example, if you take it. The way a chatbot acts in a generic way, but based on your information, when you go to a support system and complain about anything, it acts like it knows your information.
And believe me, these days, companies are hiring engineers who know how to build RAG systems. Got it?
So, we repeat: the knowledge that the system has no idea about, we provide our own knowledge so that the system we build can act based on our things. This is what RAG solves.
Now, I hope you understood both the problem and the solution. Okay, let's proceed!
What if you want one more example?
You chat with ChatGPT and ask, "Where is my Amazon order?" It will not be able to answer, right?
But if you ask the same question to Amazon Support, it will be able to answer, right?
The answer from AI will be generic, but Amazon Support will be able to act on your information. This is where RAG comes in.
Even on the website where you are learning courses, NamasteDev, there is also a RAG-enabled chatbot.
If you ask any question like, "Where was this topic taught by Akshay Saini?", it will tell you the exact timestamp, and you can watch by going to that specific episode.
So, this is amazing, correct?
And the same question asked to ChatGPT, DeepSeek, or Gemini — no one can answer!
Below, you can see in the screenshot that I asked about MongoDB installation, and it answered with the exact timestamp. AI is answering, but using my private information!

So, the AI model gets connected to documents and lots of information that is not publicly available, which the company provides so it can act on that information!
A search engine has no information about that, so how will the AI model grasp it, right?
Now, let's discuss more about the problems.
The problem?
Let's discuss what problems RAG is solving.
First, it solves the knowledge cutoff problem! Because this is one of the limitations of LLMs. An LLM has knowledge based on the data it was trained on, up to a certain point. But now, we can provide more information to the LLM without retraining the model.
It also helps reduce hallucinations. What is hallucination? We discussed this in one of our previous episodes. In simple words, when an LLM gives you an answer that sounds very confident but is incorrect or made up, that is called hallucination.
Because of RAG, we provide additional information to the LLM, so it can answer more accurately using that information. This reduces the chances of hallucination, but it does not eliminate them completely.
And one more thing: you might think you can provide 3–4 documents directly to the LLM, and it will answer everything. But that's not always practical. You cannot keep providing hundreds or thousands of documents to an LLM every time you ask a question.
Also, every LLM has a context window, and there are limitations. You cannot simply provide 100 GB of data to an LLM in one go. This also creates problems with scalability and cost.
RAG helps solve these problems as well. How? We will learn in some time.
But for now, understand what problems RAG is solving.
What is RAG?

Ohk, ohk! Let's go more academic! He he.
The full form of RAG is Retrieval-Augmented Generation. What the fake? I did not understand! Is it really so complicated? It's not even rhyming! Hahahaha! Teeno bhai (words), teeno tabahi! Hahaha!
Okay, let's focus. No more jokes, be serious.
The last word, you know, is Generation. It means getting or generating something. Same as GPT, LLMs, right?
What is Retrieval? Retrieval is nothing but a synonym for fetching or getting something. Retrieving means taking something or extracting something. Got it?
Now, the middle word, Augmented. What's Augmented?
RAG stands for Retrieval-Augmented Generation, and augmentation means adding or combining extra information to enhance or improve something, In AI, RAG lets a large language model (LLM) pull fresh or specialized facts from an outside source—like documents or a database—and attach that context to your prompt before generating an answer.
So, Augmenting means we are enhancing something.
So overall, it means there is private information, we need to retrieve relevant information from it, enhance it, and generate an answer.

So, from the above image, you can relate to the main theme. The prompt was, "How many leaves can I take in a month?"
So, retrieval will happen across a large dataset, fetching relevant information, and then it will generate an answer and provide it to the user.
This is how it happens, and this is RAG!
And when things are fetched and enriched with the retrieved information, it is called augmentation.
Now you got the RAG pipeline as well!
What is Grounding ?

So, one thing we need to remember is that when we ask any question, an LLM answers from what it has already learned or has in its memory, and it tries to use the same knowledge.
But sometimes, what happens is that when we ask something that is not in its memory, it should go and search for proper evidence sources and then answer.
So, an answer generated by an LLM can have evidence, but sometimes it may not.
When you ask an LLM for a definition, sometimes it gives you a simple answer without a link, but sometimes it answers with a link.
Suppose we ask, "Where can we find the Namaste AI digital notes?" You will not get a random answer. You will get the correct answer with the right link and proper grounding with evidence.
See the screenshot below.

Definition:
In Retrieval-Augmented Generation (RAG), grounding means anchoring a language model's answer to specific, retrieved source material rather than letting it rely only on what it memorized during training. The system pulls relevant documents, passages, or web data at query time and puts them into the prompt so the model can base its response on verifiable evidence.
So, the benefits of grounding are:
- It reduces hallucinations.
- Improves accuracy.
- Verifies the source of the answer.
- Builds trust.
- Enables reliable AI.
And this is not related to RAG only. This is a basic concept of AI and LLMs.
RAG vs Fine Tuning
Both look similar, but they look different because they are different.
So, RAG retrieves information before answering, but fine-tuning is related to the model and changes the model weights.
Fine-tuning changes the behaviour and performance of the model. RAG is related to retrieved sources. Retrieved passages can be attached, and RAG can also enforce document-level permissions.
But in fine-tuning, the model's behaviour changes, and it can take time to train. Model weights are not well suited for document-level access control.
Just remember, fine-tuning is related to the model. It's a very clear thing.
Wanna change the behaviour? Do fine-tuning.
Wanna provide extra knowledge? Use RAG and build a RAG system.
On NamasteDev.com, you can check the Resume Reviewer. It has a model behind the scenes that is fine-tuned, and there is no basic use of RAG here.
But in a chatbot, RAG is required when you need to provide extra documents to answer questions, like finding timestamps.
But a Resume Reviewer requires more from the model, changing the model's behaviour to get better review results.
Correct? Read the entire paragraph again, and you will understand.
Retrieval-Augmented Generation (RAG) pulls fresh, external data into an LLM's prompt at query time without changing the model itself, while fine-tuning retrains the model's weights on specialized examples to change how it behaves, formats outputs, or handles a domain. Think of RAG as an open-book exam (looking up facts on the fly) and fine-tuning as studying for the exam (baking patterns and behavior into memory) This is an important interview question. Go and read more about i
RAG vs Long context Prompting
First, let's understand what Long-Context Prompting is.
Long-context prompting is the practice of structuring and organizing large inputs, such as entire codebases, books, long contracts, audio, or video, inside a large language model's context window so it can accurately reason over all of it at once.
For example, summarising a PDF does not require RAG, correct? Just providing the PDF as a long-context prompt is enough.
Comparing two health insurance policies? Just provide those two documents. Long-context prompting is sufficient; RAG is not necessarily required.
But if you have 1,000 documents in a database and want to ask a question, RAG is required, not just long-context prompting, because retrieval becomes important.
NOTE: RAG and Long-Context Prompting can work together. Retrieval selects the relevant material, and a larger context window allows the model to examine more of it!
Okay, that's all for this episode. We will meet again in the next episode.
Take care of your health and never disrespect your parents. Keep loving them. ❤️
Bye-bye! 👋
Want me to write notes on a course?
Tell me the course, book, or research topic you want covered. If it helps learners, I'll consider adding structured digital notes for it in the garden.
Have a notes collection to feature here?
Do you have open notes you want featured in this digital garden? Let me know — we can collaborate and publish them for learners worldwide.
Having a doubt? Ask a query?
