Understanding Retrieval Augmented Generation (RAG) : The Open-Book Exam for AI

Raghav GoelRaghav Goel
3 min read

A Simple Analogy

Imagine a bright student preparing for a history test. They’ve studied for weeks and know a lot about the subject. But then comes a tricky question about an event that happened yesterday.

Even the best student would struggle without fresh information.

Now, suppose this student is given an open-book exam — with access to the most up-to-date textbooks and articles. They could combine their prior knowledge with the latest facts to write an ideal answer.

👉 This is exactly what Retrieval Augmented Generation (RAG) does for Artificial Intelligence.


What is Retrieval Augmented Generation (RAG)?

RAG is a technique that improves the accuracy and reliability of Large Language Models (LLMs) by supplying them with external, up-to-date information.

  • A standard LLM (like ChatGPT) is like the brilliant student — it has vast but fixed knowledge.

  • RAG acts as the student’s specialized external library, providing fresh context before answering a question.


Why Do We Need RAG?

LLMs are powerful, but they face two big challenges:

  1. Knowledge Cutoff

    • LLMs only know what they were trained on.

    • They don’t have access to recent events, new data, or private information (like company documents).

    • Example: A model stuck at 2022 knowledge.

  2. Hallucinations

    • When unsure, LLMs sometimes “make up” answers.

    • These fabricated but confident responses are known as hallucinations.

✅ RAG fixes these problems by grounding responses in real, external data sources.


How RAG Works: The Librarian and The Writer

The RAG process has two major parts:

1. The Retriever (The Librarian)

  • Searches the external knowledge base.

  • Finds the most relevant chunks of information.

  • Like a super-speedy librarian who pinpoints the exact paragraphs you need.

2. The Generator (The Writer)

  • The LLM itself.

  • Uses both the question and the retrieved information to create a coherent answer.

  • Like the student writing a well-supported essay using the right textbook pages.


A Simple Example

Question: “What were the key findings of the Alpha Project announced last week?”

  • Retriever: Searches internal documents, finds “Alpha Project: Q3 Summary”, extracts the Key Findings section.

  • Generator: Produces a response:

    “The key findings of the Alpha Project, announced last week, were a 15% increase in efficiency and a 10% reduction in operational costs.”


Under the Hood: How the Library Works

1. Indexing

  • Creates a meaning-based catalog of documents.

  • Goes beyond just titles; it understands context and semantics.

2. Vectorization

  • Converts text into numerical vectors.

  • Think of it as a map of information dots:

    • Related concepts (e.g., French Revolution and 18th-century peasant unrest) are close together.

    • Unrelated topics (French Revolution vs. how to bake a cake) are far apart.

  • When you ask a question, RAG places it on this map and retrieves nearby information.

3. Chunking

  • Large documents are broken into smaller, manageable chunks.

  • Instead of searching whole books, the system searches relevant pages/paragraphs.

4. Overlapping

  • Prevents context loss when splitting documents.

  • A few sentences from the end of one chunk are added to the start of the next.

  • Like having a small snippet of the previous page at the top of the current one.


Why RAG Matters

RAG makes LLMs more useful, trustworthy, and adaptable. It:

  • Reduces hallucinations

  • Provides current, factual responses

  • Allows access to domain-specific or private data

  • Lets users verify answers with sources


In a Nutshell

RAG transforms a bright but forgetful student into a true open-book expert.

By combining the LLM’s reasoning ability with real-time, verified knowledge, RAG ensures responses are accurate, current, and reliable.

0
Subscribe to my newsletter

Read articles from Raghav Goel directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Raghav Goel
Raghav Goel

Hello! I'm Raghav Goel, a passionate Front-End Developer with a knack for creating intuitive and high-performing web applications. I specialize in React.js and its ecosystem, building everything from responsive single-page applications to complex dashboards. I thrive on translating designs into pixel-perfect, functional user interfaces and optimizing for the best possible user experience. Currently, I'm freelancing and expanding my skills in UI/UX design and backend technologies. I'm also proud to have co-authored a research paper on solar power forecasting, which is slated for publication. I'm always eager to take on new challenges and collaborate on exciting projects. Let's connect!