<?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: Sanjay Sajukumar</title>
    <description>The latest articles on DEV Community by Sanjay Sajukumar (@sanjay_sajukumar_04).</description>
    <link>https://dev.to/sanjay_sajukumar_04</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%2F4098790%2F7ded1c53-517a-4a5d-a110-5421765d0095.png</url>
      <title>DEV Community: Sanjay Sajukumar</title>
      <link>https://dev.to/sanjay_sajukumar_04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanjay_sajukumar_04"/>
    <language>en</language>
    <item>
      <title>Building a Closed-Domain Agentic AI Knowledge Assistant with Hybrid RAG</title>
      <dc:creator>Sanjay Sajukumar</dc:creator>
      <pubDate>Sun, 30 Aug 2026 04:56:47 +0000</pubDate>
      <link>https://dev.to/sanjay_sajukumar_04/building-a-closed-domain-agentic-ai-knowledge-assistant-with-hybrid-rag-2416</link>
      <guid>https://dev.to/sanjay_sajukumar_04/building-a-closed-domain-agentic-ai-knowledge-assistant-with-hybrid-rag-2416</guid>
      <description>&lt;p&gt;I recently built an &lt;strong&gt;"Agentic AI Knowledge Assistant"&lt;/strong&gt; that combines "Retrieval-Augmented Generation (RAG), hybrid search, and an LLM agent" to answer questions strictly from a predefined knowledge base.&lt;/p&gt;

&lt;p&gt;One of the main goals of this project was to address a common problem with LLM applications: &lt;strong&gt;the model should not answer questions using its general pretrained knowledge when the required information is not available in the knowledge base.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The system follows a retrieval-first approach:&lt;br&gt;
User Question → Hybrid Retrieval → Relevant Context → AI Agent → Final Answer:&lt;br&gt;
The knowledge base is divided into smaller chunks using "LangChain's RecursiveCharacterTextSplitter". Each chunk is converted into embeddings using:&lt;br&gt;
"sentence-transformers/all-MiniLM-L6-v2"&lt;br&gt;
For retrieval, I implemented two approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FAISS for semantic vector search&lt;/li&gt;
&lt;li&gt;BM25 for keyword-based search
These are combined using a weighted hybrid scoring mechanism:
"Hybrid Score = 0.7 × Vector Score + 0.3 × BM25 Score"
This allows the system to benefit from both semantic similarity and exact keyword matching.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The workflow looks like this:&lt;br&gt;
User Query&lt;br&gt;
    ↓&lt;br&gt;
Hybrid Search&lt;br&gt;
   ↓&lt;br&gt;&lt;br&gt;
FAISS    ||  BM25&lt;br&gt;
Vector   ||  Keyword&lt;br&gt;
Search   ||  Search&lt;br&gt;
          ↓&lt;br&gt;
Relevant Knowledge Base Chunks&lt;br&gt;
    ↓&lt;br&gt;
Retrieved Context&lt;br&gt;
    ↓&lt;br&gt;
Qwen Language Model&lt;br&gt;
    ↓&lt;br&gt;
Final Answer&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic AI Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The retrieval system is exposed to the agent through a custom:&lt;br&gt;
knowledge_base_search() tool.&lt;br&gt;
The project uses &lt;strong&gt;smolagents CodeAgent&lt;/strong&gt; along with the:&lt;br&gt;
"Qwen/Qwen2.5-72B-Instruct" model for response generation.&lt;br&gt;
The agent retrieves relevant information from the knowledge base before generating a response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closed-Domain Knowledge Restriction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most important features of this project is the strict knowledge-base-only approach.&lt;br&gt;
The assistant is instructed not to use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wikipedia&lt;/li&gt;
&lt;li&gt;Internet searches&lt;/li&gt;
&lt;li&gt;External websites&lt;/li&gt;
&lt;li&gt;External APIs&lt;/li&gt;
&lt;li&gt;External documents&lt;/li&gt;
&lt;li&gt;General pretrained knowledge&lt;/li&gt;
&lt;li&gt;Guessing or assumptions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the knowledge base does not contain sufficient information, the intended response is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The knowledge base does not contain enough content to answer this question."&lt;br&gt;
This makes the system more suitable for applications where responses need to remain within a controlled information domain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Technologies Used&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;LangChain&lt;/li&gt;
&lt;li&gt;Sentence Transformers&lt;/li&gt;
&lt;li&gt;FAISS&lt;/li&gt;
&lt;li&gt;BM25&lt;/li&gt;
&lt;li&gt;Hugging Face Transformers&lt;/li&gt;
&lt;li&gt;smolagents&lt;/li&gt;
&lt;li&gt;Qwen 2.5 72B Instruct&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Building this project helped me understand how different components of an AI application work together rather than treating an LLM as a standalone system.&lt;/p&gt;

&lt;p&gt;In particular, I gained practical experience with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document chunking&lt;/li&gt;
&lt;li&gt;Text embeddings&lt;/li&gt;
&lt;li&gt;Vector databases/search&lt;/li&gt;
&lt;li&gt;BM25 retrieval&lt;/li&gt;
&lt;li&gt;Hybrid search&lt;/li&gt;
&lt;li&gt;Retrieval-Augmented Generation&lt;/li&gt;
&lt;li&gt;AI agents and tools&lt;/li&gt;
&lt;li&gt;LLM integration&lt;/li&gt;
&lt;li&gt;Closed-domain AI systems&lt;/li&gt;
&lt;li&gt;Controlling unsupported LLM responses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Future Improvements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some improvements I would like to implement next include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding PDF and document ingestion&lt;/li&gt;
&lt;li&gt;Persistent vector storage&lt;/li&gt;
&lt;li&gt;A web-based interface&lt;/li&gt;
&lt;li&gt;Better retrieval evaluation&lt;/li&gt;
&lt;li&gt;A program-level relevance gate before sending queries to the LLM&lt;/li&gt;
&lt;li&gt;Conversation history while maintaining the closed-domain restriction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This project was a great hands-on experience in understanding how &lt;strong&gt;RAG + Hybrid Search + Agentic AI + LLMs&lt;/strong&gt; can be combined to build a more controlled AI assistant.&lt;/p&gt;

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