<?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: Zusu12</title>
    <description>The latest articles on DEV Community by Zusu12 (@zusu12).</description>
    <link>https://dev.to/zusu12</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%2F3062399%2Fe559735f-227f-47a7-be94-b71c332a9f89.png</url>
      <title>DEV Community: Zusu12</title>
      <link>https://dev.to/zusu12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zusu12"/>
    <language>en</language>
    <item>
      <title>🚀 Building My First Hybrid RAG Agent: A CS Student's Journey into AI</title>
      <dc:creator>Zusu12</dc:creator>
      <pubDate>Wed, 05 Aug 2026 15:58:29 +0000</pubDate>
      <link>https://dev.to/zusu12/building-my-first-hybrid-rag-agent-a-cs-students-journey-into-ai-3o2p</link>
      <guid>https://dev.to/zusu12/building-my-first-hybrid-rag-agent-a-cs-students-journey-into-ai-3o2p</guid>
      <description>&lt;h1&gt;
  
  
  🚀 Built a Hybrid RAG Agent — Here's What I Learned
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Hey DEV's! 👋
&lt;/h2&gt;

&lt;p&gt;I'm a Computer Science student who's been diving deep into AI lately. Instead of just watching tutorials, I decided to build something real — a &lt;strong&gt;Hybrid RAG Agent&lt;/strong&gt; that retrieves information from documents and generates accurate answers.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 The Problem I Was Solving
&lt;/h2&gt;

&lt;p&gt;Most beginner RAG projects use only vector search for retrieval. But here's what I discovered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vector search&lt;/strong&gt; is great for semantic meaning but misses exact keyword matches&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyword search (BM25)&lt;/strong&gt; catches exact terms but doesn't understand context&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single-method retrieval&lt;/strong&gt; = answers that are either too vague or miss the point entirely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The solution? &lt;strong&gt;Hybrid RAG&lt;/strong&gt; — combining both approaches with intelligent reranking.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Query
    │
    ▼
┌─────────────────────────────────┐
│ Hybrid Search Retrieval Engine  │
│ ├─ Semantic (ChromaDB + Cosine) │
│ └─ Lexical (BM25 Keyword Match) │
└────────────────┬────────────────┘
                 │ Top-K Candidates
                 ▼
┌─────────────────────────────────┐
│     Cross-Encoder Reranking     │ ← Evaluates full passage-query relevance
└────────────────┬────────────────┘
                 │ Top-3 Highest Scoring Chunks
                 ▼
┌─────────────────────────────────┐
│      LLM Generation Context     │ ← Appends conversation history memory
└────────────────┬────────────────┘
                 │
                 ▼
          Answer + Sources
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: Python + Flask&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vector DB&lt;/strong&gt;: ChromaDB (persistent)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embeddings&lt;/strong&gt;: sentence-transformers (all-mpnet-base-v2)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyword Search&lt;/strong&gt;: BM25Okapi&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM&lt;/strong&gt;: Hugging Face API (Qwen2.5-7B / Mistral / Llama-3.1)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reranker&lt;/strong&gt;: ms-marco-MiniLM-L-6-v2 (cross-encoder)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: Custom HTML/CSS/JS with glassmorphic dark UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-format docs (PDF, TXT, DOCX, Markdown)&lt;/li&gt;
&lt;li&gt;Stateful conversation memory&lt;/li&gt;
&lt;li&gt;Persistent storage (survives restarts)&lt;/li&gt;
&lt;li&gt;Source citations in responses&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 How It Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Document Ingestion
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Split into chunks (500 chars, 50-char overlap)&lt;/li&gt;
&lt;li&gt;Embed with sentence-transformers&lt;/li&gt;
&lt;li&gt;Store in ChromaDB + build BM25 index&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Query Processing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Vector search finds semantically similar chunks&lt;/li&gt;
&lt;li&gt;BM25 finds exact keyword matches&lt;/li&gt;
&lt;li&gt;Both run in parallel&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Cross-Encoder Reranking
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Combines results from both searches&lt;/li&gt;
&lt;li&gt;Cross-encoder scores each query-chunk pair for relevance&lt;/li&gt;
&lt;li&gt;Sends only top-3 most relevant chunks to LLM&lt;/li&gt;
&lt;li&gt;This is the highest-ROI improvement for RAG systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Response Generation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;LLM generates answer with context + conversation history&lt;/li&gt;
&lt;li&gt;Returns grounded response with source citations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Challenges I Faced
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vector-only missed exact terms&lt;/strong&gt; → Added BM25 for keyword matching&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Too many irrelevant chunks&lt;/strong&gt; → Cross-encoder reranking fixed this&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lost conversation context&lt;/strong&gt; → Added stateful memory for multi-turn queries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not production-ready&lt;/strong&gt; → Added persistent storage, health checks, clean API&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 What's Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Add query expansion and HyDE for better recall&lt;/li&gt;
&lt;li&gt;Implement evaluation metrics (precision@k, recall@k)&lt;/li&gt;
&lt;li&gt;Add metadata filtering (date ranges, doc types)&lt;/li&gt;
&lt;li&gt;Deploy to Railway/Render with CI/CD&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🙏 Let's Connect!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What AI projects are you working on?&lt;/li&gt;
&lt;li&gt;Tried hybrid search or reranking in your RAG?&lt;/li&gt;
&lt;li&gt;Want to collaborate on open-source AI?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! Let's build together. 🚀&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt; #ai #rag #machinelearning #python #artificialintelligence #webdev #beginners #students&lt;/p&gt;

</description>
      <category>ai</category>
      <category>beginners</category>
      <category>learning</category>
      <category>rag</category>
    </item>
  </channel>
</rss>
