<?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: Edu Arana</title>
    <description>The latest articles on DEV Community by Edu Arana (@arananet).</description>
    <link>https://dev.to/arananet</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2118120%2F185cc8c5-e0c7-47df-b00a-9c7b0bc780f2.png</url>
      <title>DEV Community: Edu Arana</title>
      <link>https://dev.to/arananet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arananet"/>
    <language>en</language>
    <item>
      <title>I Built a Swarm Agent RAG System Inspired by Karpathy's LLM Wiki</title>
      <dc:creator>Edu Arana</dc:creator>
      <pubDate>Wed, 22 Apr 2026 10:14:46 +0000</pubDate>
      <link>https://dev.to/arananet/i-built-a-swarm-agent-rag-system-inspired-by-karpathys-llm-wiki-2adn</link>
      <guid>https://dev.to/arananet/i-built-a-swarm-agent-rag-system-inspired-by-karpathys-llm-wiki-2adn</guid>
      <description>&lt;p&gt;Most RAG systems use a single retriever to search a vector database. It works — until your knowledge base has code, images, tables, and text all mixed together. One retriever can't specialize in all of them.&lt;/p&gt;

&lt;p&gt;So I built rag-swarm — a multimodal RAG system where specialized swarm agents search in parallel, and an LLM-powered oracle evaluates every result before it reaches the user.&lt;/p&gt;

&lt;p&gt;The architecture is inspired by &lt;a href="https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f" rel="noopener noreferrer"&gt;Karpathy's LLM Wiki&lt;/a&gt; three-layer design (ingestion → retrieval → generation), adapted for swarm-based vector retrieval with enterprise-grade evaluation. Where Karpathy's wiki describes a clean separation of concerns for LLM-augmented knowledge systems, rag-swarm takes the retrieval layer and replaces the single search path with a coordinated swarm of specialized agents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem with Single-Retriever RAG&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traditional RAG does this:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Embed the query&lt;/li&gt;
&lt;li&gt;Search the vector DB&lt;/li&gt;
&lt;li&gt;Return top-K results&lt;/li&gt;
&lt;li&gt;Feed them to an LLM&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It treats all documents the same. A Python function, a data table, and a paragraph of text all get the same embedding strategy, the same search, the same ranking. That's leaving relevance on the table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Swarm RAG Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of one retriever, rag-swarm dispatches your query to 4 specialized agents running in parallel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TextAgent — optimized for prose and documentation&lt;/li&gt;
&lt;li&gt;CodeAgent — understands function signatures, docstrings, imports&lt;/li&gt;
&lt;li&gt;ImageAgent — works with captions and CLIP embeddings&lt;/li&gt;
&lt;li&gt;TableAgent — handles structured/tabular data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each agent searches the same ChromaDB vector store but with modality-aware strategies. The results are deduplicated, re-ranked with a cross-encoder, and then sent to the Oracle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Oracle — The Quality Gate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The oracle is the part I'm most proud of. It's a two-stage evaluator:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fast pass — embedding similarity between the query and each result&lt;/li&gt;
&lt;li&gt;Deep pass — LLM reasoning that explains why each result is relevant or not&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every result comes back with a human-readable verdict:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"relevance_score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.9572&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"reasoning"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"This chunk is RELEVANT as it directly addresses the query by explaining the functionality and evaluation process of the Oracle Agent."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"passed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No black box. The user sees the oracle's reasoning for every single result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semantic Query Cache&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every query gets embedded once. If a similar query was asked before (cosine similarity ≥ 0.95), the cached response returns instantly — skipping the entire swarm + oracle pipeline. Near-duplicate queries hit cache too, not just exact matches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MCP Server — Plug Into Any AI Host&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The whole system is exposed as an MCP server (Model Context Protocol, spec 2025-11-25). That means Claude Desktop, VS Code Copilot, or any MCP-compatible host can use it as a tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rag-swarm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"uv"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"--directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./backend"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"-m"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"app.mcp_server"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7 tools, 2 resources, 2 prompts — all discoverable by the host.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend: Python + FastAPI + ChromaDB&lt;/li&gt;
&lt;li&gt;Inference: Cloudflare Workers AI (embeddings, LLM, VLM, re-ranker) — no local GPU needed&lt;/li&gt;
&lt;li&gt;Frontend: React + Vite + D3.js for vector space visualization&lt;/li&gt;
&lt;li&gt;MCP: FastMCP with stdio and streamable HTTP transports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I built a comparison mode that runs both approaches side-by-side with evaluation metrics (Precision, Recall, NDCG, MRR). The swarm consistently surfaces results across modalities that a single retriever misses — at the cost of slightly lower average relevance because it casts a wider net.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project is open source under MIT:&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://dev.tourl"&gt;github.com/arananet/rag-swarm&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;backend &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
uvicorn app.main:app &lt;span class="nt"&gt;--reload&lt;/span&gt; &lt;span class="nt"&gt;--port&lt;/span&gt; 8000

&lt;span class="nb"&gt;cd&lt;/span&gt; ../frontend &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm run dev
&lt;span class="c"&gt;# Open http://localhost:5173&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd love feedback — especially on the oracle evaluation approach and whether the swarm architecture makes sense for your use cases.&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
  </channel>
</rss>
