{"id":116043,"date":"2025-02-28T22:39:33","date_gmt":"2025-02-28T22:39:33","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/how-to-build-agentic-qa-rag-system-using-haystack-framework\/"},"modified":"2025-02-28T22:39:33","modified_gmt":"2025-02-28T22:39:33","slug":"how-to-build-agentic-qa-rag-system-using-haystack-framework","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=116043","title":{"rendered":"How to Build Agentic QA RAG System Using Haystack Framework"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"article-start\">\n<p>Imagine you are building a <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2023\/09\/ai-for-customer-service\/\" target=\"_blank\" rel=\"noreferrer noopener\">customer support AI<\/a> that needs to answer questions about your product. Sometimes it needs to pull information from your documentation, while other times it needs to search the web for the latest updates. Agentic <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2023\/09\/retrieval-augmented-generation-rag-in-ai\/\" target=\"_blank\" rel=\"noreferrer noopener\">RAG systems<\/a> come in handy in such types of complex AI applications. Think of them as smart research assistants who not only know your internal documentation but also decide when to go to search the web. In this guide, we will walk through the process of building an agentic QA RAG system using the Haystack framework.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-learning-objectives\">Learning Objectives<\/h4>\n<ul class=\"wp-block-list\">\n<li>Know what an agentic LLM is and understand how it is different from a RAG system.<\/li>\n<li>Familiarize the Haystack framework for agentic LLM applications.<\/li>\n<li>Understand the process of prompt building from a template and learn how to join different prompts together.<\/li>\n<li>Learn how to create embedding using ChromaDB in Haystack.<\/li>\n<li>Learn how to set up a complete local development system from embedding to generation.<\/li>\n<\/ul>\n<p><em><strong>This article was published as a part of the\u00a0<\/strong><\/em><a href=\"https:\/\/www.analyticsvidhya.com\/datahack\/blogathon\" target=\"_blank\" rel=\"noreferrer noopener\"><em><strong>Data Science Blogathon.<\/strong><\/em><\/a><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-an-agentic-llm\">What is an Agentic LLM?<\/h2>\n<p>An agentic LLM is an AI system that can autonomously make decisions and take actions based on its understanding of the task. Unlike traditional LLMs that mainly generate text responses, an agentic LLM can do a lot more. <span style=\"font-weight: 400;\">It can think, plan, and act with minimal human input. It assesses its knowledge, recognizing when it needs more information or external tools. <\/span>Agentic LLMs<span style=\"font-weight: 400;\"> don\u2019t rely on static data or indexed knowledge, instead, they decide which sources to trust and how to gather the best insights.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This type of system can also pick the right tools for the job. It can decide when it needs to retrieve documents, run calculations, or automate tasks. What sets them apart is its ability to break down complex problems into steps and execute them independently which makes it valuable for research, analysis, and workflow automation.<\/span><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-rag-vs-agentic-rag\">RAG vs Agentic RAG<\/h3>\n<p>Traditional RAG systems follow a linear process. <span style=\"font-weight: 400;\">When a query is received, the system first identifies the key elements within the request. It then searches the knowledge base, scanning for relevant information that can help design an accurate response. Once the relevant information or data is retrieved, the system processes it to generate a meaningful and contextually relevant response.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can understand the processes easily by the below diagram.<\/span><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"345\" height=\"647\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/RAG.webp\" alt=\"How RAG works\" class=\"wp-image-223556\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/RAG.webp 345w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/RAG-160x300.webp 160w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/RAG-150x281.webp 150w\" sizes=\"(max-width: 345px) 100vw, 345px\"\/><figcaption class=\"wp-element-caption\">Source: Author <\/figcaption><\/figure>\n<\/div>\n<p>Now, an agentic RAG system enhances this process by:<\/p>\n<ul class=\"wp-block-list\">\n<li>Evaluating query requirements<\/li>\n<li>Deciding between multiple knowledge sources<\/li>\n<li>Potentially combining information from different sources<\/li>\n<li>Making autonomous decisions about response strategy<\/li>\n<li>Providing source-attributed responses<\/li>\n<\/ul>\n<p>The <a href=\"https:\/\/www.youtube.com\/watch?v=an_sy9ahvV0\" target=\"_blank\" rel=\"noreferrer noopener\">key difference<\/a> lies in the system\u2019s ability to make intelligent decisions about how to handle queries, rather than following a fixed retrieval-generation pattern.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-understanding-haystack-framework-components\">Understanding Haystack Framework Components<\/h2>\n<p>Haystack is an open-source framework for building production-ready AI, LLM applications, RAG pipelines, and search systems. It<span style=\"font-weight: 400;\"> offers a powerful and flexible framework for building LLM applications. It allows you to integrate models from various platforms such as Huggingface, OpenAI, CoHere, Mistral, and Local Ollama. You can also deploy models on cloud services like <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2022\/05\/an-introduction-to-aws-sagemaker-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">AWS SageMaker<\/a>, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2024\/02\/building-end-to-end-generative-ai-models-with-aws-bedrock\/\" target=\"_blank\" rel=\"noreferrer noopener\">BedRock<\/a>, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2021\/09\/a-comprehensive-guide-on-using-azure-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\">Azure<\/a>, and <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2022\/12\/gcp-the-future-of-cloud-computing\/\" target=\"_blank\" rel=\"noreferrer noopener\">GCP<\/a>. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Haystack provides robust document stores for efficient data management. It also comes with a comprehensive set of tools for evaluation, monitoring, and data integration which ensure smooth performance across all layers of your application. It also has strong community collaboration which makes new service integration from various service providers periodically.<\/span><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-what-can-you-build-using-haystack\">What Can You Build Using Haystack?<\/h3>\n<ul class=\"wp-block-list\">\n<li>Simple to advance RAG on your data, using robust retrieval and generation techniques.<\/li>\n<li>Chatbot and agents using up-to-date GenAI models like <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2024\/07\/chatgpt-4-vision\/\" target=\"_blank\" rel=\"noreferrer noopener\">GPT-4<\/a>, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2024\/09\/llama-3-2-models\/\" target=\"_blank\" rel=\"noreferrer noopener\">Llama3.2<\/a>, Deepseek-R1.<\/li>\n<li>Generative multimodal question-answering system on mixed types (images, text, audio, and table) knowledge base.<\/li>\n<li>Information extraction from documents or building knowledge graphs.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-haystack-building-blocks\">Haystack Building Blocks<\/h2>\n<p>Haystack has two primary concepts for building fully functional GenAI LLM systems \u2013 components and pipelines. Let\u2019s understand them with a simple example of RAG on Japanese Anime Characters<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-components\">Components<\/h3>\n<p>Components are the core building blocks of Haystack. They can perform tasks such as document storing, document retrieval, text generation, and embedding. Haystack has many components you can use directly after installation, it also provides APIs for making your own components by writing a Python class.<\/p>\n<p>There is a collection of integration from partner companies and the community.<\/p>\n<p><strong>Install Libraries and set <a href=\"https:\/\/ollama.com\/\" target=\"_blank\" rel=\"nofollow noopener\">Ollama<\/a><\/strong><\/p>\n<pre class=\"wp-block-code\"><code>$ pip install haystack-ai ollama-haystack\n\n# On you system download Ollama and install LLM\n\nollama pull llama3.2:3b\n\nollama pull nomic-embed-text\n\n\n# And then start ollama server\nollama serve<\/code><\/pre>\n<p><b>Import some components<\/b><\/p>\n<pre class=\"wp-block-code\"><code>from haystack import Document, Pipeline\nfrom haystack.components.builders.prompt_builder import PromptBuilder\nfrom haystack.components.retrievers.in_memory import InMemoryBM25Retriever\nfrom haystack.document_stores.in_memory import InMemoryDocumentStore\nfrom haystack_integrations.components.generators.ollama import OllamaGenerator<\/code><\/pre>\n<p>Create a document and document store<\/p>\n<pre class=\"wp-block-code\"><code>document_store = InMemoryDocumentStore()\ndocuments = [\n    Document(\n        content=\"Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage.\"\n    ),\n    Document(\n        content=\"Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece.\"\n    ),\n    Document(\n        content=\"Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell.\"\n    ),\n    Document(\n        content=\"Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names.\"\n    ),\n    Document(\n        content=\"Levi Ackerman is humanity\u2019s strongest soldier, fighting against the Titans to protect mankind.\"\n    ),\n]<\/code><\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-pipeline\">Pipeline<\/h3>\n<p>Pipelines are the backbone of Haystack\u2019s framework. They define the flow of data between different components. Pipelines are essentially a Directed Acyclic Graph (DAG). A single component with multiple outputs can connect to another single component with multiple inputs.<\/p>\n<p>You can define pipeline by<\/p>\n<pre class=\"wp-block-code\"><code>pipe = Pipeline()\n\npipe.add_component(\"retriever\", InMemoryBM25Retriever(document_store=document_store))\npipe.add_component(\"prompt_builder\", PromptBuilder(template=template))\npipe.add_component(\n    \"llm\", OllamaGenerator(model=\"llama3.2:1b\", url=\"http:\/\/localhost:11434\")\n)\npipe.connect(\"retriever\", \"prompt_builder.documents\")\npipe.connect(\"prompt_builder\", \"llm\")<\/code><\/pre>\n<p>You can visualize the pipeline<\/p>\n<pre class=\"wp-block-code\"><code>image_param = {\n    \"format\": \"img\",\n    \"type\": \"png\",\n    \"theme\": \"forest\",\n    \"bgColor\": \"f2f3f4\",\n}\npipe.show(params=image_param)<\/code><\/pre>\n<p>The pipeline provides:<\/p>\n<ul class=\"wp-block-list\">\n<li>Modular workflow management<\/li>\n<li>Flexible components arrangement<\/li>\n<li>Easy debugging and monitoring<\/li>\n<li>Scalable processing architecture<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-nodes\">Nodes<\/h3>\n<p>Nodes are the basic processing units that can be connected in a pipeline these nodes are the components that perform specific tasks.<\/p>\n<p>Examples of nodes from the above pipeline<\/p>\n<pre class=\"wp-block-code\"><code>pipe.add_component(\"retriever\", InMemoryBM25Retriever(document_store=document_store))\npipe.add_component(\"prompt_builder\", PromptBuilder(template=template))\npipe.add_component(\n    \"llm\", OllamaGenerator(model=\"llama3.2:1b\", url=\"http:\/\/localhost:11434\")\n)\n<\/code><\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-connection-graph\">Connection Graph<\/h3>\n<p>The connection\u00a0graph defines how components interact.<\/p>\n<p>From the above pipeline, you can visualize the connection graph.<\/p>\n<pre class=\"wp-block-code\"><code>image_param = {\n    \"format\": \"img\",\n    \"type\": \"png\",\n    \"theme\": \"forest\",\n    \"bgColor\": \"f2f3f4\",\n}\npipe.show(params=image_param)<\/code><\/pre>\n<p>The connection graph of the anime pipeline<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"276\" height=\"1290\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_Yq64Z4B.webp\" alt=\"Building Agentic QA-RAG Using Haystack Framework\" class=\"wp-image-223704\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_Yq64Z4B.webp 276w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_Yq64Z4B-64x300.webp 64w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_Yq64Z4B-150x701.webp 150w\" sizes=\"auto, (max-width: 276px) 100vw, 276px\"\/><\/figure>\n<p>This graph structure:<\/p>\n<ul class=\"wp-block-list\">\n<li>Defines data flow between components<\/li>\n<li>Manages input\/output relationships<\/li>\n<li>Enables parallel processing where possible<\/li>\n<li>Creates flexible processing pathways.<\/li>\n<\/ul>\n<p>Now we can query our anime knowledge base using the prompt.<\/p>\n<p><strong>Create a prompt template<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>template = \"\"\"\nGiven only the following information, answer the question.\nIgnore your own knowledge.\n\nContext:\n{% for document in documents %}\n    {{ document.content }}\n{% endfor %}\n\nQuestion: {{ query }}?\n\"\"\"<\/code><\/pre>\n<p>This prompt will provide an answer taking information from the document base.<\/p>\n<p>Query using prompt and retriever<\/p>\n<pre class=\"wp-block-code\"><code>query = \"How Goku eliminate people?\"\nresponse = pipe.run({\"prompt_builder\": {\"query\": query}, \"retriever\": {\"query\": query}})\nprint(response[\"llm\"][\"replies\"])<\/code><\/pre>\n<p><strong>Response:<\/strong><\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"440\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/goku_res.webp\" alt=\"RAG response\" class=\"wp-image-223705\" style=\"width:588px;height:auto\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/goku_res.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/goku_res-300x151.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/goku_res-768x388.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/goku_res-150x76.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>This RAG is simple yet conceptually valuable to the newcomer. Now that we have understood most of the concepts of Haystack frameworks, we can deep dive into our main project. If any new thing comes up I will explain along the way.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-question-answer-rag-project-for-higher-secondary-physics\">Question-Answer RAG Project for Higher Secondary Physics<\/h2>\n<p>We will build an NCERT Physics books-based Question Answer RAG for higher secondary students. It will provide answers to the query by taking information from the NCERT books, and If the information is not there it will search the web to get that information.<br \/>For this, I will use:<\/p>\n<ul class=\"wp-block-list\">\n<li>Local Llama3.2:3b or Llama3.2:1b<\/li>\n<li>ChromaDB for embedding storage<\/li>\n<li>Nomic Embed Text model for local embedding<\/li>\n<li>DuckDuckGo search for web search or Tavily Search (optional)<\/li>\n<\/ul>\n<p>I use a free, totally localized system.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-setting-up-the-developer-environment\">Setting Up the Developer Environment<\/h3>\n<p>We will setup a conda env Python 3.12<\/p>\n<pre class=\"wp-block-code\"><code>$conda create --name agenticlm python=3.12\n\n$conda activate agenticlm<\/code><\/pre>\n<h4 class=\"wp-block-heading\" id=\"h-install-necessary-package\">Install Necessary Package<\/h4>\n<pre class=\"wp-block-code\"><code>$pip install haystack-ai ollama-haystack pypdf\n\n$pip install chroma-haystack duckduckgo-api-haystack<\/code><\/pre>\n<p>Now create a project directory named <b>qagent<\/b>.<\/p>\n<pre class=\"wp-block-code\"><code>$md qagent # create dir\n\n$cd qagent # change to dir\n\n$ code .   # open folder in vscode<\/code><\/pre>\n<p>You can use plain Python files for the project or Jupyter Notebook for the project it does not matter. I will use a plain Python file.<\/p>\n<p>Create a <b>main.py<\/b> file on the project root.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-importing-necessary-libraries\">Importing Necessary Libraries<\/h4>\n<ul class=\"wp-block-list\">\n<li>System packages<\/li>\n<li>Core haystack components<\/li>\n<li>ChromaDB for embedding components<\/li>\n<li>Ollama Components for Local Inferences<\/li>\n<li>And Duckduckgo for web search<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code># System packages\nimport os\nfrom pathlib import Path<\/code><\/pre>\n<pre class=\"wp-block-code\"><code># Core haystack components\nfrom haystack import Pipeline\nfrom haystack.components.writers import DocumentWriter\nfrom haystack.components.joiners import BranchJoiner\nfrom haystack.document_stores.types import DuplicatePolicy\nfrom haystack.components.converters import PyPDFToDocument\nfrom haystack.components.routers import ConditionalRouter\nfrom haystack.components.builders.prompt_builder import PromptBuilder\nfrom haystack.components.preprocessors import DocumentCleaner, DocumentSplitter<\/code><\/pre>\n<pre class=\"wp-block-code\"><code># ChromaDB integration\nfrom haystack_integrations.document_stores.chroma import ChromaDocumentStore\nfrom haystack_integrations.components.retrievers.chroma import (\n    ChromaEmbeddingRetriever,\n)<\/code><\/pre>\n<pre class=\"wp-block-code\"><code># Ollama integration\nfrom haystack_integrations.components.embedders.ollama.document_embedder import (\n    OllamaDocumentEmbedder,\n)\nfrom haystack_integrations.components.embedders.ollama.text_embedder import (\n    OllamaTextEmbedder,\n)\nfrom haystack_integrations.components.generators.ollama import OllamaGenerator<\/code><\/pre>\n<pre class=\"wp-block-code\"><code># Duckduckgo search integration\nfrom duckduckgo_api_haystack import DuckduckgoApiWebSearch<\/code><\/pre>\n<h4 class=\"wp-block-heading\" id=\"h-creating-a-document-store\">Creating a Document Store<\/h4>\n<p>Document store is the most important here we will store our embedding for retrieval, we use <b>ChromaDB <\/b>for the embedding store, and as you may see in the earlier example, we use InMemoryDocumentStore for fast retrieval because then our data was tiny but for a robust system of retrieval we don\u2019t rely on the InMemoryStore, it will hog the memory and we will have creat embeddings every time we start the system.<\/p>\n<p>The solution is a Vector database such as Pinecode, Weaviate, Postgres Vector DB, or ChromaDB. I use ChromaDB because free, open-source, easy to use, and robust.<\/p>\n<pre class=\"wp-block-code\"><code># Chroma DB integration component for document(embedding) store\n\ndocument_store = ChromaDocumentStore(persist_path=\"qagent\/embeddings\")<\/code><\/pre>\n<p><b>persist_path<\/b> is where you want to store your embedding.<\/p>\n<p><b>PDF files path<\/b><\/p>\n<pre class=\"wp-block-code\"><code>HERE = Path(__file__).resolve().parent\nfile_path = [HERE \/ \"data\" \/ Path(name) for name in os.listdir(\"QApipeline\/data\")]<\/code><\/pre>\n<p>It will create a list of files from the data folder which consists of our PDF files.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-document-preprocessing-components\">Document Preprocessing Components<\/h3>\n<p>We will use Haystack\u2019s built-in document preprocessor such as cleaner, splitter, and file converter, and then use a writer to write the data into the store.<\/p>\n<p><b>Cleaner: <\/b>It will clean the extra space, repeated lines, empty lines, etc from the documents.<\/p>\n<pre class=\"wp-block-code\"><code>cleaner = DocumentCleaner()<\/code><\/pre>\n<p><b>Splitter: <\/b>It will split the document in various ways such as words, sentences, para, pages.<\/p>\n<pre class=\"wp-block-code\"><code>splitter = DocumentSplitter()<\/code><\/pre>\n<p><b>File Converter: <\/b>It will use the pypdf to convert the pdf to documents.<\/p>\n<pre class=\"wp-block-code\"><code>file_converter = PyPDFToDocument()<\/code><\/pre>\n<p><b>Writer: <\/b>It will store the document where you want to store the documents and for duplicate documents, it will overwrite with previous one.<\/p>\n<pre class=\"wp-block-code\"><code>writer = DocumentWriter(document_store=document_store, policy=DuplicatePolicy.OVERWRITE)<\/code><\/pre>\n<p>Now set the embedder for document indexing.<\/p>\n<p><b>Embedder: Nomic Embed Text<\/b><\/p>\n<p>We will use nomic-embed-text embedder which is very effective and free inHuggingface and Ollama.<\/p>\n<p>Before you run your indexing pipeline open your terminal and type below to Pull the nomic-embed-text and llama3.2:3b model from the Ollama model store<\/p>\n<pre class=\"wp-block-code\"><code>$ ollama pull nomic-embed-text\n\n$ ollama pull llama3.2:3b<\/code><\/pre>\n<p>and start Ollama by typing the command<b> ollama serve <\/b>in your terminal<\/p>\n<p>now embedder component<\/p>\n<pre class=\"wp-block-code\"><code>embedder = OllamaDocumentEmbedder(\n    model=\"nomic-embed-text\", url=\"http:\/\/localhost:11434\"\n)<\/code><\/pre>\n<p>We use <b>OllamaDocumentEmbedder <\/b>component for embedding documents, but if you want to embed the text string then you have to use <b>OllamaTextEmbedder.<\/b><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-creating-indexing-pipeline\">Creating Indexing Pipeline<\/h3>\n<p>Like our previous toy RAG example, we will start by initiating the Pipeline class.<\/p>\n<pre class=\"wp-block-code\"><code>indexing_pipeline = Pipeline()<\/code><\/pre>\n<p>Now we will add the components to our pipeline one by one<\/p>\n<pre class=\"wp-block-code\"><code>indexing_pipeline.add_component(\"embedder\", embedder)\nindexing_pipeline.add_component(\"converter\", file_converter)\nindexing_pipeline.add_component(\"cleaner\", cleaner)\nindexing_pipeline.add_component(\"splitter\", splitter)\nindexing_pipeline.add_component(\"writer\", writer)<\/code><\/pre>\n<p>Adding components to the pipeline does not care about order so, you can add components in any order. but connecting is what matters.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-connecting-components-to-the-pipeline-graph\">Connecting Components to the Pipeline Graph<\/h4>\n<pre class=\"wp-block-code\"><code>indexing_pipeline.connect(\"converter\", \"cleaner\")\nindexing_pipeline.connect(\"cleaner\", \"splitter\")\nindexing_pipeline.connect(\"splitter\", \"embedder\")\nindexing_pipeline.connect(\"embedder\", \"writer\")<\/code><\/pre>\n<p>Here, order matters, because how you connect the component tells the pipeline how the data will flow through the pipeline. It is like, It doesn\u2019t matter in which order or from where you buy your plumbing items but how to put them together will decide whether you get your water or not.<\/p>\n<p>The converter converts the PDFs and sends them to clean for cleaning. Then the cleaner sends the cleaned documents to the splitter for chunking. Those chunks will then pass to the embedded for vectorization, and the last embedded will hand over these embeddings to the writer for storage.<\/p>\n<p>Understand! Ok, let me give you a visual graph of the indexing so you can inspect the data flow.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-draw-indexing-pipeline\">Draw Indexing Pipeline<\/h4>\n<pre class=\"wp-block-code\"><code>image_param = {\n    \"format\": \"img\",\n    \"type\": \"png\",\n    \"theme\": \"forest\",\n    \"bgColor\": \"f2f3f4\",\n}\n\nindexing_pipeline.draw(\"indexing_pipeline.png\", params=image_param)  # type: ignore<\/code><\/pre>\n<p>Yeah, you can create a nice mermaid graph from the haystack pipeline easily.<\/p>\n<p><strong>Graph of Indexing Pipeline<\/strong><\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"394\" height=\"1522\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/indexing_pipeline.webp\" alt=\"Building Agentic QA-RAG Using Haystack Framework\" class=\"wp-image-223706\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/indexing_pipeline.webp 394w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/indexing_pipeline-78x300.webp 78w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/indexing_pipeline-150x579.webp 150w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\"\/><\/figure>\n<p>I assume now you have fully grasped the idea behind the Haystack Pipeline. Give a thank to you Plumber.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-implement-a-router\">Implement a Router<\/h3>\n<p>Now, we need to create a router to route the data through a different path. In this case, we\u2019ll use a conditional router which will do our routing job on certain conditions. <span style=\"font-weight: 400;\">The conditional router will evaluate conditions based on component output. It will direct data flow through different pipeline branches which enables dynamic decision-making. It will also have robust fallback strategies.<\/span><\/p>\n<pre class=\"wp-block-code\"><code># Conditions for routing\nroutes = [\n    {\n        \"condition\": \"{{'no_answer' in replies[0]}}\",\n        \"output\": \"{{query}}\",\n        \"output_name\": \"go_to_websearch\",\n        \"output_type\": str,\n    },\n    {\n        \"condition\": \"{{'no_answer' not in replies[0]}}\",\n        \"output\": \"{{replies[0]}}\",\n        \"output_name\": \"answer\",\n        \"output_type\": str,\n    },\n]\n\n\n# router component\n\nrouter = ConditionalRouter(routes=routes)<\/code><\/pre>\n<p>When the system gets no_answer replies from the embedding store context, then it will go to the web search tools for collecting relevant data from the internet.<\/p>\n<p>For web search, we will use Duckduckgo API or Tavily, here I have used Duckduckgo.<\/p>\n<pre class=\"wp-block-code\"><code>websearch = DuckduckgoApiWebSearch(top_k=5)<\/code><\/pre>\n<p>Ok, most of the heavy lifting has been done. Now, time for prompt engineering<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-create-prompt-templates\">Create Prompt Templates<\/h3>\n<p>We will use the Haystack PromptBuilder component for building prompts from the template<\/p>\n<p>First, we will create a prompt for qa<\/p>\n<pre class=\"wp-block-code\"><code>template_qa = \"\"\"\nGiven ONLY the following information, answer the question.\nIf the answer is not contained within the documents reply with \"no_answer.\nIf the answer is contained within the documents, start the answer with \"FROM THE KNOWLEDGE BASE: \".\n\nContext:\n{% for document in documents %}\n    {{ document.content }}\n{% endfor %}\n\nQuestion: {{ query }}?\n\n\"\"\"<\/code><\/pre>\n<p>It will take the context from the document and try to answer the question. But if it does not find relevant context in the documents it will reply no_answer.<\/p>\n<p>Now, in the second prompt after getting no_answer from the LLM, the system will use the web search tools for gathering context from the internet.<\/p>\n<p><strong>Duckduckgo prompt template<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>template_websearch = \"\"\"\nAnswer the following query given the documents retrieved from the web.\nStart the answer with \"FROM THE WEB: \".\n\nDocuments:\n{% for document in documents %}\n    {{ document.content }}\n{% endfor %}\n\nQuery: {{query}}\n\n\"\"\"<\/code><\/pre>\n<p>It will facilitate the system to go to the web search and try to answer the query.<\/p>\n<p><strong>Creating prompt using PromptBuilder from Haystack<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>prompt_qa = PromptBuilder(template=template_qa)\n\nprompt_builder_websearch = PromptBuilder(template=template_websearch)<\/code><\/pre>\n<p>We will use Haystack prompt joiner to join to branches of the prompt together.<\/p>\n<pre class=\"wp-block-code\"><code>prompt_joiner = BranchJoiner(str)<\/code><\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-implement-query-pipeline\">Implement Query Pipeline<\/h3>\n<p>The query pipeline will be embedding the query gathering contextual resources from the embeddings and answering our query using LLM or Web Search tool.<\/p>\n<p>It is similar to the indexing pipeline.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-initiating-pipeline\">Initiating Pipeline<\/h4>\n<pre class=\"wp-block-code\"><code>query_pipeline = Pipeline()<\/code><\/pre>\n<p>Adding components to the query pipeline<\/p>\n<pre class=\"wp-block-code\"><code>query_pipeline.add_component(\"text_embedder\", OllamaTextEmbedder())\nquery_pipeline.add_component(\n    \"retriever\", ChromaEmbeddingRetriever(document_store=document_store)\n)\nquery_pipeline.add_component(\"prompt_builder\", prompt_qa)\nquery_pipeline.add_component(\"prompt_joiner\", prompt_joiner)\nquery_pipeline.add_component(\n    \"llm\",\n    OllamaGenerator(model=\"llama3.2:3b\", timeout=500, url=\"http:\/\/localhost:11434\"),\n)\nquery_pipeline.add_component(\"router\", router)\nquery_pipeline.add_component(\"websearch\", websearch)\nquery_pipeline.add_component(\"prompt_builder_websearch\", prompt_builder_websearch)<\/code><\/pre>\n<p>Here, for LLM generation we use the OllamaGenerator component for generating answers using Llama3.2:3b or 1b or whatever LLM you like with tools calling.<\/p>\n<p>Connecting all the components together for query flow and answer generation<\/p>\n<pre class=\"wp-block-code\"><code>query_pipeline.connect(\"text_embedder.embedding\", \"retriever.query_embedding\")\nquery_pipeline.connect(\"retriever\", \"prompt_builder.documents\")\nquery_pipeline.connect(\"prompt_builder\", \"prompt_joiner\")\nquery_pipeline.connect(\"prompt_joiner\", \"llm\")\nquery_pipeline.connect(\"llm.replies\", \"router.replies\")\nquery_pipeline.connect(\"router.go_to_websearch\", \"websearch.query\")\nquery_pipeline.connect(\"router.go_to_websearch\", \"prompt_builder_websearch.query\")\nquery_pipeline.connect(\"websearch.documents\", \"prompt_builder_websearch.documents\")\nquery_pipeline.connect(\"prompt_builder_websearch\", \"prompt_joiner\")<\/code><\/pre>\n<p>In summary of the above connection:<\/p>\n<ol class=\"wp-block-list\">\n<li>The embedding from the text_embedder sent to the retriever\u2019s query embedding.<\/li>\n<li>The retriever sends data to the prompt_builder\u2019s document.<\/li>\n<li>Prompt builder go to the prompt joiner to join with other prompts.<\/li>\n<li>Prompt joiner passes data to the llm for generation.<\/li>\n<li>LLM\u2019s replies go to the routers to check if the reply has <b>no_answer <\/b>or not.\u00a0If <b>no_answer <\/b>then it will go to the web search module.<\/li>\n<li>Web search sends the data to a web search prompt as a query.<\/li>\n<li>Web search documents send data to the web search documents.<\/li>\n<li>The web search prompt sends the data to the prompt joiner.<\/li>\n<li>And the prompt joiner will send the data to the LLM for answer generation.<\/li>\n<\/ol>\n<p>Why not see for yourself?<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-draw-query-pipeline-graph\">Draw Query Pipeline Graph<\/h3>\n<pre class=\"wp-block-code\"><code>query_pipeline.draw(\"agentic_qa_pipeline.png\", params=image_param)  # type: ignore<\/code><\/pre>\n<p><b>Query Graph<\/b><\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"2128\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline.webp\" alt=\"Building Agentic QA-RAG Using Haystack Framework\" class=\"wp-image-223707\" style=\"width:616px;height:auto\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline-123x300.webp 123w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline-768x1874.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline-629x1536.webp 629w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline-839x2048.webp 839w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/agentic_qa_pipeline-150x366.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>I know it is a huge graph but it will show you exactly what is going on under the belly of the beast.<\/p>\n<p>Now it is time to enjoy the fruit of our hard work.<\/p>\n<p>Create a function for easy querying.<\/p>\n<pre class=\"wp-block-code\"><code>def get_answer(query: str):\n    response = query_pipeline.run(\n        {\n            \"text_embedder\": {\"text\": query},\n            \"prompt_builder\": {\"query\": query},\n            \"router\": {\"query\": query},\n        }\n    )\n    return response[\"router\"][\"answer\"]<\/code><\/pre>\n<p>It is an easy simple function for answer generation.<\/p>\n<p>Now run your main script for indexing the NCERT physics book<\/p>\n<pre class=\"wp-block-code\"><code>indexing_pipeline.run({\"converter\": {\"sources\": file_path}})<\/code><\/pre>\n<p>It is a one-time job, after indexing you must comment on this line otherwise it will start re-indexing the books.<\/p>\n<p>and the bottom of the file we write our driver code for the query<\/p>\n<pre class=\"wp-block-code\"><code>if __name__ == \"__main__\":\n    query = \"Give me 5 MCQ on resistivity?\"\n    print(get_answer(query))<\/code><\/pre>\n<p>MCQ on resistivity from the book\u2019s knowledge<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"629\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_8zfl6k1.webp\" alt=\"RAG system response\" class=\"wp-image-223708\" style=\"width:700px;height:auto\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_8zfl6k1.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_8zfl6k1-300x216.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_8zfl6k1-768x554.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_8zfl6k1-150x108.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>Another question that is not in the book<\/p>\n<pre class=\"wp-block-code\"><code>if __name__ == \"__main__\":\n    query = \"What is Photosynthesis?\"\n    print(get_answer(query))<\/code><\/pre>\n<p><strong>Output<\/strong><\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"407\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_6tu9tAI.webp\" alt=\"Output by RAG model\" class=\"wp-image-223709\" style=\"width:703px;height:auto\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_6tu9tAI.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_6tu9tAI-300x140.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_6tu9tAI-768x358.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_6tu9tAI-150x70.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>Let\u2019s try another question.<\/p>\n<pre class=\"wp-block-code\"><code>if __name__ == \"__main__\":\n    query = (\n        \"Tell me what is DRIFT OF ELECTRONS AND THE ORIGIN OF RESISTIVITY from the book\"\n    )\n    print(get_answer(query))<\/code><\/pre>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"275\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_a0bJG0P.webp\" alt=\"Building Agentic QA-RAG Using Haystack Framework\" class=\"wp-image-223710\" style=\"width:704px;height:auto\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_a0bJG0P.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_a0bJG0P-300x95.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_a0bJG0P-768x242.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/02\/image_a0bJG0P-150x47.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>So, it\u2019s working! We can use more data, books, or PDFs for embedding which will generate more contextual-aware answers. Also, LLMs such as GPT-4o, Anthropic\u2019s Claude, or other cloud LLMs will do the job even better.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n<p>Our agentic RAG system demonstrates the flexibility and robustness of the Haystack framework with its power of combining components and pipelines. This RAG can be made production-ready by deploying to the web service platform and also using better paid LLM such as OpenAI, and nthropic. You can build a UI using Streamlit or React-based web SPA for a better user experience.<\/p>\n<p>You can find all the code used in the article, <a href=\"https:\/\/github.com\/avizyt\/blog-post-code\/tree\/main\/QArag\" target=\"_blank\" rel=\"nofollow noopener\">here.<\/a><\/p>\n<h4 class=\"wp-block-heading\" id=\"h-key-takeaways\">Key Takeaways<\/h4>\n<ul class=\"wp-block-list\">\n<li>Agentic RAG systems provide more intelligent and flexible responses than traditional RAG.<\/li>\n<li>Haystack\u2019s pipeline architecture enables complex, modular workflows.<\/li>\n<li>Routers enable dynamic decision-making in response generation.<\/li>\n<li>Connection graphs provide flexible and maintainable component interactions.<\/li>\n<li>Integration of multiple knowledge sources enhances response quality.<\/li>\n<\/ul>\n<p><strong>The media shown in this article is not owned by Analytics Vidhya and is used at the Author\u2019s discretion<\/strong>.<a href=\"https:\/\/www.analyticsvidhya.com\/blog\/author\/mimi6\/\"\/><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-frequently-asked-question\">Frequently Asked Question<\/h2>\n<div class=\"schema-faq wp-block-yoast-faq-block\">\n<div class=\"schema-faq-section\" id=\"faq-question-1740647190720\"><strong class=\"schema-faq-question\">Q1. How does the system handle unknown queries?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. The system uses its router component to automatically fall back to web search when local knowledge is insufficient, ensuring comprehensive coverage.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1740647201632\"><strong class=\"schema-faq-question\">Q2. What advantages does the pipeline architecture offer?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. The pipeline architecture enables modular development, easy testing, and flexible component arrangement, making the system maintainable and extensible.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1740647214160\"><strong class=\"schema-faq-question\">Q3. How does the connection graph enhance system functionality?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. The connection graph enables complex data flows and parallel processing, improving system efficiency and flexibility in handling different types of queries.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1740647225055\"><strong class=\"schema-faq-question\">Q4. Can I use other LLM APIs?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. Yes, it is very easy just install the necessary integration package for the respective LLM API such as Gemini, Anthropic, and Groq, and use it with your API keys.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"border-top py-3 author-info my-4\">\n<div class=\"author-card d-flex align-items-center\">\n<div class=\"flex-shrink-0 overflow-hidden\">\n                                    <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/author\/avizyt\/\" class=\"text-decoration-none active-avatar\"><br \/>\n                                                                       <img decoding=\"async\" src=\"https:\/\/av-eks-lekhak.s3.amazonaws.com\/media\/lekhak-profile-images\/converted_image_9z6Gys1.webp\" width=\"48\" height=\"48\" alt=\"Avijit Biswas\" loading=\"lazy\" class=\"rounded-circle\"\/><\/p>\n<p>                                <\/a>\n                                <\/div>\n<\/p><\/div>\n<p>         A self-taught, project-driven learner, love to work on complex projects on deep learning, Computer vision, and NLP. I always try to get a deep understanding of the topic which may be in any field such as Deep learning, Machine learning, or Physics. Love to create content on my learning. Try to share my understanding with the worlds.              <\/p>\n<\/p><\/div>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Imagine you are building a customer support AI that needs to answer questions about your product. Sometimes it needs to pull information from your documentation, while other times it needs to search the web for the latest updates. Agentic RAG systems come in handy in such types of complex AI applications. Think of them as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":116046,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[25423,5815,5293,13782,51468,32726,2345],"dealstore":[],"offerexpiration":[],"class_list":["post-116043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-agentic","tag-blogathon","tag-build","tag-framework","tag-haystack","tag-rag","tag-system"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=116043\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"Imagine you are building a customer support AI that needs to answer questions about your product. Sometimes it needs to pull information from your documentation, while other times it needs to search the web for the latest updates. Agentic RAG systems come in handy in such types of complex AI applications. Think of them as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=116043\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-28T22:39:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"872\" \/>\n\t<meta property=\"og:image:height\" content=\"473\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=116043#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"How to Build Agentic QA RAG System Using Haystack Framework\",\"datePublished\":\"2025-02-28T22:39:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043\"},\"wordCount\":2592,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp\",\"keywords\":[\"agentic\",\"Blogathon\",\"Build\",\"Framework\",\"Haystack\",\"RAG\",\"SYSTEM\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=116043#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=116043\",\"url\":\"https:\/\/fivemor.com\/?p=116043\",\"name\":\"How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp\",\"datePublished\":\"2025-02-28T22:39:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=116043#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=116043\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=116043#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp\",\"width\":872,\"height\":473},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=116043#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build Agentic QA RAG System Using Haystack Framework\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=116043","og_locale":"en_US","og_type":"article","og_title":"How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network","og_description":"Imagine you are building a customer support AI that needs to answer questions about your product. Sometimes it needs to pull information from your documentation, while other times it needs to search the web for the latest updates. Agentic RAG systems come in handy in such types of complex AI applications. Think of them as [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=116043","og_site_name":"Som2ny Network","article_published_time":"2025-02-28T22:39:33+00:00","og_image":[{"width":872,"height":473,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp","type":"image\/webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=116043#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=116043"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"How to Build Agentic QA RAG System Using Haystack Framework","datePublished":"2025-02-28T22:39:33+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=116043"},"wordCount":2592,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=116043#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp","keywords":["agentic","Blogathon","Build","Framework","Haystack","RAG","SYSTEM"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=116043#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=116043","url":"https:\/\/fivemor.com\/?p=116043","name":"How to Build Agentic QA RAG System Using Haystack Framework - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=116043#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=116043#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp","datePublished":"2025-02-28T22:39:33+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=116043#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=116043"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=116043#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/Building-Agentic-QA-RAG-Using-Haystack-Framework.webp.webp","width":872,"height":473},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=116043#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"How to Build Agentic QA RAG System Using Haystack Framework"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/116043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=116043"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/116043\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/116046"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=116043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=116043"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=116043"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=116043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}