<?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: Halan P Babu</title>
    <description>The latest articles on DEV Community by Halan P Babu (@halan_pbabu_202f93123bd9).</description>
    <link>https://dev.to/halan_pbabu_202f93123bd9</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%2F4102140%2Fc4175a5c-d431-4e14-b802-ae832a6ac6b3.jpeg</url>
      <title>DEV Community: Halan P Babu</title>
      <link>https://dev.to/halan_pbabu_202f93123bd9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/halan_pbabu_202f93123bd9"/>
    <language>en</language>
    <item>
      <title>Building an Agentic Hybrid RAG System with FAISS, BM25, and smolagents</title>
      <dc:creator>Halan P Babu</dc:creator>
      <pubDate>Mon, 31 Aug 2026 05:47:58 +0000</pubDate>
      <link>https://dev.to/halan_pbabu_202f93123bd9/building-an-agentic-hybrid-rag-system-with-faiss-bm25-and-smolagents-3ok1</link>
      <guid>https://dev.to/halan_pbabu_202f93123bd9/building-an-agentic-hybrid-rag-system-with-faiss-bm25-and-smolagents-3ok1</guid>
      <description>&lt;p&gt;I've been learning about &lt;strong&gt;RAG (Retrieval-Augmented Generation)&lt;/strong&gt; and wanted to understand how it actually works beyond just reading about it.&lt;/p&gt;

&lt;p&gt;So, I decided to build my own &lt;strong&gt;Agentic Hybrid RAG System&lt;/strong&gt; using Python and open-source AI tools.&lt;/p&gt;

&lt;p&gt;The goal was simple: allow a user to ask questions and get answers based on information stored in a custom knowledge base.&lt;/p&gt;

&lt;p&gt;But instead of using only one retrieval method, I wanted to combine &lt;strong&gt;semantic search and keyword search&lt;/strong&gt; to make the retrieval more reliable.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What is RAG?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RAG stands for &lt;strong&gt;Retrieval-Augmented Generation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In a normal LLM application, the model generates an answer based on its trained knowledge. With RAG, we first retrieve relevant information from an external knowledge base and then provide that information to the LLM.&lt;/p&gt;

&lt;p&gt;The basic idea is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Question
      ↓
Retrieve Relevant Information
      ↓
Give Context to LLM
      ↓
Generate Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful when we want an AI system to answer questions using our own documents or knowledge base.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Why Hybrid Search?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While building the project, I learned that there isn't one perfect way to search documents.&lt;/p&gt;

&lt;p&gt;That's why I used two retrieval techniques:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FAISS&lt;/strong&gt; for semantic search and &lt;strong&gt;BM25&lt;/strong&gt; for keyword search.&lt;/p&gt;

&lt;p&gt;FAISS uses embeddings to find content that is similar in meaning.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How can I authenticate my account?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It can find a document talking about:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"User authentication and login methods"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;even if the exact words aren't the same.&lt;/p&gt;

&lt;p&gt;BM25 works differently. It focuses more on matching important keywords.&lt;/p&gt;

&lt;p&gt;So if someone searches:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"FAISS vector search"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;BM25 can give higher importance to documents containing those exact terms.&lt;/p&gt;

&lt;p&gt;By combining both approaches, the system can benefit from &lt;strong&gt;meaning-based search as well as exact keyword matching&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  How My System Works
&lt;/h2&gt;

&lt;p&gt;The overall architecture looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    User Question
                          ↓
                       CodeAgent
                          ↓
                Knowledge Base Search
                          ↓
                 ┌────────┴────────┐
                 ↓                 ↓
               FAISS              BM25
          Semantic Search     Keyword Search
                 ↓                 ↓
                 └────────┬────────┘
                          ↓
                   Hybrid Scoring
                          ↓
                  Relevant Chunks
                          ↓
                    Qwen 2.5 72B
                          ↓
                     Final Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For semantic search, I used the &lt;strong&gt;&lt;code&gt;all-MiniLM-L6-v2&lt;/code&gt;&lt;/strong&gt; Sentence Transformer model to convert text into embeddings.&lt;/p&gt;

&lt;p&gt;These embeddings are stored and searched using FAISS.&lt;/p&gt;

&lt;p&gt;For keyword retrieval, I used BM25.&lt;/p&gt;

&lt;p&gt;I then combine the scores using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hybrid Score =
0.7 × Vector Score +
0.3 × Keyword Score
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I chose a 70/30 split so semantic similarity has more influence while keyword matching still contributes to the final ranking.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Document Chunking&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before searching the documents, I split them into smaller chunks using LangChain's &lt;code&gt;RecursiveCharacterTextSplitter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My current configuration is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk Size: 500
Chunk Overlap: 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chunking is important because sending an entire large document to the model isn't always useful.&lt;/p&gt;

&lt;p&gt;Smaller, relevant pieces of information allow the retrieval system to find more precise context.&lt;/p&gt;

&lt;p&gt;The overlap also helps prevent important information from being lost between two chunks.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Adding an Agent&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I didn't want the application to be just a simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question → Search → Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;pipeline.&lt;/p&gt;

&lt;p&gt;I used &lt;strong&gt;smolagents&lt;/strong&gt; and a &lt;code&gt;CodeAgent&lt;/code&gt; with a custom &lt;code&gt;knowledge_base_search&lt;/code&gt; tool.&lt;/p&gt;

&lt;p&gt;The agent can use the search tool to retrieve information from the knowledge base before generating an answer.&lt;/p&gt;

&lt;p&gt;For the LLM, I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Qwen/Qwen2.5-72B-Instruct
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives the system an additional reasoning layer on top of the retrieval process.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;The Biggest Thing I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The biggest lesson from this project was that &lt;strong&gt;RAG isn't just about using an LLM&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are many components involved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
   ↓
Chunking
   ↓
Embeddings
   ↓
Vector Search
   +
Keyword Search
   ↓
Ranking
   ↓
Relevant Context
   ↓
LLM
   ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the retrieval step returns irrelevant information, even a powerful LLM can struggle to provide a good answer.&lt;/p&gt;

&lt;p&gt;So, improving the retrieval process can be just as important as choosing the LLM.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Challenges&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Getting all the components to work together wasn't always straightforward.&lt;/p&gt;

&lt;p&gt;I faced compatibility and API issues while working with different versions of the AI libraries. Debugging those issues actually helped me understand the frameworks better.&lt;/p&gt;

&lt;p&gt;Instead of simply following a tutorial, I had to understand what each component was doing and how information was moving through the system.&lt;/p&gt;

&lt;p&gt;That was probably the most valuable part of the project for me.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What's Next?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The current system is a foundation, and there are several things I'd like to improve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a reranking model&lt;/li&gt;
&lt;li&gt;Evaluate retrieval accuracy properly&lt;/li&gt;
&lt;li&gt;Improve chunking strategies&lt;/li&gt;
&lt;li&gt;Add better hallucination handling&lt;/li&gt;
&lt;li&gt;Build a cleaner user interface&lt;/li&gt;
&lt;li&gt;Experiment with different hybrid-search weights&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm still learning about RAG and agentic AI, so this project is definitely not finished.&lt;/p&gt;

&lt;p&gt;But building it from the ground up gave me a much better understanding of how &lt;strong&gt;retrieval, embeddings, vector databases, keyword search, agents, and LLMs come together to build an AI application.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project started as an attempt to understand RAG, but it ended up teaching me much more about building AI systems in general.&lt;/p&gt;

&lt;p&gt;The main takeaway for me is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A good AI application isn't just about having a powerful model. It's about building a good system around that model.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that's what I'm continuing to explore.&lt;/p&gt;

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