<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ajay Bazil Issac</title>
    <description>The latest articles on DEV Community by Ajay Bazil Issac (@ajay_bazilissac_a8063c5b).</description>
    <link>https://dev.to/ajay_bazilissac_a8063c5b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4098607%2F0858fe34-2d0e-4873-963c-0ef75f5a6fb1.jpg</url>
      <title>DEV Community: Ajay Bazil Issac</title>
      <link>https://dev.to/ajay_bazilissac_a8063c5b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajay_bazilissac_a8063c5b"/>
    <language>en</language>
    <item>
      <title>Design, Optimization, and Deployment of a Hybrid Agentic Retrieval-Augmented Generation (Agentic-RAG) Architecture</title>
      <dc:creator>Ajay Bazil Issac</dc:creator>
      <pubDate>Sat, 29 Aug 2026 08:11:15 +0000</pubDate>
      <link>https://dev.to/ajay_bazilissac_a8063c5b/design-optimization-and-deployment-of-a-hybrid-agentic-retrieval-augmented-generation-32e8</link>
      <guid>https://dev.to/ajay_bazilissac_a8063c5b/design-optimization-and-deployment-of-a-hybrid-agentic-retrieval-augmented-generation-32e8</guid>
      <description>&lt;h1&gt;
  
  
  Abstract
&lt;/h1&gt;

&lt;p&gt;Traditional RAG pipelines usually work deterministically by using only static vector search[cite: 1]. Because of this, vocabulary mismatches can occur when searching for exact words or technical keywords, and the agent may be unable to verify context[cite: 1]. &lt;/p&gt;

&lt;p&gt;In this research document, I explain the complete details of the Agentic Hybrid RAG architecture I engineered[cite: 1]. It combines dense semantic search (FAISS IndexFlatIP with L2-normalized embeddings) and exact keyword search (BM25Okapi), and operates through an autonomous LLM agent using the &lt;code&gt;smolagents&lt;/code&gt; framework[cite: 1]. It also describes in detail how I overcame issues encountered when running the model locally on CPU, such as Python sandbox import errors, extreme CPU time latency (&amp;gt;213 seconds per step), and model hallucinations, by using a cloud model (Qwen2.5-72B-Instruct) and dynamic score normalization ($\alpha=0.7$), along with the benchmark results[cite: 1].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keywords:&lt;/strong&gt; Agentic AI, Retrieval-Augmented Generation (RAG), Hybrid Search, FAISS, BM25, Smolagents, Knowledge Grounding, Score Normalization[cite: 1].&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Introduction &amp;amp; Aim
&lt;/h1&gt;

&lt;p&gt;Across enterprise decision-support systems, the deployment of large language models (LLMs) has exposed significant architectural weaknesses: static parametric knowledge cutoffs, hallucinated facts, and an inability to access proprietary ground-truth records[cite: 1]. While standard retrieval-augmented generation (RAG) addresses these weaknesses by providing external context before generation, canonical RAG pipelines continue to operate in a rigid, deterministic manner[cite: 1].&lt;/p&gt;

&lt;p&gt;In standard RAG, every query leads to a vector lookup that is not much different[cite: 1]. As a result, pipelines fail when queries involve exact alphanumeric codes or rare technical terms (vocabulary mismatch problem), or when multiple stages of logical analysis are needed before retrieval[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  1.1 Research Aim and Objectives
&lt;/h2&gt;

&lt;p&gt;This study aims to design, build, and evaluate an autonomous "agentic hybrid RAG" system that functions as a rational, reasoning-capable system[cite: 1]. Its main objectives are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Dual-engine hybrid retrieval:&lt;/strong&gt; Build an integrated scoring pipeline that combines sparse lexical matching with dense semantic vector similarity[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Autonomous tool orchestration:&lt;/strong&gt; Create an autonomous agent with Python code execution capabilities that dynamically decides when to retrieve, what query formulations to use, and how to inspect retrieved artifacts[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practical problem solving:&lt;/strong&gt; Identify and overcome critical deployment constraints, including sandbox containment security flaws, local CPU compute latency bottlenecks, and tool-calling hallucinations in smaller models[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interdisciplinary scaling roadmap:&lt;/strong&gt; Provide an architectural blueprint for scaling into knowledge graphs (graphRAG), multi-agent consensus, and automated valuation frameworks[cite: 1].&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  2. System Architecture &amp;amp; Methodology
&lt;/h1&gt;

&lt;p&gt;This system includes three mutually complementary components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Knowledge base ingestion and chunking[cite: 1]&lt;/li&gt;
&lt;li&gt;Dual-engine indexing[cite: 1]&lt;/li&gt;
&lt;li&gt;The agentic orchestration loop[cite: 1]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Architectural Workflow Summary:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;User Query&lt;/code&gt; --&amp;gt; &lt;code&gt;Agent Reasoning&lt;/code&gt; --&amp;gt; &lt;code&gt;Code Tool Call: knowledge_base_search(query)&lt;/code&gt; --&amp;gt; &lt;code&gt;Dual Index: FAISS Vector (cos θ) + BM25 Lexical&lt;/code&gt; --&amp;gt; &lt;code&gt;Min-Max Score Normalization&lt;/code&gt; --&amp;gt; &lt;code&gt;Weighted Fusion (α=0.7)&lt;/code&gt; --&amp;gt; &lt;code&gt;Top-K Passages&lt;/code&gt; --&amp;gt; &lt;code&gt;Grounded Answer Synthesis&lt;/code&gt;[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  2.1 Context-Preserving Chunking
&lt;/h2&gt;

&lt;p&gt;We divide the source documents D={d_1, d_2, \dots, d_N} using recursive character boundary splitting[cite: 1]. To maintain semantic continuity, we use a windowing function:&lt;/p&gt;

&lt;p&gt;Equation (1):    C = Chunk(di, W_size = 300, W_overlap = 50)&lt;/p&gt;

&lt;p&gt;Here, a chunk size of 300 characters and an overlap of 50 characters are used; this overlap prevents semantic discontinuity between chunk boundaries and ensures completeness of information[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  2.2 Dense Vector Search via FAISS IndexFlatIP
&lt;/h2&gt;

&lt;p&gt;Each part (chunk) c_j in C is embedded into a dense vector e_j in mathbb{R}^{384} using &lt;code&gt;all-MiniLM-L6-v2&lt;/code&gt;, and then L2-normalized efficiently[cite: 1]:&lt;/p&gt;

&lt;p&gt;Equation (2):    ê_j = e_j / ||e_j||_2,  such that ||ê_j||_2 = 1.0&lt;/p&gt;

&lt;p&gt;The vectors are indexed using &lt;code&gt;faiss.IndexFlatIP&lt;/code&gt;[cite: 1]. For a normalized query vector q, the inner product exactly computes the directional cosine similarity[cite: 1]:&lt;/p&gt;

&lt;p&gt;Equation (3):    Sim(q̂, ê_j) = q̂ · ê_j = Σ q̂_k · ê_j,k = cos(θ)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;IndexFlatIP&lt;/code&gt;, by avoiding lossy quantization or clustering-based approximate calculations, guarantees 100% accuracy in vector space[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  2.3 Sparse Lexical Search via Okapi BM25
&lt;/h2&gt;

&lt;p&gt;Concurrently, chunks are tokenized after stop-word sanitation[cite: 1]. The lexical relevance score of query tokens Q={t1,..., tm} against chunk c_j is computed via the probabilistic BM25 model, with saturation parameter k_1=1.5 and length normalization b=0.75[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  2.4 Min-Max Normalization &amp;amp; Hybrid Fusion
&lt;/h2&gt;

&lt;p&gt;Since the distributions of dense vector inner products and BM25 scores do not match, directly combining them causes a large imbalance or skew[cite: 1]. Therefore, we apply feature-level min-max scaling[cite: 1]:&lt;/p&gt;

&lt;p&gt;Equation (5):    Ŝ(x) = [S(x) - min(S)] / [max(S) - min(S) + ε]&lt;/p&gt;

&lt;p&gt;The final unified hybrid ranking score is computed as[cite: 1]:&lt;/p&gt;

&lt;p&gt;Equation (6):    S_hybrid(c_j) = α · Ŝ_vector(c_j) + (1 - α) · Ŝ_keyword(c_j)&lt;/p&gt;

&lt;p&gt;where α = 0.7 prioritizes semantic context while allocating 30% weight to exact keyword preservation[cite: 1].&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Challenges &amp;amp; Engineering Solutions
&lt;/h1&gt;

&lt;p&gt;The shift from an interactive notebook to a practical standalone system in VS Code has revealed four critical failure points[cite: 1]:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Challenge / Failure Mode&lt;/th&gt;
&lt;th&gt;Observed Root Cause&lt;/th&gt;
&lt;th&gt;Engineering Countermeasure&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;1. Sandbox Import Violation&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;Small LLM (1.5B) hallucinated external APIs (&lt;code&gt;requests&lt;/code&gt;, &lt;code&gt;wolframalpha&lt;/code&gt;)[cite: 1].&lt;/td&gt;
&lt;td&gt;Enforced explicit tool prompting; transitioned backbone to &lt;strong&gt;Qwen2.5-72B-Instruct&lt;/strong&gt;[cite: 1].&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;2. CPU Compute Latency&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;Local inference exceeded 213 seconds per reasoning step on consumer CPU[cite: 1].&lt;/td&gt;
&lt;td&gt;Offloaded LLM reasoning to Hugging Face hosted GPU endpoints (&lt;code&gt;InferenceClientModel&lt;/code&gt;)[cite: 1].&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;3. API Interface Drift&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;smolagents&lt;/code&gt; renamed &lt;code&gt;HfApiModel&lt;/code&gt; to &lt;code&gt;InferenceClientModel&lt;/code&gt; across package updates[cite: 1].&lt;/td&gt;
&lt;td&gt;Implemented multi-version dynamic try-except fallback import wrapper[cite: 1].&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;4. Vocabulary Mismatch&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;BM25 failed on conceptual synonyms; pure vector missed exact alphanumeric IDs[cite: 1].&lt;/td&gt;
&lt;td&gt;Engineered dual-engine weighted hybrid fusion ($\alpha=0.7$) and Min-Max scaling[cite: 1].&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  3.1 Deep Dive: Resolving Sandbox Violations &amp;amp; Hallucinations
&lt;/h2&gt;

&lt;p&gt;When running a 1.5B model locally, the agent made uncontrolled network calls (for example: &lt;code&gt;import requests; request.get('http://api.wolframalpha.com/...')&lt;/code&gt;)[cite: 1]. Since the &lt;code&gt;CodeAgent&lt;/code&gt; is running in a secure sandbox that allows only standard math libraries (&lt;code&gt;math&lt;/code&gt;, &lt;code&gt;re&lt;/code&gt;, &lt;code&gt;collections&lt;/code&gt;), an &lt;code&gt;Interpreter Error&lt;/code&gt; occurred and execution stopped[cite: 1].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; The agent's reasoning backbone was upgraded to &lt;code&gt;Qwen2.5-72B-Instruct&lt;/code&gt;, and that resolved this issue[cite: 1]. This large model, which follows instructions accurately, strictly adhered to the given system contract and made precise calls to &lt;code&gt;knowledge_base_search(query=...)&lt;/code&gt; without unnecessary assumptions or hallucinations about external dependencies[cite: 1].&lt;/p&gt;

&lt;h2&gt;
  
  
  3.2 Deep Dive: Eliminating Compute Bottlenecks
&lt;/h2&gt;

&lt;p&gt;When running the first stage of the iterative generation on local CPU hardware, an unacceptable time of 213.85 seconds was required[cite: 1]. By shifting model inference to high-capacity cloud endpoints, the latency at each stage dropped from over 210 seconds to under 2.4 seconds; this indicates an approximately &lt;strong&gt;89-fold increase in speed&lt;/strong&gt;[cite: 1].&lt;/p&gt;




&lt;h1&gt;
  
  
  4. Experimental Results &amp;amp; Findings
&lt;/h1&gt;

&lt;p&gt;To measure retrieval precision and the ability to control hallucination, the hybrid agentic pipeline was evaluated across three different search categories[cite: 1]:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Retrieval Paradigm&lt;/th&gt;
&lt;th&gt;Semantic Recall&lt;/th&gt;
&lt;th&gt;Exact Identifier&lt;/th&gt;
&lt;th&gt;Composite MRR@3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Pure Vector (IndexFlatIP)&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;0.94[cite: 1]&lt;/td&gt;
&lt;td&gt;0.62[cite: 1]&lt;/td&gt;
&lt;td&gt;0.81[cite: 1]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Pure Keyword (BM25Okapi)&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;0.48[cite: 1]&lt;/td&gt;
&lt;td&gt;0.96[cite: 1]&lt;/td&gt;
&lt;td&gt;0.74[cite: 1]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Hybrid Fusion ($\alpha=0.7$)&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0.95&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0.93&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0.96&lt;/strong&gt;[cite: 1]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  4.1 Groundedness and Answer Synthesis
&lt;/h2&gt;

&lt;p&gt;In benchmark tests, the agent achieved &lt;strong&gt;100% grounding verification&lt;/strong&gt; on specific target queries[cite: 1]. When answering the question, &lt;em&gt;"What is RAG, and why are embeddings important in a RAG system?"&lt;/em&gt;, the agent used a hybrid search tool and analyzed information from the &lt;code&gt;RAG001&lt;/code&gt; and &lt;code&gt;EMB001&lt;/code&gt; chunks, producing a comprehensive response that clearly explained vector conversion, semantic indexing, and grounded context synthesis without factual errors[cite: 1].&lt;/p&gt;




&lt;h1&gt;
  
  
  5. System Expansion &amp;amp; Future Roadmap
&lt;/h1&gt;

&lt;p&gt;To scale this architecture into enterprise production, we are implementing four key enhancements[cite: 1]:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Knowledge graph fusion (graphRAG):&lt;/strong&gt; Integrate structured graph databases (e.g., Neo4j) to store entity-relation-entity triples, enabling the agent to perform multi-hop graph searches alongside vector retrieval, bridging global contextual queries[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-agent debate and verification:&lt;/strong&gt; Decompose a single agent into a multi-agent hierarchy (planner agent, retriever agent, verifier/critic agent) to perform automated citation validation and assign blame for unsupported claims[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production vector DB clustering:&lt;/strong&gt; Migrate to distributed vector stores (Qdrant, Milvus, Pinecone) using HNSW indexing for billion-scale vector collections[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous triad metric evaluation:&lt;/strong&gt; Automate the use of evaluation frameworks such as Ragas and TruLens to continuously monitor metrics like groundedness, answer relevance, and latency[cite: 1].&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  6. Conclusion
&lt;/h1&gt;

&lt;p&gt;This research demonstrated the full reality of an agentic hybrid RAG architecture[cite: 1]. By combining FAISS dense vector retrieval, BM25 sparse lexical indexing, and an autonomous code-executing LLM agent, the system overcomes the limitations of static RAG pipelines[cite: 1]. We addressed core engineering challenges related to sandbox execution safety, inference latency, and library version compatibility[cite: 1]. &lt;/p&gt;

&lt;p&gt;The empirical results confirm that integrating hybrid retrieval with autonomous agent decision-making delivers better grounding, stronger keyword precision, and highly fast, factual synthesis, establishing a modular framework for modern enterprise AI architectures[cite: 1].&lt;/p&gt;




&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[1]&lt;/strong&gt; P. Lewis et al., "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks," in &lt;em&gt;Advances in Neural Information Processing Systems (NeurIPS)&lt;/em&gt;, vol. 33, pp. 9459-9474, 2020[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[2]&lt;/strong&gt; J. Johnson, M. Douze, and H. Jégou, "Billion-Scale Similarity Search with GPUs," &lt;em&gt;IEEE Transactions on Big Data&lt;/em&gt;, vol. 7, no. 3, pp. 535-547, 2019[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[3]&lt;/strong&gt; S. Robertson and H. Zaragoza, "The Probabilistic Relevance Framework: BM25 and Beyond," &lt;em&gt;Foundations and Trends in Information Retrieval&lt;/em&gt;, vol. 3, no. 4, pp. 333-389, 2009[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[4]&lt;/strong&gt; N. Reimers and I. Gurevych, "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks," in &lt;em&gt;Proc. of EMNLP-IJCNLP&lt;/em&gt;, pp. 3982-3992, 2019[cite: 1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[5]&lt;/strong&gt; Hugging Face, "Smolagents: A Minimalist Framework for Building Code Agents," GitHub Repository, 2024. [Online]. Available: &lt;a href="https://github.com/huggingface/smolagents%5Bcite:" rel="noopener noreferrer"&gt;https://github.com/huggingface/smolagents[cite:&lt;/a&gt; 1]&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[6]&lt;/strong&gt; S. Es, J. James, L. Espinosa-Anke, and S. Schockaert, "Ragas: Automated Evaluation of Retrieval Augmented Generation," in &lt;em&gt;Proc. of EACL&lt;/em&gt;, 2024[cite: 1].&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
