<?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: Sachin Sajukumar</title>
    <description>The latest articles on DEV Community by Sachin Sajukumar (@sachin_sajukumar_04).</description>
    <link>https://dev.to/sachin_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%2F4098792%2F3212179c-b879-4511-8f47-ee2ccf2ce090.png</url>
      <title>DEV Community: Sachin Sajukumar</title>
      <link>https://dev.to/sachin_sajukumar_04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sachin_sajukumar_04"/>
    <language>en</language>
    <item>
      <title>Building an Agentic RAG AI Agent with FAISS, BM25 and Qwen</title>
      <dc:creator>Sachin Sajukumar</dc:creator>
      <pubDate>Sun, 30 Aug 2026 04:56:46 +0000</pubDate>
      <link>https://dev.to/sachin_sajukumar_04/building-an-agentic-rag-ai-agent-with-faiss-bm25-and-qwen-13ed</link>
      <guid>https://dev.to/sachin_sajukumar_04/building-an-agentic-rag-ai-agent-with-faiss-bm25-and-qwen-13ed</guid>
      <description>&lt;p&gt;I recently completed a project as part of my AI Engineering learning journey: an Agentic RAG AI Agent that answers user questions based on a provided knowledge base.&lt;/p&gt;

&lt;p&gt;The main goal of this project was to build an AI assistant that does not simply rely on its general knowledge. Instead, it first searches a knowledge base, retrieves relevant information, and then generates an answer using that retrieved context.&lt;/p&gt;

&lt;p&gt;What is the idea behind the project?&lt;/p&gt;

&lt;p&gt;Large Language Models can sometimes answer questions using their pre-trained knowledge, even when that information is not available in the documents provided to the system. To address this, I built a Retrieval-Augmented Generation (RAG) pipeline.&lt;br&gt;
The workflow looks like this:&lt;/p&gt;

&lt;p&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;Technologies Used&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python – Main programming language&lt;/li&gt;
&lt;li&gt;Sentence Transformers – Generating text embeddings&lt;/li&gt;
&lt;li&gt;FAISS – Semantic vector similarity search&lt;/li&gt;
&lt;li&gt;BM25 – Keyword-based search&lt;/li&gt;
&lt;li&gt;Hybrid Search – Combining vector and keyword search&lt;/li&gt;
&lt;li&gt;Qwen2.5-72B-Instruct – Generating the final response&lt;/li&gt;
&lt;li&gt;Hugging Face Transformers – Loading and using the language model&lt;/li&gt;
&lt;li&gt;Visual Studio Code – Development environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How the system works&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Knowledge Base&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The system starts with a predefined knowledge base containing information about specific topics.&lt;br&gt;
The goal is to ensure that the AI assistant answers questions only from this available information.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Document Chunking&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Large documents are divided into smaller chunks.&lt;br&gt;
This helps the retrieval system find the specific section of a document that is most relevant to the user's question.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Embedding Generation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each text chunk is converted into a numerical representation called an embedding using a Sentence Transformer model.&lt;br&gt;
These embeddings allow the system to perform semantic search based on meaning rather than only exact keywords.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FAISS Vector Search&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When a user asks a question, the question is also converted into an embedding.&lt;br&gt;
FAISS compares the query embedding with the document embeddings and retrieves the most semantically similar chunks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;BM25 Keyword Search&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to semantic search, I also implemented BM25 for keyword-based retrieval.&lt;br&gt;
This is useful for finding exact terms, technical concepts, and important keywords.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hybrid Search&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The results from FAISS and BM25 are combined to improve retrieval quality.&lt;br&gt;
This gives the system the advantages of both semantic understanding and exact keyword matching.&lt;br&gt;
Hybrid Search = Vector Search + Keyword Search&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Answer Generation with Qwen&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most relevant chunks are combined into a context.&lt;/p&gt;

&lt;p&gt;The Qwen language model receives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The retrieved knowledge base context&lt;/li&gt;
&lt;li&gt;The user's question&lt;/li&gt;
&lt;li&gt;Strict instructions to answer only from the provided context
The model then generates the final answer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example Interaction: Question Inside the Knowledge Base&lt;/p&gt;

&lt;p&gt;You: What is RAG?&lt;/p&gt;

&lt;p&gt;Searching knowledge base...&lt;/p&gt;

&lt;p&gt;Agent: RAG stands for Retrieval-Augmented Generation.&lt;br&gt;
It is an AI approach that combines information retrieval&lt;br&gt;
with language generation. The system retrieves relevant&lt;br&gt;
information from a knowledge base and provides it as context&lt;br&gt;
to a language model to generate an answer.&lt;/p&gt;

&lt;p&gt;In this case, the system finds relevant information in the knowledge base and uses it to generate the answer.&lt;/p&gt;

&lt;p&gt;Example Interaction: Question Outside the Knowledge Base&lt;/p&gt;

&lt;p&gt;You: Who is the Prime Minister of India?&lt;/p&gt;

&lt;p&gt;Searching knowledge base...&lt;/p&gt;

&lt;p&gt;Agent: Sorry, I cannot answer this question because&lt;br&gt;
the required information is not available in the&lt;br&gt;
provided knowledge base.&lt;/p&gt;

&lt;p&gt;One of the important features of this project is attempting to prevent the AI from answering questions that are outside the provided knowledge base.&lt;/p&gt;

&lt;p&gt;The model is instructed to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer only from the retrieved context&lt;/li&gt;
&lt;li&gt;Avoid using unsupported general knowledge&lt;/li&gt;
&lt;li&gt;Avoid guessing or creating information&lt;/li&gt;
&lt;li&gt;Reject questions when sufficient information is not available&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Challenges I Faced&lt;/p&gt;

&lt;p&gt;During development, I initially experimented with a &lt;code&gt;CodeAgent&lt;/code&gt; approach. However, the language model sometimes generated unsupported tool calls and did not consistently follow the code format required by the agent framework.&lt;/p&gt;

&lt;p&gt;For example, instead of using the available knowledge base search tool, the model attempted to call a tool that did not exist.&lt;/p&gt;

&lt;p&gt;I simplified the architecture by using a direct RAG pipeline:&lt;br&gt;
User Query&lt;br&gt;
    ↓&lt;br&gt;
Retrieve Relevant Context&lt;br&gt;
    ↓&lt;br&gt;
FAISS + BM25 Hybrid Search&lt;br&gt;
    ↓&lt;br&gt;
Provide Context to Qwen&lt;br&gt;
    ↓&lt;br&gt;
Generate Final Answer&lt;/p&gt;

&lt;p&gt;This approach was simpler and more reliable for my project. I also experimented with different Qwen model sizes. I moved to Qwen2.5-72B-Instruct to reduce response time and make the project more practical for local execution.&lt;/p&gt;

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

&lt;p&gt;Through this project, I gained hands-on experience with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval-Augmented Generation&lt;/li&gt;
&lt;li&gt;Text chunking&lt;/li&gt;
&lt;li&gt;Text embeddings&lt;/li&gt;
&lt;li&gt;Vector databases and similarity search&lt;/li&gt;
&lt;li&gt;FAISS&lt;/li&gt;
&lt;li&gt;BM25&lt;/li&gt;
&lt;li&gt;Hybrid search&lt;/li&gt;
&lt;li&gt;Prompt engineering&lt;/li&gt;
&lt;li&gt;Knowledge-grounded AI systems&lt;/li&gt;
&lt;li&gt;Large Language Model integration&lt;/li&gt;
&lt;li&gt;Building an AI project in Python and VS Code&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Some features I would like to add in the future include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PDF and document upload support&lt;/li&gt;
&lt;li&gt;A web interface using Gradio or Streamlit&lt;/li&gt;
&lt;li&gt;Source citations with every answer&lt;/li&gt;
&lt;li&gt;Better relevance threshold checking&lt;/li&gt;
&lt;li&gt;Persistent vector storage&lt;/li&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;Support for multiple knowledge bases&lt;/li&gt;
&lt;li&gt;RAG evaluation metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This project was a great hands-on learning experience for understanding how modern AI assistants can be grounded in external knowledge.&lt;/p&gt;

&lt;p&gt;I'm continuing to learn and build more AI Engineering projects. Feedback and suggestions are welcome!&lt;/p&gt;

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