RAGvs Agentic RAG
RAGvs Agentic RAG
prev Interview Prep Career GenAI Prompt Engg ChatGPT LLM nextL
Today, I am discussing RAG vs Agentic RAG. In this guide, I will provide you with the
Firstly, let’s understand what RAG is. It is not a piece of old cloth but the framework
But can we see the limitations of LLMs without RAG? Absolutely! Here, I have asked
ChatGpt to give me output on its knowledge without any external searches for Swarm
by OpenAI; it cannot provide the right output. This is due to its knowledge cutoff date,
which is 2023, and to get the correct output, it has to be updated with new information
or access to an external source. Intriguing, right? So, can we augment the LLMs with
our own custom data to get the right response? Of course, we can do it with long-
context LLMs and RAG. Today, we will be talking about RAG.
Show details
Crafted Just for YOU!
Accept all cookies Use necessary cookies
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 1/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Download Now
Instead of relying solely on the large language model’s (LLM) pre-trained knowledge,
which may be outdated or incomplete, RAG dynamically retrieves the most relevant
documents or information from an external knowledge base or database.
Let us comprehend this with an example: if we humans, after birth, rely on only one
source of information when exploring the external environment, our understanding
would remain severely limited. Similarly, a Large Language Model (LLM) on its own
has a predefined training dataset that serves as its “internal knowledge.” This has to
be the only source of Information for the model, resulting in old information,
ungrounded hallucinations, senseless content and more. While vast, this dataset
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 2/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
11. LangChain Agentic RAG System Using the IBM Granite-3.0-8B-Instruct model
12. Conclusion
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
Source: Author
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 3/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
1. Retrieval (R): This involves searching for relevant data from external sources,
2. Augmentation (A): In this phase, the retrieved data is added to the prompt
context. This means the information is integrated or combined with the input given
to the AI, effectively enriching its knowledge base for better reasoning and context-
aware responses.
3. Generation (G): Finally, the AI uses the augmented context to generate outputs,
such as text, explanations, or insights, based on the combined input and retrieved
data. This step represents the output of generative AI tools like GPT models.
information.
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 4/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Source: Author
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 5/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Customisation Cannot access or utilise user- Integrates public and private datasets,
specific datasets or private enabling highly tailored and relevant
sources, resulting in generic outputs.
responses.
Use Cases Suitable for general-purpose tasks Ideal for tasks requiring live updates,
but less effective for dynamic or research, or custom data integration.
data-intensive applications.
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 6/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Source: Author
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 7/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Source: Author
Working of RAG
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 8/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
This part focuses on preparing and managing the knowledge base during retrieval.
Step 1: Load
The system ingests different types of data (e.g., text files, PDFs, URLs, and JSON
files).
The data can come from diverse sources, ensuring a comprehensive knowledge
base.
Step 2: Split
This step ensures that retrieval works efficiently, allowing the system to fetch
precise and relevant parts of documents instead of retrieving entire files.
Step 3: Embed
models.
These embeddings capture the semantic meaning of the text, enabling the system
to perform similarity-based searches.
Step 4: Store
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
The embeddings and corresponding data are stored in a vector database.
Cookies Policy.
Show details
The vector database is optimised for quick and accurate similarity searches, which
is crucial for retrieval.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 9/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
This describes the overall process of combining retrieval and generation to produce an
answer:
The system begins by analysing this question for context and intent.
Step 2: Retrieve
We use cookies essential for this site to function well. Please click to help us improve its
The system queries
usefulness an indexed
with additional cookies. knowledge
Learn about our base (retrieval
use of cookies system)
in our Privacy Policyto& gather the
Cookies Policy.
most relevant documents or pieces of information.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 10/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
The retrieved documents are structured into a prompt for the LLM.
The prompt includes the original question and the retrieved information, guiding
the LLM in generating a context-aware response.
The LLM processes the prompt, utilizing its generative capabilities to create a
coherent and precise response.
The response combines insights from the retrieved documents with the LLM’s pre-
trained knowledge.
The final answer is presented to the user, blending the retrieved knowledge and
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 11/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
must synthesize data from multiple sources and generate coherent, actionable
insights.
accurate,Show
relevant,
detailsand directly addresses the user’s query.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 12/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Large Language Models (LLMs) with vector databases to overcome LLM limitations.
While effective for basic tasks like Q&A or support bots, they struggle with complex
use cases. These systems often fail to contextualize retrieved data, resulting in
nuanced use cases effectively. This is where Agentic RAG comes to the rescue.
I hope you now have a clear understanding of the traditional RAG. We will now
discuss a different version of RAG with agents—the Agentic Rag.
Generation system where an “agent” plays a key role in orchestrating processes. The
agent intelligently determines which resources or databases are most relevant for a
user’s query, making it capable of handling more complex, multi-tasking scenarios. It
We use cookies essential for this site to function well. Please click to help us improve its
Agentic:usefulness
The system works
with additional on its
cookies. own,
Learn aboutmaking
our use ofdecisions
cookies in our and taking
Privacy Policy &actions
Cookies Policy.
depending on the situation.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 13/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Source: Author
The process flow of an Agentic RAG System for handling user queries. Here’s a
breakdown of each component:
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
1. User Input and Initial Assessment:
Cookies Policy.
The Show
system receives a user query.
details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 14/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
The query is assessed to determine if it fits the criteria for retrieval (it is part of
The agent identifies the most relevant vector database for the query.
If the query does not match any database, the process routes to a failsafe
mechanism.
3. Content Retrieval:
Retrieved content is integrated into the LLM prompt for further processing.
Based on the query and retrieved content, the system determines the
appropriate response type:
5. Final Output:
The We
system generates
use cookies the
essential for thisappropriate response
site to function well. Please click(text,
to help code, or itschart) and
us improve
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
delivers the
Cookies final output.
Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 15/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Crucial Points:
Agent Role: The agent dynamically selects the most relevant database,
Task Specialization: Different vector databases are optimized for specific tasks
(e.g., code generation, chart creation), improving performance and accuracy for
complex scenarios.
Also read: How Agentic RAG Systems with CrewAI and LangChain Transform Tech?
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
Source: LangChain
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 16/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
1. Agent (Node): Initiates the process and decides whether to retrieve documents by
5. Rewrite (Node): Reformulates the query and restarts the retrieval process if
necessary.
This iterative approach ensures accuracy and relevance by dynamically retrieving and
refining the query as needed.
Also read: A Comprehensive Guide to Building Agentic RAG Systems with LangGraph
Agents are the driving force behind the Retrieval-Augmented Generation (RAG)
framework, functioning as specialized units that streamline each stage of the retrieval
and generation pipeline. They operate collaboratively to achieve tasks like
managing the
Weoverall workflow.
use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
By orchestrating these functions, agents ensure smooth, efficient, and intelligent
Show details
handling of tasks. This modular and adaptive approach allows the system to tackle
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 17/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
complex queries effectively while improving overall performance and system reliability.
The RAG system employs several types of agents, each with a specific purpose and
1. Routing Agents
Source: LlamaIndex
Purpose: Direct
We useuser queries
cookies to this
essential for thesitemost appropriate
to function well. Please sources.
click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
How They Work: Analyze queries using large language models (LLMs) to determine
Show details
which parts of the RAG pipeline best handle the request.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 18/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
answer a specific query: “What did the author do during his time in art school?”. Here’s
a breakdown of how the system works:
This is the main process to extract and summarize information relevant to the
query.
data.
Afterusefulness
processingwith additional cookies. Learn about our use of cookies in our Privacy Policy &
by the engines, a summarized response is generated: “During
Cookies Policy.
his time
Showindetails
art school, the author took foundation classes in fundamental
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 19/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Advantages:
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 20/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
manageable components.
Assign retrieval and generation tasks for each sub-query across the RAG
pipelines.
The process of retrieving and comparing revenue growth information for Uber
and Lyft in 2021 from their financial documents (10-K filings).
Process Overview:
1. Query Decomposition:
The initial query (Compare revenue growth of Uber and Lyft in 2021) is split
2. Data Source:
The data is extracted from 10-K filings (annual financial reports) of Uber and
Lyft.
These filings are stored in a document database where each report is split
We use cookies essential for this site to function well. Please click to help us improve its
3. Retrieval (Top-2 Chunks):
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
For each sub-query:
Show details
The system identifies the most relevant chunks (top-2) from the
For example:
Uber 10-K chunk 4 and Uber 10-K chunk 8 for the Uber sub-query.
Lyft 10-K chunk 4 and Lyft 10-K chunk 8 for the Lyft sub-query.
4. Results Compilation:
After retrieving the relevant chunks, the system processes the content to
generate responses for each sub-query.
Finally, the results for Lyft and Uber are combined to facilitate a comparison.
Key Insights:
Chunking: Large documents like 10-K filings are divided into smaller sections
(chunks) for more efficient and targeted searches.
similarity or keyword relevance) to select the top-2 chunks most likely to contain
Modular Query Handling: By decomposing the query into smaller parts, the
Outcome: Results from each sub-query are synthesized into a complete, coherent
response.
Benefits:
Show details
3. ReAct Agents (Reasoning and Action Agents)
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 22/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 23/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Source: paperswithcode
Show details
Executor: Implements these strategies effectively.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 24/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
1. User Input:
Example Query: “How much does Microsoft’s market cap need to increase to
exceed Apple’s market cap?”
2. LLM Planner:
Task Generation: The query is analyzed, and tasks are created as a Directed
Acyclic Graph (DAG) with dependencies. For example:
Task 1: search(Microsoft Market Cap)
and 2).
Task 3 depends on the results of Tasks 1 and 2 and must wait for their
completion.
Dependency Resolution:
This unit identifies the tasks ready for execution (those with resolved
dependencies).
For example:
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Initially, Tasks 1 and 2 are fetched for parallel execution.
Cookies Policy.
Show details
Once Tasks 1 and 2 are completed, their results are fed into Task 3.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 25/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
4. Executor:
Executes tasks using tools or functions as needed.
Tools Available:
search: Used to retrieve information (e.g., market caps for Microsoft and
Apple).
Execution Workflow:
5. Final Answer:
Once all tasks are executed and dependencies are resolved, the results are
For the example query, the final result would quantify how much Microsoft’s
market cap needs to increase to exceed Apple’s.
Key Features:
Show details
Dependency Management: Ensures tasks are executed in the correct sequence,
based on their interdependencies.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 26/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Tool Integration: Supports multiple tools (e.g., search, math) to handle various
task types.
By employing specialized agents with distinct functions, the RAG pipeline ensures:
Agentic RAG frameworks are much more versatile than traditional RAG setups. In a
traditional RAG system, the AI relies on a single tool—a vector database—for
retrieving information to shape its responses. While effective for basic data retrieval,
advanced frameworks can integrate multiple tools to handle a variety of tasks. For
We use cookies essential for this site to function well. Please click to help us improve its
example, they can perform complex mathematical calculations, write emails, analyze
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
data, or even make decisions based on contextual needs. This ability to incorporate
Show details
different tools makes them far more flexible and capable.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 27/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Additionally, agentic RAG systems excel in multistep reasoning. They are context-
aware, meaning they can decide when and how to use specific tools to solve problems
or accomplish tasks. This ensures better accuracy and efficiency in handling more
complex requirements.
Its ability to work collaboratively in multiagent systems sets agentic RAG apart.
Multiple AI agents can work together, achieving results that are often far better than
those of a single AI agent. This adaptability and scalability make agentic RAG a
powerful choice for dynamic, real-world applications.
Also read:
Task Complexity Handles simple query-based Handles complex multi-step tasks with
tasks but lacks advanced multiple tools and agents as needed for
decision-making retrieval, reasoning, and more
Key Role Combines LLMs with external Enhances RAG by using agents for
data retrieval to generate intelligent retrieval, response
responses generation, grading, critiquing, and
moreclick to help us improve its
We use cookies essential for this site to function well. Please
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Real-Time Cookies Policy.
Data Not possible in native RAG Designed for real-time data retrieval and
Retrieval Show details integration
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 28/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Integration with Tied to static retrieval from Deeply integrated with diverse retrieval
Retrieval pre-defined vector databases systems, agents control the process
Systems
Context- Limited by the static vector High, agents adapt to user query and
Awareness database, no advanced or retrieve context, including real-time data
real-time context-awareness
Copy Code
!pip install langchain==0.3.4
!pip install langchain-openai==0.2.3
!pip install langchain-community==0.3.3
!pip install jq==1.8.0
!pip install pymupdf==1.24.12
!pip install langchain-chroma==0.1.4
from getpass import getpass
OPENAI_KEY = getpass('Enter Open AI API Key: ')
import os
os.environ['OPENAI_API_KEY'] = OPENAI_KEY
from langchain_openai import OpenAIEmbeddings
openai_embed_model = OpenAIEmbeddings(model='text-embedding-3-small')
1. Core Functionalities
Show details
Copy Code
from langchain.document_loaders import JSONLoader
import json
from langchain.docstore.document import Document
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 29/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
# Load JSON documents
loader = JSONLoader(file_path='./rag_docs/wikidata_rag_demo.jsonl',
jq_schema='.',
text_content=False,
json_lines=True)
wiki_docs = loader.load()
# Process JSON documents
import json
from langchain.docstore.document import Document
wiki_docs_processed = []
for doc in wiki_docs:
doc = json.loads(doc.page_content)
metadata = {
"title": doc['title'],
"id": doc['id'],
"source": "Wikipedia"
}
data = ' '.join(doc['paragraphs'])
wiki_docs_processed.append(Document(page_content=data, metadata=metadata))
Output
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 30/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
doc_pages = loader.load()
splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overla
return splitter.split_documents(doc_pages)
from glob import glob
pdf_files = glob('./rag_docs/*.pdf')
# Process PDF files
paper_docs = []
for fp in pdf_files:
paper_docs.extend(create_simple_chunks(file_path=fp))
Output
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 31/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Copy Code
from langchain_openai import OpenAIEmbeddings
from langchain_chroma import Chroma
# Initialize embedding model
openai_embed_model = OpenAIEmbeddings(model='text-embedding-3-small')
# Combine documents
total_docs = wiki_docs_processed + paper_docs
# Create and save vector database
chroma_db = Chroma.from_documents(documents=total_docs,
collection_name='my_db',
embedding=openai_embed_model,
collection_metadata={"hnsw:space": "cosine"},
persist_directory="./my_db")
Copy Code
chroma_db = Chroma(persist_directory="./my_db",
collection_name='my_db',
embedding_function=openai_embed_model)
3. Semantic Retrieval
Copy Code
similarity_retriever = chroma_db.as_retriever(search_type="similarity", search_kw
# Query for semantic similarity
query = "What is machine learning?"
top_docs = similarity_retriever.invoke(query)
# Display results
from IPython.display import display, Markdown
def display_docs(docs):
for doc in docs:
print('Metadata:', doc.metadata)
print('Content Brief:')
display(Markdown(doc.page_content[:1000]))
print()
We use cookies essential for this site to function well. Please click to help us improve its
display_docs(top_docs)
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 32/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
4. RAG Pipeline
Prompt Template
Copy Code
from langchain_core.prompts import ChatPromptTemplate
rag_prompt = """You are an assistant who is an expert in question-answering tasks
We use cookies
Answer essential
the for this site to function
following well. Please
question usingclickonly
to helpthe
us improve its
following pieces of
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
If the answer is not in the context, do not make up answers, just
Cookies Policy.
Keep the answer detailed and well formatted based on the informat
Show details
Question:
{question}
Context:
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 33/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
{context}
Answer:
"""
rag_prompt_template = ChatPromptTemplate.from_template(rag_prompt)
Pipeline Construction
Copy Code
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
# Initialize ChatGPT model
chatgpt = ChatOpenAI(model_name="gpt-4o-mini", temperature=0)
# Format documents into a single string
def format_docs(docs):
return "\n\n".join(doc.page_content for doc in docs)
# Construct the RAG pipeline
qa_rag_chain = (
{
"context": (similarity_retriever | format_docs),
"question": RunnablePassthrough()
}
|
rag_prompt_template
|
chatgpt
)
Example Usage
Copy Code
query = "What is the difference between AI, ML, and DL?"
result = qa_rag_chain.invoke(query)
# Display the generated answer
from IPython.display import display, Markdown
display(Markdown(result.content))
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 34/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Copy Code
query = "What is LangGraph?"
result = qa_rag_chain.invoke(query)
display(Markdown(result.content))
Output
I don't know.
This is due to the fact that the document does not contain any information about the
LangGraph.
Here, we will create an Agentic RAG system that uses external information to discuss
the 2024 USWe
Open.
use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
1. Setting Up thedetails
Show Environment
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 35/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Set Up Jupyter Notebook: This can be done in the cloud environment or locally
by uploading pre-built notebooks.
Create WML Instance: Select the region and Lite plan for a free option.
Link WML to watsonx.ai Project: Integrate the project for seamless use.
Copy Code
!pip install langchain | tail -n 1
!pip install langchain-ibm | tail -n 1
!pip install langchain-community | tail -n 1
!pip install ibm-watsonx-ai | tail -n 1
!pip install ibm_watson_machine_learning | tail -n 1
!pip install chromadb | tail -n 1
!pip install tiktoken | tail -n 1
!pip install python-dotenv | tail -n 1
!pip install bs4 | tail -n 1
We use cookies essential for this site to function well. Please click to help us improve its
import os usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
from dotenv import
Cookies Policy.load_dotenv
from langchain_ibm import WatsonxEmbeddings, WatsonxLLM
Show details
from langchain.vectorstores import Chroma
from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 36/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.prompts import PromptTemplate
from langchain.tools import tool
from langchain.tools.render import render_text_description_and_args
from langchain.agents.output_parsers import JSONAgentOutputParser
from langchain.agents.format_scratchpad import format_log_to_str
from langchain.agents import AgentExecutor
from langchain.memory import ConversationBufferMemory
from langchain_core.runnables import RunnablePassthrough
from ibm_watson_machine_learning.metanames import GenTextParamsMetaNames as GenPa
from ibm_watsonx_ai.foundation_models.utils.enums import EmbeddingTypes
The Setup:
Copy Code
llm = WatsonxLLM(
model_id= "ibm/granite-3-8b-instruct",
url=credentials.get("url"),
apikey=credentials.get("apikey"),
project_id=project_id,
params={
GenParams.DECODING_METHOD: "greedy",
GenParams.TEMPERATURE: 0,
GenParams.MIN_NEW_TOKENS: 5,
GenParams.MAX_NEW_TOKENS:
We use cookies essential for this site 250,
to function well. Please click to help us improve its
usefulness with additional cookies. Learn
GenParams.STOP_SEQUENCES: about our use"Observation"],
["Human:", of cookies in our Privacy Policy &
}, Cookies Policy.
) Show details
template = "Answer the {query} accurately. If you do not know the answer, simply
prompt = PromptTemplate.from_template(template)
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 37/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
agent = prompt | llm
agent.invoke({"query": "What sport is played at the US Open?"})
Copy Code
agent.invoke({"query": "Where was the 2024 US Open Tennis Championship?"})
RecursiveCharacterTextSplitter.
Copy Code
urls = [
"https://www.ibm.com/case-studies/us-open",
"https://www.ibm.com/sports/usopen",
"https://newsroom.ibm.com/US-Open-AI-Tennis-Fan-Engagement",
"https://newsroom.ibm.com/2024-08-15-ibm-and-the-usta-serve-up-new-and-enhanc
]
docs = [WebBaseLoader(url).load() for url in urls]
docs_list = [item for sublist in docs for item in sublist]
docs_list[0]
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 38/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Copy Code
text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
chunk_size=250, chunk_overlap=0
doc_splitsWe
= use cookies essential for this site to function well. Please click to help us improve its
text_splitter.split_documents(docs_list)
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
#The embedding model that we are using is an IBM Slate™ model through the watsonx
Show details
embeddings = WatsonxEmbeddings(
model_id=EmbeddingTypes.IBM_SLATE_30M_ENG.value,
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 39/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
url=credentials["url"],
apikey=credentials["apikey"],
project_id=project_id,
)
#In order to store our embedded documents, we will use Chroma DB, an open source
vectorstore = Chroma.from_documents(
documents=doc_splits,
collection_name="agentic-rag-chroma",
embedding=embeddings,
)
Set up a retriever to enable queries over this knowledge base. We must set up a
Copy Code
retriever = vectorstore.as_retriever()
6. Defining Tools
Tools guide the agent to retrieve specific information from the vector store.
Copy Code
@tool
def get_IBM_US_Open_context(question: str):
"""Get context about IBM's involvement in the 2024 US Open Tennis Championshi
context = retriever.invoke(question)
return context
tools = [get_IBM_US_Open_context]
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 40/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Copy Code
system_prompt = """Respond to the human as helpfully and accurately as possible.
Use a json blob to specify a tool by providing an action key (tool name) and an a
Valid "action" values: "Final Answer" or {tool_names}
Provide only ONE action per $JSON_BLOB, as shown:"
```
{{
"action": $TOOL_NAME,
"action_input": $INPUT
}}
```
Follow this format:
Question: input question to answer
Thought: consider previous and subsequent steps
Action:
```
$JSON_BLOB
```
Observation: action result
... (repeat Thought/Action/Observation N times)
Thought: I know what to respond
Action:
```
{{
"action": "Final Answer",
"action_input": "Final response to human"
}}
Begin! Reminder to ALWAYS respond with a valid json blob of a single action.
Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observatio
human_prompt = """{input}
{agent_scratchpad}
(reminder to always respond in a JSON blob)"""
prompt = ChatPromptTemplate.from_messages(
[
("system", system_prompt),
MessagesPlaceholder("chat_history", optional=True),
We use cookies essential for this site to function well. Please click to help us improve its
("human", human_prompt),
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
] Cookies Policy.
)
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 41/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Agent Chain: Combine the prompt, LLM, tools, and memory into an
AgentExecutor.
Verify behavior for complex queries requiring tools (e.g., retrieving IBM’s US Open
involvement).
Copy Code
agent_executor.invoke({"input": "Where was the 2024 US Open Tennis Championship?"
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 42/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
'history': '',
We use cookies essential for this site to function well. Please click to help us improve its
'output': 'The 2024
usefulness withUS Open cookies.
additional TennisLearn
Championship
about our use of was held
cookies in ourat thePolicy
Privacy USTA& Billie
Jean King National Tennis Center in Flushing, Queens, New York.'}
Cookies Policy.
Show details
Great! The agent used its available RAG tool to return the location of the
2024 US Open, per the user's query. We even get to see the exact document
that the agent is retrieving its information from. Now, let's try a slightly
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 43/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
more complex question query. This time, the query will be about IBM's
involvement in the 2024 US Open.
Copy Code
agent_executor.invoke(
{"input": "How did IBM use watsonx at the 2024 US Open Tennis Championship?"}
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
{'input': 'How did IBM use watsonx at the 2024 US Open Tennis Championship?',
'history': 'Human: Where was the 2024 US Open Tennis Championship?\nAI: The
2024 US Open Tennis Championship was held at the USTA Billie Jean King
National Tennis Center in Flushing, Queens, New York.',
This structured system combines IBM’s watsonx.ai, LangChain, and machine learning
to build a versatile, knowledge-augmented AI agent tailored for both general and
domain-specific queries.
Also, if you are looking for an AI Agents course online, then explore: Agentic AI
Pioneer Program
Conclusion
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
RAG (Retrieval-Augmented
Cookies Policy.
Generation) enhances LLMs by combining external data
retrieval withShow details capabilities, improving accuracy and relevance and reducing
generative
hallucinations. However, it struggles with complex, multi-step queries. Agentic RAG
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 45/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
advances this by integrating intelligent agents that dynamically select tools, refine
queries, and handle specialized tasks like code generation or visualizations. It
supports multi-agent collaboration, ensuring adaptability, scalability, and precise
context-aware responses. While traditional RAG suits basic Q&A and research,
Agentic RAG excels in dynamic, data-intensive applications like real-time analysis and
enterprise systems. Agentic RAG’s modularity and intelligence make it ideal for
tackling complex tasks beyond the scope of traditional RAG systems.
I hope you find this guide helpful in understanding RAG vs Agentic RAG! If you any
Pankaj Singh
Hi, I am Pankaj Singh Negi - Senior Content Editor | Passionate about storytelling and
crafting compelling narratives that transform ideas into impactful content. I love
reading about technology revolutionizing our lifestyle.
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 46/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
4.7
4.5
4.6
4.8
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
Improving Real World RAG Systems: Key Challenges & Practical Solutions
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 47/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Explore practical solutions, advanced retrieval strategies, and agentic RAG systems to improve context,
relevance, and accuracy in AI-driven applications.
4.7
RECOMMENDED ARTICLES
Show details
Evolution of RAG, Long Context LLMs to Agentic RAG
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 48/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Submit reply
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Write fordetails
Show us
Write, captivate, and earn accolades and rewards for your work
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 49/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Flagship Courses
GenAI Pinnacle Program | GenAI Pinnacle Plus Program | AI/ML BlackBelt Courses | Agentic AI
Pioneer Program
Free Courses
We use cookies essential for this site to function well. Please click to help us improve its
Generative AI | DeepSeek | OpenAI Agent SDK | LLM Applications using Prompt Engineering |
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
DeepSeek from Scratch
Cookies Policy.| Stability.AI | SSM & MAMBA | RAG Systems using LlamaIndex |
Getting Started withdetails
Show LLMs | Python | Microsoft Excel | Machine Learning | Deep Learning |
Mastering Multimodal RAG | Introduction to Transformer Model | Bagging & Boosting | Loan
Prediction | Time Series Forecastingn | Tableau | Business Analytics | Vibe Coding in Windsurf
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 50/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Popular Categories
Generative AI | Prompt Engineering | Generative AI Application | News | Technical Guides | AI
Tools | Interview Preparation | Research Papers | Success Stories | Quiz | Use Cases | Listicles
Company Discover
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
About Us Blogs
Cookies Policy.
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 51/52
3/27/25, 10:05 AM RAG vs Agentic RAG: A Comprehensive Guide - Analytics Vidhya
Comprehensive Guides
Learn Engage
Contribute Enterprise
Terms & conditions Refund Policy Privacy Policy Cookies Policy © Analytics
Vidhya 2025.All rights reserved.
We use cookies essential for this site to function well. Please click to help us improve its
usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy &
Cookies Policy.
Show details
https://www.analyticsvidhya.com/blog/2024/11/rag-vs-agentic-rag/ 52/52