A query cannot be answered correctly without having knowledge about the intention of the query.
RAG is a technique that retrieves relevant information from external sources and gives it to an LLM (Large Language Model) as context when answering the question. It helps the LLM to get some knowledge about the intention of the query. In business, this technique will help us make the LLM work for our specific needs.
I don’t want to keep you waiting long, so let’s get started…
What is RAG? Why RAG?
Before understanding what RAG is, we need to know WHY RAG and what the business problem it’s going to solve.
Let’s assume you have a great finance assistant to work for your organisation, but he doesn’t have any knowledge of your real data. So, when you ask ‘Explain the reasons given in 2025 annual report for the fall in revenue’ do you think that he will be able to answer that? Without knowing the data, he couldn’t answer the question. This is where RAG comes into the picture.
You might have the best LLM, but they are trained on various source of data, and they don’t have any knowledge of your organisation’s data. So, we need to provide the respective data to the LLM to answer your query. RAG helps us to provide the data which are needed to answer the query.
Cutoff: early 2024
Not in training data
The Three Stages: Retrieve, Augment and Generate
The name Retrieval-Augmented Generation (RAG) describes the three core stages involved in producing a response. Rather than relying solely on the knowledge learned during training, a RAG system first retrieves relevant information from external sources, augments the LLM’s prompt with that information, and then generates a response based on both the user’s query and the retrieved context.
Retrieve: Search the knowledge base and retrieve the most relevant information for the user’s query.
Augment: Add the retrieved information to the LLM’s prompt as additional context.
Generate: The LLM uses the augmented prompt to generate a grounded and context-aware response.
The following sections explain each of these stages in detail, with a primary focus on retrieval, as it is the foundation of an effective RAG system.
Retrieval
This is the part where the data that is relevant to the query are to be populated. There are many types of retrieval strategies which can be used alone or in a combination based on our business needs. Let’s assume we have our data in the form of documents, which makes it much easier to understand.
Document 1:
” The total spent on machine repair costs in 2025 was $2 million “
Document 2:
” Employee salary increased by 10% “
1. Keyword-Based Retrieval (Sparse Retrieval)
This is the simplest and traditional search approach. It will match the keywords in the query with documents and retrieve the matched ones.
How does it work?
Example Query: How much did we spend on machinery repairs in 2025?
I. Identify keywords in the query,
- machinery
- repair
- spent
II. Search all the populated keywords in the documents. We can use effective search like an inverted index.
III. Retrieve the documents/chunks which have the keywords
IV. Attach the context with the query and send it to the LLM. (Sample input to the LLM)
Answer the question using this context:
Document 1:
The total spent on machine repair costs in 2025 was $2 million.
Question:
How much did we spend on machinery repairs in 2025?
V. LLM will respond to the query using the attached context.
Question: How much did we spend on machinery repairs in 2025?
(grounded prompt with retrieved context)
Limitation:
This approach will not work if the query doesn’t have the exact keywords. For example, if a user forms the query like
How much was the equipment maintenance expense in 2025?
The above query has the same intent, but it doesn’t have the exact keywords which are present in the document. Basic keyword search may fail or rank the correct document poorly when the query uses different terminology. More advanced techniques like fuzzy or phonetic search can partially bridge this gap, but they still struggle with true semantic differences in meaning. These kinds of issues are solved using semantic retrieval.
2. Semantic Retrieval (Dense Retrieval)
This is the most common retrieval method in modern RAG. Instead of comparing the keywords, this strategy will compare the meaning/intent of the query with the data.
The Main Idea Behind Semantic Retrieval
Semantic retrieval converts text into vectors. A vector is just a list of numbers that represents the meaning of the text.
“machine repair cost”
Embedding: [0.23, 0.91, 0.44, 0.71]
“equipment maintenance expense”
Embedding: [0.22, 0.89, 0.42, 0.73]
Notice the vectors are very similar. The embedding model has learnt that that phrases such as “machine repair cost” and “equipment maintenance expense” most often express similar meanings, so it places their vectors close together.
Embedding Model
An embedding model is a machine learning model trained to convert text into vectors.
↓
Embedding Model
↓
Vector (numbers)
Input: “equipment maintenance expense”
Output: [0.124, 0.762, 0.442, … 1536 numbers]
Depending on the embedding model, a vector may contain several hundred or several thousand numbers.
Example of embedding models:
- OpenAI text embedding models
- BERT-based embedding models
- Sentence Transformers
Document Storage Process (Indexing Phase)
We got the idea of semantic search. Now the question is how to convert our raw data to vectors. We need some pre-processing to enable the semantic search. R or the database which support vector search.
Let’s take a PDF:
Annual_Report_2025.pdf
Page 1:
Company Overview
Page 30:
The total spent on machine repair costs in 2025 was $2 million.
Page 60:
Future plans…
Step 1: Document loading
The system extracts text from the document.
↓
Raw Text
Example: The total spent on machine repair costs in 2025 was $2 million.
Step 2: Chunking
Large documents are split into smaller pieces called chunks. Choosing an effective chunking strategy is crucial, as it directly impacts retrieval quality. Depending on the nature of the data, strategies such as fixed-size chunking, semantic chunking, recursive character splitting, and others can be used.
Chunk 1:
Company Overview…
Chunk 2:
Total spent on machine repair cost in 2025 was $2 million.
Chunk 3:
Future plans…
Step 3: Generate Embeddings
Each chunk goes to the embedding model:
↓
Embedding Model
↓
Vector
Example:
Chunk: The equipment maintenance cost was $2 million.
Vector: [0.27, 0.60, 0.91, 0.44, …]
Step 4: Store in Vector Database
The vector database stores something like:
“id”: “chunk_002”,
“text”: ” Total spent on machine repair cost in 2025 was $2 million.”,
“embedding”: [0.27, 0.60, 0.91, 0.44],
“metadata”: {
“document”: “Annual_Report_2025.pdf”,
“page”: 30,
“department”: “Finance”
}
}
So, a vector database usually stores:
This entire process is called indexing or ingestion.
[
Similarity search
Sent to LLM
Filtering & traceability
Query Time (Retrieval Phase)
Note: In a production RAG system, each document chunk is typically stored along with metadata such as the document name, page number, author, creation date, department, category, or other business-specific attributes. Metadata enables the retrieval system to filter and retrieve information more accurately, cite the source of the retrieved content, and answer queries constrained to specific criteria (for example, a particular department, product, region, or time period).
For simplicity, the chunk examples used throughout this blog do not include metadata. The focus of the examples is to explain the retrieval concepts rather than the complete implementation details.
Query: How much was the equipment maintenance expense in 2025?
Step 1: Convert Query to Vector
The same embedding model is used:
↓
Embedding Model
↓
Query Vector
Example: [0.26, 0.61, 0.90, 0.45]
Step 2: Vector Similarity Search
The query vector is compared against the millions of stored vectors in a vector database.
Example:
Query:
[0.26, 0.61, 0.90, 0.45]
Chunk_001:
Document 1
Page 2
Total spent on machine repair cost in 2025 was $2 million.
Similarity: 0.97
Chunk_004:
Document 10
Page 11
Employee salary report
Similarity: 0.15
Similarity: 0.97
Chunk_102:
Document 5
Page 7
Machinery replacement budget was $1M
Similarity: 0.20
The closest vectors are selected.
Step 3: Return Top-K Chunks
The best matches are selected. Top selection will be fixed based on the output quality.
Example:
Top 2 results:
- Total spent on machine repair cost in 2025 was $2 million.
- Machinery replacement budget was $1M.
Step 4: Create a prompt – Augmentation
Augmentation simply means adding the retrieved information to the LLM’s prompt.
Answer the question using only the provided context and also mention the source details that supports the answer. Avoid inventing missing information and state when the answer is not present.
Retrieved Context:
Chunk_001:
Document 1
Page 2
Total spent on machine repair cost in 2025 was $2 million.
Similarity: 0.97
Chunk_102:
Document 5
Page 7
Machinery replacement budget was $1M
Similarity: 0.20
Question:
How much did we spend on machinery repairs in 2025?
Note: The quality of a RAG system depends not only on retrieval but also on prompt design. The prompt should instruct the LLM
- answer using the supplied sources;
- state when the answer is not present;
- avoid inventing missing information;
- cite its sources;
- mention conflicts between sources.
Effective retrieval alone does not guarantee a reliable, grounded response.
Step 5: LLM response – Generation
Now the LLM finally does what it is best at.
It reads the user’s question and augmented context and generated the natural language answer.
The equipment maintenance cost in 2025 was $2 million.
Source:
Document 1 – Page 2
Repair cost 2025: $2M
Similarity: 0.97
Employee salary report
Similarity: 0.15
Replacement budget: $1M
Similarity: 0.20
2. Replacement budget: $1 million
Chunk_102, Doc 5 p.7, replacement budget: $1M, sim 0.20
Question: how much did we spend on repairs in 2025?
Instruction: cite sources, flag conflicts, don’t invent info
Source: Document 1, page 2
3. Hybrid Retrieval (Keyword + Semantic)
Interestingly, many production RAG systems use both.
Why?
Because semantic search can sometimes miss exact details. Example:
Query: Show invoice INV-98234
Semantic search may not treat INV-98234 as highly meaningful. Keyword search will match since the same invoice number will be present in the document. So, production RAG systems often combine keyword and semantic retrieval to leverage the strengths of both approaches. The retrieved candidates are then merged, deduplicated, and reranked so that only the most relevant passages are sent to the LLM.
This helps reduce irrelevant context, improves answer quality, and makes better use of the LLM’s context window.
Payment terms overview
INV-98234 may be missed
Amount: $4,500, due Jan 30
Exact match found ✓
– Payment terms overview (deprioritized)
Question: show invoice INV-98234
4. Multi-Hop RAG
A hop means one step of retrieving information. A single hop which we have seen so far can solve a direct query.
Example:
Query: Who is the author of “Harry Potter”?
Consider the following query:
Query: In which country was the author of “Harry Potter” born?
Assume your knowledge base contains the following documents:
Document 1:
Harry Potter was written by J.K. Rowling.
Document 2:
J. K. Rowling was born in England, part of the United Kingdom.
Consider the following query:
Query: In which country was the author of “Harry Potter” born?
To answer this question, the system must connect information from multiple pieces of evidence:
- Identify the author of Harry Potter.
- Determine the country where the author was born.
Although a single retrieval may sometimes return both documents, this cannot always be guaranteed, especially in large knowledge bases. In such cases, the system first retrieves the author’s name, then performs another retrieval using that information to find the author’s birthplace. This step-by-step retrieval process is known as Multi-hop Retrieval.
Hop1:
Query: In which country was the author of “Harry Potter” born?
Retrieval:
Based on the above query, Let’s assume the system retrieved only the following context.
Document 1:
Harry Potter was written by J.K. Rowling.
Augmentation:
The retrieved context and the user’s query are then sent to the LLM. The prompt is carefully designed (augmented) to help the LLM determine whether the available context is sufficient to answer the question. If additional information is required, the LLM identifies the missing information and generates the next search query, enabling another retrieval hop.
Example Input
Answer the question using only the provided context.
Original Question:
In which country was the author of “Harry Potter” born?
Retrieved Context:
Document 1: Harry Potter was written by J.K. Rowling.
Instructions
1. Determine whether the retrieved context is sufficient to answer the original question.
2. If it is sufficient, provide the answer.
3. If it is not sufficient, explain what information is missing and generate the next search query needed to retrieve that information.
4. List the source details that supports the answer.
Generation:
The LLM reasons
I found that J.K. Rowling is the author of “Harry Potter”, but I don’t know the country in which she was born.
Missing information:
The country where J.K. Rowling was born.
Source:
Document 1
Next search query:
“Which country was J.K. Rowling born in?”
The system recognises that it still needs one more fact and performs another search using the author’s name.
Hop2:
Query: Which country was J.K. Rowling born in?
Retrieval:
Context retrieved
Document 2:
J.K. Rowling was born in England, part of the United Kingdom.
Augmentation:
LLM Input
Answer the question using only the provided context.
Original Question:
In which country was the author of “Harry Potter” born?
Retrieved Context:
Document 1: Harry Potter was written by J.K. Rowling.
Document 2: J. K. Rowling was born in England, part of the United Kingdom.
Instructions
1. Determine whether the retrieved context is sufficient to answer the original question.
2. If it is sufficient, provide the answer.
3. If it is not sufficient, explain what information is missing and generate the next search query needed to retrieve that information.
4. List the source details that supports the answer.
Generation:
LLM Output
Yes, enough information is available.
J.K. Rowling, who is the author of “Harry Potter”, was born in England, part of the United Kingdom.
Source:
Document 1 – Page 10
Document 2 – Page 5
Limitation:
It is difficult to handle multiple retrieval and reasoning steps.
Limitations:
✗ Her country of birth is not in this context.
Source: Document 1
Next search: “Which country was J.K. Rowling born in?”
part of the United Kingdom.
Doc 1: Harry Potter was written by J.K. Rowling.
Doc 2: J.K. Rowling was born in England, UK.
✓ Yes, enough information available to answer.
Source: Document 1 – page 10, Document 2 – page 5
was born in England, part of the United Kingdom.
Source: Document 1 – page 10, Document 2 – page 5
Each hop builds on the previous — context accumulates across hops
Retrieval Quality Issues
The quality of a RAG system heavily depends on the quality of the retrieved context. Poor retrieval can result in missing relevant information or including irrelevant context, which directly impacts the accuracy of the generated response.
Source Quality
RAG grounds answers in source documents, but cannot guarantee the sources themselves are accurate. If the underlying documents are outdated, incorrect, duplicated, contradictory, or incomplete, the answer will reflect those flaws.
Irrelevant Context (Context Pollution)
Even when relevant information is retrieved, additional unrelated chunks may also be included, which can distract the LLM and reduce answer accuracy.
No Guarantee of Correct Answers (Hallucination)
RAG reduces hallucinations by providing external context, but it does not completely eliminate them. The LLM may still generate incorrect or misleading answers.
Security and Access Control
In a business context, not all documents should be accessible to all users. A RAG system must ensure users retrieve only documents they are authorised to see, sensitive data is protected, and queries and responses are appropriately logged and governed. Simply uploading documents to a vector database is not enough — access control must be part of the design.
Context Window Limitation
LLMs have a limited context window (the maximum number of tokens they can process). Large amounts of retrieved context may exceed this limit, causing important information to be excluded.
Difficulty with Multi-Hop Reasoning
Questions requiring information from multiple documents can be difficult to answer, as they may require multiple retrieval and reasoning steps.
Key Feature: Citations and Traceability
A well-designed RAG system should always indicate which document or passage supported the answer, allowing users to verify it independently. This builds trust and enables audit trails.
When RAG is Appropriate and When Another Tool Is Better
RAG is an excellent choice when the information required to answer a question exists in unstructured or semi-structured sources such as documents, PDFs, manuals, knowledge bases, policies, or FAQs. It enables LLMs to retrieve relevant information from these sources and generate grounded responses without retraining the model.
However, RAG is not the best solution for every use case. When information is stored in structured databases, it is often more efficient to query the database directly using SQL or another query language. Similarly, tasks involving calculations, business workflows, API integrations, or real-time operations are better handled by dedicated tools or agents rather than document retrieval.
In practice, enterprise AI applications often combine RAG with other techniques. For example, a system may use RAG to retrieve information from documents, execute SQL queries against a database, call APIs to fetch live data, or invoke external tools to perform actions. Choosing the right approach depends on the nature of the data and the problem being solved.
Conclusion
RAG is a practical and effective way to enable LLMs to answer questions using private, up-to-date, or domain-specific information without retraining the model. By retrieving relevant information, augmenting the prompt with that context, and generating a response, RAG helps ground answers in external knowledge while keeping the model’s knowledge separate from business data.
However, building an effective RAG system involves much more than retrieval alone. The quality of the response depends on the quality of the source data, document processing, chunking, retrieval strategy, ranking, prompt design, and the relevance of the retrieved context. Depending on the use case, keyword, semantic, hybrid, or multi-hop retrieval may be the most suitable approach.
Although RAG can significantly reduce hallucinations and improve answer traceability through source citations, it cannot guarantee correctness. An effective RAG solution should also consider security, access control, and the specific needs of its users. Ultimately, there is no one-size-fits-all approach; understanding your data, business requirements, and user queries is the key to designing an accurate, reliable, and scalable RAG system.
Frequently asked questions on RAG
What problem does RAG solve?
An LLM is trained on general public data and has no knowledge of an organisation’s private or internal information. RAG solves this by retrieving relevant data from external sources and giving it to the LLM as context, so it can answer questions about information it was never trained on.
What do the three letters in RAG stand for?
RAG stands for Retrieval, Augmentation, and Generation. The system first retrieves relevant information from a knowledge base, augments the LLM’s prompt with that information, and then generates a response using both the query and the retrieved context.
What happens during the Retrieval stage?
During retrieval, the system searches a knowledge base and pulls out the pieces of information most relevant to the user’s query. This stage forms the foundation of an effective RAG system, since the quality of everything that follows depends on it.
What is keyword-based retrieval?
Keyword-based, or sparse, retrieval is the simplest search approach. It matches the exact words in a query against the words in stored documents and retrieves whichever ones contain matching keywords.
What is the main limitation of keyword-based retrieval?
It fails when a query expresses the same intent using different wording than the source document. Since it looks for exact keyword matches, it can miss relevant documents that describe the same idea using different terminology.
What is semantic retrieval?
Semantic, or dense, retrieval compares the meaning of a query with the meaning of stored data rather than matching exact words. It converts text into vectors, so phrases with similar meaning end up with similar vector values even if they use different wording.
What is an embedding model?
An embedding model is a machine learning model that converts text into a vector, which is a list of numbers representing the meaning of that text. Similar pieces of text produce vectors that sit close together numerically.
What is chunking, and why does it matter?
Chunking is the process of splitting large documents into smaller pieces before generating embeddings for them. Each chunk needs to be small enough to search effectively but large enough to preserve the meaning of the surrounding text.
What information does a vector database typically store?
Alongside the embedding vector itself, a vector database usually stores the original chunk text and metadata such as the source document, page number, and department. This combination supports similarity search, feeds the LLM the right text, and enables filtering and traceability.
What is hybrid retrieval?
Hybrid retrieval combines keyword-based and semantic search in the same system. It’s useful because semantic search can miss exact identifiers like invoice or reference numbers, which keyword search catches reliably, so combining both leverages the strengths of each.
What is multi-hop RAG?
Multi-hop RAG is a retrieval process that requires more than one retrieval step to answer a question. The system retrieves an initial piece of evidence, uses it to generate a follow-up query, and retrieves again until it has gathered enough information to answer.
Does RAG eliminate hallucinations completely?
No. RAG significantly reduces hallucinations by grounding answers in retrieved context, but it cannot guarantee correctness. The LLM can still generate incorrect or misleading answers, especially if the source documents themselves are outdated or inaccurate.
Why does access control matter in a business RAG system?
Not all documents should be visible to all users in a business setting. A RAG system needs to ensure retrieval respects user permissions, protects sensitive data, and logs queries and responses appropriately, rather than treating the vector database as open to everyone.
When is RAG not the best solution?
RAG is best suited to unstructured or semi-structured sources like documents, manuals, and FAQs. For structured data it’s usually more efficient to query a database directly with SQL, and tasks like calculations, workflows, or live API calls are better handled by dedicated tools or agents.
