See all notes
Namaste AI Notes

RAG Architecture Explained: Indexing, Querying & Semantic Search

Ashutosh Anand Tiwari
By Ashutosh Anand Tiwari05 Dec, 2026 · 8 min read
RAG Architecture Explained: Indexing, Querying & Semantic Search

Okay, now let's discuss the architecture of RAG.

Basically, we can divide it into two phases. One is the Indexing Phase, and the other is the Query Phase.

Let's understand this using an example.

Suppose this is the book:

Software Engineering (9th Edition) by Ian Sommerville

And we want to build a RAG system where all the answers are generated from the pages of this book.

The example PDF we have is more than 750 pages long. So, how will we build this type of system to retrieve information from the book?

That's exactly what we are going to learn here using RAG.

As we discussed, there are two phases:

  1. Indexing Phase
  2. Query Phase

The Indexing Phase is basically about taking the book's content, processing it, and preparing it in a way that a RAG system can efficiently retrieve relevant information whenever a user asks a question.

In technical terms, the Indexing Phase is the process of ingesting documents, extracting their content, splitting the content into smaller chunks, generating embeddings, and storing those embeddings in a vector database for efficient retrieval.

Indexing Phase of RAG

The Indexing Phase in Retrieval-Augmented Generation (RAG) is the offline preparation step that loads, cleans, chunks, embeds, and organizes external data into a searchable index before a user ever asks a question. It turns raw documents into a structured format so the system can quickly find relevant context during live queries.

So, let's dig deeper into the Indexing Phase of RAG.

We have a 750+ page book that will be our source for the RAG system. Remember, any content we want to use as a source for our RAG system—whether it comes from a PDF, video, or audio—needs to be converted into text first.

Refer to the image below.

So, we extract the data in Step 2. Whatever source we have, for example, our book, all the text from its 750+ pages will be extracted in Step 2.

Let's assume each page has around 500 words. So, for a 750-page book, we will have approximately 3.75 lakh words.

Now, in Step 3, all the extracted text will be divided into smaller chunks. This process is called Chunking.

Chunking is a strategy.

Chunking in Retrieval-Augmented Generation (RAG) is the process of breaking large documents into smaller, self-contained pieces (chunks) before turning them into embeddings and storing them in a database.

Doing this helps search systems find the exact information needed and keeps answers focused within a model's context window.

The next step is Embedding.

We have already discussed embeddings in detail earlier. There are many embedding models available. They are not the same as LLM models; they are designed for a different purpose.

Let's quickly recall the definition:

In Retrieval-Augmented Generation (RAG), an embedding is a list of numbers (called a vector) that captures the meaning of text, images, or other data so a system can find relevant information based on concepts rather than exact word matches.

Now, we get an array of numbers representing the meaning of each chunk. These vector embeddings are then stored in a Vector Database.

This is a high-level explanation of Step 1 of RAG, the Indexing Phase, and the steps involved in it. You can definitely dig deeper and learn more about each step. By the way, we will also explore them in detail, but slowly.

Now, a question comes to mind:

Why a Vector Database? How is it different from other databases?

Each type of database is designed for different types of data and use cases. A Vector Database is designed to make similarity searches on vector embeddings efficient and fast.

We will understand this better in the Query Phase, so be patient!

Now, let's discuss the Query Phase.

Querying Phase of RAG

The Querying Phase (also called the Retrieval Phase or Query Pipeline) in Retrieval-Augmented Generation (RAG) is the live, runtime step where a user's question is processed, matched against stored knowledge, and used to generate a grounded answer.

Unlike the Indexing Phase, which prepares and stores documents ahead of time, this phase runs in real time whenever someone asks a question.

Suppose you want to get an answer from our book. For example, you ask:

"What is the process of risk management? What are its stages?"

This is called a query.

Now, let's understand how this works.

First, this query goes through an embedding model, which converts the question into a vector embedding.

See the image below.

Our query is converted into an embedding, and that embedding is passed to the Vector Database.

Remember, the Vector Database already has embeddings stored from the Indexing Phase, right? So, the Vector Database compares our query embedding with the stored embeddings and finds the chunks that best match our query.

Basically, it compares embeddings to embeddings. This is called Similarity Search.

In Retrieval-Augmented Generation (RAG), similarity search is the process of finding stored text chunks whose meaning closely matches a user's query so an LLM can use them as context.

Instead of matching exact keywords, it converts text into numerical vectors (embeddings) and compares how close they are in vector space.

When we get these chunks from the Vector Database, they are called Retrieved Documents or Retrieved Chunks.

These retrieved chunks are then passed to the LLM as context, and the LLM generates our response.

And both phases together form the RAG pipeline:

  1. Indexing Phase
  2. Query Phase

Don't worry, we will properly learn the technical aspects as well. For now, we are learning the theory so that we can understand everything better later.

Semantic Search

Let's see what Semantic Search is.

It is a meaning-based search, and it is helpful even when the wording is different. It uses techniques like cosine similarity to find relevant information based on meaning.

Semantic Search is a way of finding relevant information based on meaning and intent rather than matching exact keywords.

For example, a user asks, "Can I get my money back?" This query may relate to the refund policy.

Similarly, if a user asks, "Is there a holiday on Diwali?", the system can find the relevant holiday policy.

Got it? This is how Semantic Search works!

Bye-bye! We will dive deeper into the technical aspects in the next episode.

Take care of your health! ❤️

Bye-bye! 👋

Request a Topic

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.

Collaborate

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.

Made with by Ashutosh · Digital Garden © 2026