{"id":41495,"date":"2025-10-01T06:48:28","date_gmt":"2025-10-01T06:48:28","guid":{"rendered":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/"},"modified":"2025-10-01T06:48:28","modified_gmt":"2025-10-01T06:48:28","slug":"how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval","status":"publish","type":"post","link":"https:\/\/youzum.net\/es\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/","title":{"rendered":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?"},"content":{"rendered":"<p>In this tutorial, we walk through the implementation of an Agentic Retrieval-Augmented Generation (RAG) system. We design it so that the agent does more than just retrieve documents; it actively decides when retrieval is needed, selects the best retrieval strategy, and synthesizes responses with contextual awareness. By combining embeddings, FAISS indexing, and a mock LLM, we create a practical demonstration of how agentic decision-making can elevate the standard RAG pipeline into something more adaptive and intelligent. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">import numpy as np\nimport faiss\nfrom sentence_transformers import SentenceTransformer\nimport json\nimport re\nfrom typing import List, Dict, Any, Optional\nfrom dataclasses import dataclass\nfrom enum import Enum\n\n\nclass MockLLM:\n   def generate(self, prompt: str, max_tokens: int = 150) -&gt; str:\n       prompt_lower = prompt.lower()\n      \n       if \"decide whether to retrieve\" in prompt_lower:\n           if any(word in prompt_lower for word in [\"specific\", \"recent\", \"data\", \"facts\", \"when\", \"who\", \"what\"]):\n               return \"RETRIEVE: The query requires specific factual information that needs to be retrieved.\"\n           else:\n               return \"NO_RETRIEVE: This is a general question that can be answered with existing knowledge.\"\n      \n       elif \"choose retrieval strategy\" in prompt_lower:\n           if \"comparison\" in prompt_lower or \"versus\" in prompt_lower:\n               return \"STRATEGY: multi_query - Need to retrieve information about multiple entities for comparison.\"\n           elif \"recent\" in prompt_lower or \"latest\" in prompt_lower:\n               return \"STRATEGY: temporal - Focus on recent information.\"\n           else:\n               return \"STRATEGY: semantic - Standard semantic similarity search.\"\n      \n       elif \"synthesize\" in prompt_lower and \"context:\" in prompt_lower:\n           return \"Based on the retrieved information, here's a comprehensive answer that combines multiple sources and provides specific details with proper context.\"\n      \n       return \"This is a mock response. In practice, use a real LLM like OpenAI's GPT or similar.\"\n\n\nclass RetrievalStrategy(Enum):\n   SEMANTIC = \"semantic\"\n   MULTI_QUERY = \"multi_query\"\n   TEMPORAL = \"temporal\"\n   HYBRID = \"hybrid\"\n\n\n@dataclass\nclass Document:\n   id: str\n   content: str\n   metadata: Dict[str, Any]\n   embedding: Optional[np.ndarray] = None<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We set up the foundation of our Agentic RAG system. We define a mock LLM to simulate decision-making, create a retrieval strategy enum, and design a Document dataclass so we can structure and manage our knowledge base efficiently. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">class AgenticRAGSystem:\n   def __init__(self, model_name: str = \"all-MiniLM-L6-v2\"):\n       self.encoder = SentenceTransformer(model_name)\n       self.llm = MockLLM()\n       self.documents: List[Document] = []\n       self.index: Optional[faiss.Index] = None\n      \n   def add_documents(self, documents: List[Dict[str, Any]]) -&gt; None:\n       print(f\"Processing {len(documents)} documents...\")\n      \n       for i, doc in enumerate(documents):\n           doc_obj = Document(\n               id=doc.get('id', str(i)),\n               content=doc['content'],\n               metadata=doc.get('metadata', {})\n           )\n           self.documents.append(doc_obj)\n      \n       contents = [doc.content for doc in self.documents]\n       embeddings = self.encoder.encode(contents, show_progress_bar=True)\n      \n       for doc, embedding in zip(self.documents, embeddings):\n           doc.embedding = embedding\n      \n       dimension = embeddings.shape[1]\n       self.index = faiss.IndexFlatIP(dimension)\n      \n       faiss.normalize_L2(embeddings)\n       self.index.add(embeddings.astype('float32'))\n      \n       print(f\"Knowledge base built with {len(self.documents)} documents\")<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We build the core of our Agentic RAG system. We initialize the embedding model, set up the FAISS index, and add documents by encoding their contents into vectors, enabling fast and accurate semantic retrieval from our knowledge base. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\"> def decide_retrieval(self, query: str) -&gt; bool:\n       decision_prompt = f\"\"\"\n       Analyze the following query and decide whether to retrieve information:\n       Query: \"{query}\"\n      \n       Decide whether to retrieve information from the knowledge base.\n       Consider if this needs specific facts, recent data, or can be answered generally.\n      \n       Respond with either:\n       RETRIEVE: [reason] or NO_RETRIEVE: [reason]\n       \"\"\"\n      \n       response = self.llm.generate(decision_prompt)\n       should_retrieve = response.startswith(\"RETRIEVE:\")\n      \n       print(f\"<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\" alt=\"\ud83e\udd16\" class=\"wp-smiley\" \/> Agent Decision: {'Retrieve' if should_retrieve else 'Direct Answer'}\")\n       print(f\"   Reasoning: {response.split(':', 1)[1].strip() if ':' in response else response}\")\n      \n       return should_retrieve\n  \n   def choose_strategy(self, query: str) -&gt; RetrievalStrategy:\n       strategy_prompt = f\"\"\"\n       Choose the best retrieval strategy for this query:\n       Query: \"{query}\"\n      \n       Available strategies:\n       - semantic: Standard similarity search\n       - multi_query: Multiple related queries (for comparisons)\n       - temporal: Focus on recent information\n       - hybrid: Combination approach\n      \n       Choose retrieval strategy and explain why.\n       Respond with: STRATEGY: [strategy_name] - [reasoning]\n       \"\"\"\n      \n       response = self.llm.generate(strategy_prompt)\n      \n       if \"multi_query\" in response.lower():\n           strategy = RetrievalStrategy.MULTI_QUERY\n       elif \"temporal\" in response.lower():\n           strategy = RetrievalStrategy.TEMPORAL\n       elif \"hybrid\" in response.lower():\n           strategy = RetrievalStrategy.HYBRID\n       else:\n           strategy = RetrievalStrategy.SEMANTIC\n      \n       print(f\"<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f3af.png\" alt=\"\ud83c\udfaf\" class=\"wp-smiley\" \/> Retrieval Strategy: {strategy.value}\")\n       print(f\"   Reasoning: {response.split('-', 1)[1].strip() if '-' in response else response}\")\n      \n       return strategy<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We give our agent the ability to think before it fetches. We first determine if a query truly requires retrieval, then we select the most suitable strategy: semantic, multi-query, temporal, or hybrid. This allows us to target the correct context with clear, printed reasoning for each step. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">  def retrieve_documents(self, query: str, strategy: RetrievalStrategy, k: int = 3) -&gt; List[Document]:\n       if not self.index:\n           print(\"<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/274c.png\" alt=\"\u274c\" class=\"wp-smiley\" \/> No knowledge base available\")\n           return []\n      \n       if strategy == RetrievalStrategy.MULTI_QUERY:\n           queries = [query, f\"advantages of {query}\", f\"disadvantages of {query}\"]\n           all_docs = []\n           for q in queries:\n               docs = self._semantic_search(q, k=2)\n               all_docs.extend(docs)\n           seen_ids = set()\n           unique_docs = []\n           for doc in all_docs:\n               if doc.id not in seen_ids:\n                   unique_docs.append(doc)\n                   seen_ids.add(doc.id)\n           return unique_docs[:k]\n      \n       elif strategy == RetrievalStrategy.TEMPORAL:\n           docs = self._semantic_search(query, k=k*2)\n           docs_with_dates = [(doc, doc.metadata.get('date', '1900-01-01')) for doc in docs]\n           docs_with_dates.sort(key=lambda x: x[1], reverse=True)\n           return [doc for doc, _ in docs_with_dates[:k]]\n      \n       else:\n           return self._semantic_search(query, k=k)\n  \n   def _semantic_search(self, query: str, k: int) -&gt; List[Document]:\n       query_embedding = self.encoder.encode([query])\n       faiss.normalize_L2(query_embedding)\n      \n       scores, indices = self.index.search(query_embedding.astype('float32'), k)\n      \n       results = []\n       for score, idx in zip(scores[0], indices[0]):\n           if idx &lt; len(self.documents):\n               results.append(self.documents[idx])\n      \n       return results\n  \n   def synthesize_response(self, query: str, retrieved_docs: List[Document]) -&gt; str:\n       if not retrieved_docs:\n           return self.llm.generate(f\"Answer this query: {query}\")\n      \n       context = \"nn\".join([f\"Document {i+1}: {doc.content}\"\n                             for i, doc in enumerate(retrieved_docs)])\n      \n       synthesis_prompt = f\"\"\"\n       Query: {query}\n      \n       Context: {context}\n      \n       Synthesize a comprehensive answer using the provided context.\n       Be specific and reference the information sources when relevant.\n       \"\"\"\n      \n       return self.llm.generate(synthesis_prompt, max_tokens=200)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We implement how we actually fetch and use knowledge. We perform semantic search, branch into multi-query or temporal re-ranking when needed, deduplicate results, and then synthesize a focused answer from the retrieved context. In doing so, we maintain efficient, transparent, and tightly aligned retrieval. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">   def query(self, query: str) -&gt; str:\n       print(f\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f50d.png\" alt=\"\ud83d\udd0d\" class=\"wp-smiley\" \/> Processing Query: '{query}'\")\n       print(\"=\" * 50)\n      \n       if not self.decide_retrieval(query):\n           print(\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f4dd.png\" alt=\"\ud83d\udcdd\" class=\"wp-smiley\" \/> Generating direct response...\")\n           return self.llm.generate(f\"Answer this query: {query}\")\n      \n       strategy = self.choose_strategy(query)\n      \n       print(f\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f4da.png\" alt=\"\ud83d\udcda\" class=\"wp-smiley\" \/> Retrieving documents using {strategy.value} strategy...\")\n       retrieved_docs = self.retrieve_documents(query, strategy)\n       print(f\"   Retrieved {len(retrieved_docs)} documents\")\n      \n       print(\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f9e0.png\" alt=\"\ud83e\udde0\" class=\"wp-smiley\" \/> Synthesizing response...\")\n       response = self.synthesize_response(query, retrieved_docs)\n      \n       if retrieved_docs:\n           print(\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f4c4.png\" alt=\"\ud83d\udcc4\" class=\"wp-smiley\" \/> Retrieved Context:\")\n           for i, doc in enumerate(retrieved_docs[:2], 1):\n               print(f\"   {i}. {doc.content[:100]}...\")\n      \n       return response<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We bring all the parts together into a single pipeline. When we run a query, we first determine if retrieval is necessary, then select the appropriate strategy, fetch documents accordingly, and finally synthesize a response while also displaying the retrieved context for transparency. This makes the system feel more agentic and explainable. Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\"no-line-numbers\"><code class=\"no-wrap language-php\">def create_sample_knowledge_base():\n   return [\n       {\n           \"id\": \"ai_1\",\n           \"content\": \"Artificial Intelligence (AI) refers to computer systems that can perform tasks requiring human intelligence\",\n           \"metadata\": {\"topic\": \"AI basics\", \"date\": \"2024-01-15\"}\n       },\n       {\n           \"id\": \"ml_1\",\n           \"content\": \"ML is a subset of AI.\",\n           \"metadata\": {\"topic\": \"Machine Learning\", \"date\": \"2024-02-10\"}\n       },\n       {\n           \"id\": \"rag_1\",\n           \"content\": \"Retrieval-Augmented Generation (RAG) combines the power of large language models with external knowledge retrieval to provide more accurate and up-to-date responses.\",\n           \"metadata\": {\"topic\": \"RAG\", \"date\": \"2024-03-05\"}\n       },\n       {\n           \"id\": \"agents_1\",\n           \"content\": \"AI agents\",\n           \"metadata\": {\"topic\": \"AI Agents\", \"date\": \"2024-03-20\"}\n       }\n   ]\n\n\nif __name__ == \"__main__\":\n   print(\"<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f680.png\" alt=\"\ud83d\ude80\" class=\"wp-smiley\" \/> Initializing Agentic RAG System...\")\n  \n   rag_system = AgenticRAGSystem()\n  \n   docs = create_sample_knowledge_base()\n   rag_system.add_documents(docs)\n  \n   demo_queries = [\n       \"What is artificial intelligence?\",\n       \"How are you today?\",\n       \"Compare AI and Machine Learning\",\n   ]\n  \n   for query in demo_queries:\n       response = rag_system.query(query)\n       print(f\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f4ac.png\" alt=\"\ud83d\udcac\" class=\"wp-smiley\" \/> Final Response: {response}\")\n       print(\"n\" + \"=\"*80)\n  \n   print(\"n<img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/2705.png\" alt=\"\u2705\" class=\"wp-smiley\" \/> Agentic RAG Tutorial Complete!\")\n   print(\"nKey Features Demonstrated:\")\n   print(\"\u2022 Agent-driven retrieval decisions\")\n   print(\"\u2022 Dynamic strategy selection\")\n   print(\"\u2022 Multi-modal retrieval approaches\")\n   print(\"\u2022 Transparent reasoning process\")<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We wrap everything into a runnable demo. We create a small knowledge base of AI-related documents, initialize the Agentic RAG system, and run sample queries that highlight various behaviors, including retrieval, direct answering, and comparison. This final block ties the whole tutorial together and showcases the agent\u2019s reasoning in action.<\/p>\n<p>In conclusion, we see how agent-driven retrieval decisions, dynamic strategy selection, and transparent reasoning come together to form an advanced Agentic RAG workflow. We now have a working system that highlights the potential of adding agency to RAG, making information retrieval smarter, more targeted, and more human-like in its adaptability. This foundation allows us to extend the system with real LLMs, larger knowledge bases, and more sophisticated strategies in future iterations.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<p>Check out the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/AI%20Agents%20Codes\/agentic_rag_tutorial_marktechpost.py\" target=\"_blank\" rel=\"noreferrer noopener\">FULL CODES here<\/a><\/strong>.\u00a0Feel free to check out our\u00a0<strong><mark><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub Page for Tutorials, Codes and Notebooks<\/a><\/mark><\/strong>.\u00a0Also,\u00a0feel free to follow us on\u00a0<strong><a href=\"https:\/\/x.com\/intent\/follow?screen_name=marktechpost\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Twitter<\/mark><\/a><\/strong>\u00a0and don\u2019t forget to join our\u00a0<strong><a href=\"https:\/\/www.reddit.com\/r\/machinelearningnews\/\" target=\"_blank\" rel=\"noreferrer noopener\">100k+ ML SubReddit<\/a><\/strong>\u00a0and Subscribe to\u00a0<strong><a href=\"https:\/\/www.aidevsignals.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">our Newsletter<\/a><\/strong>.<\/p>\n<p><!-- CONTENT END 2 --><\/p>\n<p>The post <a href=\"https:\/\/www.marktechpost.com\/2025\/09\/30\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\">How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?<\/a> appeared first on <a href=\"https:\/\/www.marktechpost.com\/\">MarkTechPost<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we walk through the implementation of an Agentic Retrieval-Augmented Generation (RAG) system. We design it so that the agent does more than just retrieve documents; it actively decides when retrieval is needed, selects the best retrieval strategy, and synthesizes responses with contextual awareness. By combining embeddings, FAISS indexing, and a mock LLM, we create a practical demonstration of how agentic decision-making can elevate the standard RAG pipeline into something more adaptive and intelligent. Check out the\u00a0FULL CODES here. Copy CodeCopiedUse a different Browser import numpy as np import faiss from sentence_transformers import SentenceTransformer import json import re from typing import List, Dict, Any, Optional from dataclasses import dataclass from enum import Enum class MockLLM: def generate(self, prompt: str, max_tokens: int = 150) -&gt; str: prompt_lower = prompt.lower() if &#8220;decide whether to retrieve&#8221; in prompt_lower: if any(word in prompt_lower for word in [&#8220;specific&#8221;, &#8220;recent&#8221;, &#8220;data&#8221;, &#8220;facts&#8221;, &#8220;when&#8221;, &#8220;who&#8221;, &#8220;what&#8221;]): return &#8220;RETRIEVE: The query requires specific factual information that needs to be retrieved.&#8221; else: return &#8220;NO_RETRIEVE: This is a general question that can be answered with existing knowledge.&#8221; elif &#8220;choose retrieval strategy&#8221; in prompt_lower: if &#8220;comparison&#8221; in prompt_lower or &#8220;versus&#8221; in prompt_lower: return &#8220;STRATEGY: multi_query &#8211; Need to retrieve information about multiple entities for comparison.&#8221; elif &#8220;recent&#8221; in prompt_lower or &#8220;latest&#8221; in prompt_lower: return &#8220;STRATEGY: temporal &#8211; Focus on recent information.&#8221; else: return &#8220;STRATEGY: semantic &#8211; Standard semantic similarity search.&#8221; elif &#8220;synthesize&#8221; in prompt_lower and &#8220;context:&#8221; in prompt_lower: return &#8220;Based on the retrieved information, here&#8217;s a comprehensive answer that combines multiple sources and provides specific details with proper context.&#8221; return &#8220;This is a mock response. In practice, use a real LLM like OpenAI&#8217;s GPT or similar.&#8221; class RetrievalStrategy(Enum): SEMANTIC = &#8220;semantic&#8221; MULTI_QUERY = &#8220;multi_query&#8221; TEMPORAL = &#8220;temporal&#8221; HYBRID = &#8220;hybrid&#8221; @dataclass class Document: id: str content: str metadata: Dict[str, Any] embedding: Optional[np.ndarray] = None We set up the foundation of our Agentic RAG system. We define a mock LLM to simulate decision-making, create a retrieval strategy enum, and design a Document dataclass so we can structure and manage our knowledge base efficiently. Check out the\u00a0FULL CODES here. Copy CodeCopiedUse a different Browser class AgenticRAGSystem: def __init__(self, model_name: str = &#8220;all-MiniLM-L6-v2&#8243;): self.encoder = SentenceTransformer(model_name) self.llm = MockLLM() self.documents: List[Document] = [] self.index: Optional[faiss.Index] = None def add_documents(self, documents: List[Dict[str, Any]]) -&gt; None: print(f&#8221;Processing {len(documents)} documents&#8230;&#8221;) for i, doc in enumerate(documents): doc_obj = Document( id=doc.get(&#8216;id&#8217;, str(i)), content=doc[&#8216;content&#8217;], metadata=doc.get(&#8216;metadata&#8217;, {}) ) self.documents.append(doc_obj) contents = [doc.content for doc in self.documents] embeddings = self.encoder.encode(contents, show_progress_bar=True) for doc, embedding in zip(self.documents, embeddings): doc.embedding = embedding dimension = embeddings.shape[1] self.index = faiss.IndexFlatIP(dimension) faiss.normalize_L2(embeddings) self.index.add(embeddings.astype(&#8216;float32&#8217;)) print(f&#8221;Knowledge base built with {len(self.documents)} documents&#8221;) We build the core of our Agentic RAG system. We initialize the embedding model, set up the FAISS index, and add documents by encoding their contents into vectors, enabling fast and accurate semantic retrieval from our knowledge base. Check out the\u00a0FULL CODES here. Copy CodeCopiedUse a different Browser def decide_retrieval(self, query: str) -&gt; bool: decision_prompt = f&#8221;&#8221;&#8221; Analyze the following query and decide whether to retrieve information: Query: &#8220;{query}&#8221; Decide whether to retrieve information from the knowledge base. Consider if this needs specific facts, recent data, or can be answered generally. Respond with either: RETRIEVE: [reason] or NO_RETRIEVE: [reason] &#8220;&#8221;&#8221; response = self.llm.generate(decision_prompt) should_retrieve = response.startswith(&#8220;RETRIEVE:&#8221;) print(f&#8221; Agent Decision: {&#8216;Retrieve&#8217; if should_retrieve else &#8216;Direct Answer&#8217;}&#8221;) print(f&#8221; Reasoning: {response.split(&#8216;:&#8217;, 1)[1].strip() if &#8216;:&#8217; in response else response}&#8221;) return should_retrieve def choose_strategy(self, query: str) -&gt; RetrievalStrategy: strategy_prompt = f&#8221;&#8221;&#8221; Choose the best retrieval strategy for this query: Query: &#8220;{query}&#8221; Available strategies: &#8211; semantic: Standard similarity search &#8211; multi_query: Multiple related queries (for comparisons) &#8211; temporal: Focus on recent information &#8211; hybrid: Combination approach Choose retrieval strategy and explain why. Respond with: STRATEGY: [strategy_name] &#8211; [reasoning] &#8220;&#8221;&#8221; response = self.llm.generate(strategy_prompt) if &#8220;multi_query&#8221; in response.lower(): strategy = RetrievalStrategy.MULTI_QUERY elif &#8220;temporal&#8221; in response.lower(): strategy = RetrievalStrategy.TEMPORAL elif &#8220;hybrid&#8221; in response.lower(): strategy = RetrievalStrategy.HYBRID else: strategy = RetrievalStrategy.SEMANTIC print(f&#8221; Retrieval Strategy: {strategy.value}&#8221;) print(f&#8221; Reasoning: {response.split(&#8216;-&#8216;, 1)[1].strip() if &#8216;-&#8216; in response else response}&#8221;) return strategy We give our agent the ability to think before it fetches. We first determine if a query truly requires retrieval, then we select the most suitable strategy: semantic, multi-query, temporal, or hybrid. This allows us to target the correct context with clear, printed reasoning for each step. Check out the\u00a0FULL CODES here. Copy CodeCopiedUse a different Browser def retrieve_documents(self, query: str, strategy: RetrievalStrategy, k: int = 3) -&gt; List[Document]: if not self.index: print(&#8221; No knowledge base available&#8221;) return [] if strategy == RetrievalStrategy.MULTI_QUERY: queries = [query, f&#8221;advantages of {query}&#8221;, f&#8221;disadvantages of {query}&#8221;] all_docs = [] for q in queries: docs = self._semantic_search(q, k=2) all_docs.extend(docs) seen_ids = set() unique_docs = [] for doc in all_docs: if doc.id not in seen_ids: unique_docs.append(doc) seen_ids.add(doc.id) return unique_docs[:k] elif strategy == RetrievalStrategy.TEMPORAL: docs = self._semantic_search(query, k=k*2) docs_with_dates = [(doc, doc.metadata.get(&#8216;date&#8217;, &#8216;1900-01-01&#8217;)) for doc in docs] docs_with_dates.sort(key=lambda x: x[1], reverse=True) return [doc for doc, _ in docs_with_dates[:k]] else: return self._semantic_search(query, k=k) def _semantic_search(self, query: str, k: int) -&gt; List[Document]: query_embedding = self.encoder.encode([query]) faiss.normalize_L2(query_embedding) scores, indices = self.index.search(query_embedding.astype(&#8216;float32&#8217;), k) results = [] for score, idx in zip(scores[0], indices[0]): if idx &lt; len(self.documents): results.append(self.documents[idx]) return results def synthesize_response(self, query: str, retrieved_docs: List[Document]) -&gt; str: if not retrieved_docs: return self.llm.generate(f&#8221;Answer this query: {query}&#8221;) context = &#8220;nn&#8221;.join([f&#8221;Document {i+1}: {doc.content}&#8221; for i, doc in enumerate(retrieved_docs)]) synthesis_prompt = f&#8221;&#8221;&#8221; Query: {query} Context: {context} Synthesize a comprehensive answer using the provided context. Be specific and reference the information sources when relevant. &#8220;&#8221;&#8221; return self.llm.generate(synthesis_prompt, max_tokens=200) We implement how we actually fetch and use knowledge. We perform semantic search, branch into multi-query or temporal re-ranking when needed, deduplicate results, and then synthesize a focused answer from the retrieved context. In doing so, we maintain efficient, transparent, and tightly aligned retrieval. Check out the\u00a0FULL CODES here. Copy CodeCopiedUse a different Browser def query(self, query: str) -&gt; str: print(f&#8221;n Processing Query: &#8216;{query}'&#8221;) print(&#8220;=&#8221; * 50) if not self.decide_retrieval(query): print(&#8220;n Generating direct response&#8230;&#8221;) return self.llm.generate(f&#8221;Answer this query: {query}&#8221;) strategy = self.choose_strategy(query) print(f&#8221;n Retrieving documents using {strategy.value} strategy&#8230;&#8221;) retrieved_docs = self.retrieve_documents(query, strategy) print(f&#8221; Retrieved {len(retrieved_docs)} documents&#8221;)<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pmpro_default_level":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_pvb_checkbox_block_on_post":false,"footnotes":""},"categories":[52,5,7,1],"tags":[],"class_list":["post-41495","post","type-post","status-publish","format-standard","hentry","category-ai-club","category-committee","category-news","category-uncategorized","pmpro-has-access"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum<\/title>\n<meta name=\"description\" content=\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/youzum.net\/es\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum\" \/>\n<meta property=\"og:description\" content=\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\" \/>\n<meta property=\"og:url\" content=\"https:\/\/youzum.net\/es\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\" \/>\n<meta property=\"og:site_name\" content=\"YouZum\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DroneAssociationTH\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-01T06:48:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\" \/>\n<meta name=\"author\" content=\"admin NU\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin NU\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\"},\"author\":{\"name\":\"admin NU\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c\"},\"headline\":\"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?\",\"datePublished\":\"2025-10-01T06:48:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\"},\"wordCount\":575,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\"},\"image\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\",\"articleSection\":[\"AI\",\"Committee\",\"News\",\"Uncategorized\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\",\"url\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\",\"name\":\"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum\",\"isPartOf\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\",\"datePublished\":\"2025-10-01T06:48:28+00:00\",\"description\":\"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19\",\"breadcrumb\":{\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage\",\"url\":\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\",\"contentUrl\":\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/youzum.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/yousum.gpucore.co\/#website\",\"url\":\"https:\/\/yousum.gpucore.co\/\",\"name\":\"YouSum\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/yousum.gpucore.co\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/yousum.gpucore.co\/#organization\",\"name\":\"Drone Association Thailand\",\"url\":\"https:\/\/yousum.gpucore.co\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png\",\"contentUrl\":\"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png\",\"width\":300,\"height\":300,\"caption\":\"Drone Association Thailand\"},\"image\":{\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/DroneAssociationTH\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c\",\"name\":\"admin NU\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/yousum.gpucore.co\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png\",\"contentUrl\":\"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png\",\"caption\":\"admin NU\"},\"url\":\"https:\/\/youzum.net\/es\/members\/adminnu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum","description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","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:\/\/youzum.net\/es\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/","og_locale":"es_ES","og_type":"article","og_title":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum","og_description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","og_url":"https:\/\/youzum.net\/es\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/","og_site_name":"YouZum","article_publisher":"https:\/\/www.facebook.com\/DroneAssociationTH\/","article_published_time":"2025-10-01T06:48:28+00:00","og_image":[{"url":"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png","type":"","width":"","height":""}],"author":"admin NU","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"admin NU","Tiempo de lectura":"8 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#article","isPartOf":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/"},"author":{"name":"admin NU","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c"},"headline":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?","datePublished":"2025-10-01T06:48:28+00:00","mainEntityOfPage":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/"},"wordCount":575,"commentCount":0,"publisher":{"@id":"https:\/\/yousum.gpucore.co\/#organization"},"image":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage"},"thumbnailUrl":"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png","articleSection":["AI","Committee","News","Uncategorized"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/","url":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/","name":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval? - YouZum","isPartOf":{"@id":"https:\/\/yousum.gpucore.co\/#website"},"primaryImageOfPage":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage"},"image":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage"},"thumbnailUrl":"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png","datePublished":"2025-10-01T06:48:28+00:00","description":"\u0e01\u0e34\u0e08\u0e01\u0e23\u0e23\u0e21\u0e40\u0e01\u0e35\u0e48\u0e22\u0e27\u0e01\u0e31\u0e1a\u0e42\u0e14\u0e23\u0e19","breadcrumb":{"@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#primaryimage","url":"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png","contentUrl":"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/72x72\/1f916.png"},{"@type":"BreadcrumbList","@id":"https:\/\/youzum.net\/how-to-build-an-advanced-agentic-retrieval-augmented-generation-rag-system-with-dynamic-strategy-and-smart-retrieval\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/youzum.net\/"},{"@type":"ListItem","position":2,"name":"How to Build an Advanced Agentic Retrieval-Augmented Generation (RAG) System with Dynamic Strategy and Smart Retrieval?"}]},{"@type":"WebSite","@id":"https:\/\/yousum.gpucore.co\/#website","url":"https:\/\/yousum.gpucore.co\/","name":"YouSum","description":"","publisher":{"@id":"https:\/\/yousum.gpucore.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/yousum.gpucore.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/yousum.gpucore.co\/#organization","name":"Drone Association Thailand","url":"https:\/\/yousum.gpucore.co\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/","url":"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png","contentUrl":"https:\/\/youzum.net\/wp-content\/uploads\/2024\/11\/tranparent-logo.png","width":300,"height":300,"caption":"Drone Association Thailand"},"image":{"@id":"https:\/\/yousum.gpucore.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DroneAssociationTH\/"]},{"@type":"Person","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/97fa48242daf3908e4d9a5f26f4a059c","name":"admin NU","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/yousum.gpucore.co\/#\/schema\/person\/image\/","url":"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png","contentUrl":"https:\/\/youzum.net\/wp-content\/uploads\/avatars\/2\/1746849356-bpfull.png","caption":"admin NU"},"url":"https:\/\/youzum.net\/es\/members\/adminnu\/"}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"admin NU","author_link":"https:\/\/youzum.net\/es\/members\/adminnu\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/youzum.net\/es\/category\/ai-club\/\" rel=\"category tag\">AI<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/committee\/\" rel=\"category tag\">Committee<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/news\/\" rel=\"category tag\">News<\/a> <a href=\"https:\/\/youzum.net\/es\/category\/uncategorized\/\" rel=\"category tag\">Uncategorized<\/a>","rttpg_excerpt":"In this tutorial, we walk through the implementation of an Agentic Retrieval-Augmented Generation (RAG) system. We design it so that the agent does more than just retrieve documents; it actively decides when retrieval is needed, selects the best retrieval strategy, and synthesizes responses with contextual awareness. By combining embeddings, FAISS indexing, and a mock LLM,&hellip;","_links":{"self":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts\/41495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/comments?post=41495"}],"version-history":[{"count":0,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/posts\/41495\/revisions"}],"wp:attachment":[{"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/media?parent=41495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/categories?post=41495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/youzum.net\/es\/wp-json\/wp\/v2\/tags?post=41495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}