惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
博客园 - Franky
Martin Fowler
Martin Fowler
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
The Cloudflare Blog
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
腾讯CDC
博客园_首页
博客园 - 司徒正美
D
DataBreaches.Net
I
InfoQ
GbyAI
GbyAI
IT之家
IT之家
罗磊的独立博客

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built a Swarm Agent RAG System Inspired by Karpathy's L...
Edu Arana · 2026-04-22 · via DEV Community

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.

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.

The architecture is inspired by Karpathy's LLM Wiki 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.

The Problem with Single-Retriever RAG

Traditional RAG does this:

  1. Embed the query
  2. Search the vector DB
  3. Return top-K results
  4. Feed them to an LLM

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.

How Swarm RAG Works

Instead of one retriever, rag-swarm dispatches your query to 4 specialized agents running in parallel:

  • TextAgent — optimized for prose and documentation
  • CodeAgent — understands function signatures, docstrings, imports
  • ImageAgent — works with captions and CLIP embeddings
  • TableAgent — handles structured/tabular data

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.

The Oracle — The Quality Gate

The oracle is the part I'm most proud of. It's a two-stage evaluator:

  1. Fast pass — embedding similarity between the query and each result
  2. Deep pass — LLM reasoning that explains why each result is relevant or not

Every result comes back with a human-readable verdict:

{
  "relevance_score": 0.9572,
  "reasoning": "This chunk is RELEVANT as it directly addresses the query by explaining the functionality and evaluation process of the Oracle Agent.",
  "passed": true
}

Enter fullscreen mode Exit fullscreen mode

No black box. The user sees the oracle's reasoning for every single result.

Semantic Query Cache

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.

MCP Server — Plug Into Any AI Host

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:

{
  "mcpServers": {
    "rag-swarm": {
      "command": "uv",
      "args": ["--directory", "./backend", "run", "python", "-m", "app.mcp_server"]
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

7 tools, 2 resources, 2 prompts — all discoverable by the host.

The Stack

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

Results

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.

Try It

The project is open source under MIT:

GitHub: github.com/arananet/rag-swarm

cd backend && pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

cd ../frontend && npm install && npm run dev
# Open http://localhost:5173

Enter fullscreen mode Exit fullscreen mode

I'd love feedback — especially on the oracle evaluation approach and whether the swarm architecture makes sense for your use cases.