Inspiration
Enterprise teams deploying RAG systems face a critical problem: they're flying blind. When an LLM gives a wrong answer in production, teams scramble to figure out why. Costs spiral unpredictably as vector searches and LLM calls stack up. And worst of all, they only discover edge cases when customers complain. We were inspired to shift RAG from reactive firefighting to proactive optimization. What if you could test your RAG system like a red team tests security? What if you could slash costs by 60-80% through intelligent caching? What if every query gave you complete visibility into why the LLM answered that way? Maestro was born from this vision: an orchestration layer that makes enterprise RAG transparent, cost-efficient, and battle-tested.
What it does
Maestro is a plug-and-play middleware that sits between your application and your RAG stack (vector DB + LLM). It provides three game-changing capabilities: AI-Powered Adversarial Testing - Industry first! Uses Google Gemini 2.0 Flash to automatically generate challenging test queries (cross-domain, edge cases, multi-hop reasoning, contradictions). Maestro identifies weak spots in your knowledge base before customers do, and provides actionable recommendations to fix them. Semantic Caching (60-80% cost reduction) - Embedding-based cache that returns semantically similar queries in 5ms instead of 800-1200ms (240x faster). Only $0 per cached query vs $0.015-0.030 for full retrieval. Hit rates of 60%+ after warmup. Smart Query Routing - Automatically classifies queries as simple/moderate/complex and routes them to fast/balanced/comprehensive retrieval strategies. Simple questions get 2 documents in 200ms for $0.003. Complex queries get 10 documents with verification for maximum accuracy. Plus full observability: Real-time dashboards, audit trails, confidence scores, document attribution, and cost tracking for every single query.
How we built it
Backend (Python/FastAPI):
- Core orchestrator with 11-step processing pipeline (cache check → query classification → strategy selection → budget validation → retrieval → LLM generation → confidence scoring → verification → caching → metrics logging)
- Semantic cache using sentence-transformers (all-MiniLM-L6-v2) with cosine similarity matching (0.88 threshold) and LRU eviction
- Adversarial testing engine powered by Google Gemini 2.0 Flash for both query generation and weakness analysis
- Smart router with rule-based classification and three retrieval strategies (fast/balanced/comprehensive)
- Mock vector DB simulating Pinecone/Weaviate for demos (swappable with real adapters)
- 62 passing tests covering all core components with pytest
Frontend (Next.js 14/React 19):
- Real-time metrics dashboard with expandable time-series charts (query volume, cache hit rate, cost savings, latency, confidence)
- Interactive adversarial tester UI for running AI-generated test suites
- Audit trail showing recent queries with source document attribution
- Performance radar chart summarizing key metrics
- Built with Recharts for visualizations and Tailwind CSS 4 for styling
Infrastructure:
- Deployed on Railway with live demo at maestro-production-6e8b.up.railway.app
- Docker-ready for enterprise deployment
- Complete separation of concerns (backend/frontend directories)
Challenges we ran into
- Query Router Performance - Initially designed to use Gemini for query classification, but this added 15-20 seconds per request. Pivoted to a rule-based classifier with keyword detection, reducing classification time to <1 second while maintaining accuracy.
- Cache Similarity Threshold Tuning - Finding the sweet spot for semantic similarity was tricky. Too low (0.7) and we'd return irrelevant cached answers. Too high (0.95) and cache hit rates dropped to 10%. Settled on 0.88 through extensive testing, achieving 60%+ hit rates with high relevance.
- Demo Reliability - LLM APIs can fail. Built comprehensive fallback strategies: hand-crafted adversarial queries if Gemini unavailable, graceful degradation in the orchestrator, and mock vector DB to ensure demos never crash.
- Time-Series Data Structure - Had to design an efficient bucketing system for metrics that could handle real-time queries without overwhelming the frontend. Implemented configurable time windows with automatic aggregation.
- Balancing Complexity vs. Simplicity - Enterprise RAG is complex, but we needed the UI to be intuitive. Solved by using progressive disclosure: simple query interface upfront, with detailed metrics/audit trails accessible on demand.
Accomplishments that we're proud of
Industry-first AI-powered adversarial testing for RAG - We genuinely couldn't find anyone else doing this. Using AI to test AI systems is meta and powerful. 240x latency improvement and 67% cost reduction - Real, measurable performance gains with live demo data to prove it. Production-ready quality - 62 passing tests, full error handling, real-time monitoring, and a clean adapter pattern that works with any vector DB or LLM. Beautiful, functional UI - Real-time dashboards with time-series visualizations that actually help you understand what's happening in your RAG pipeline. Strategic positioning - Targets both Google Track (Performance & Scalability with Gemini-powered testing) and Reliability Track (Trust & Safety through adversarial testing). Live deployed system - Not vaporware! Fully functional demo running on Railway.
What we learned
AI testing AI is incredibly powerful - Using Gemini to generate adversarial queries revealed edge cases we never would have thought of manually. The AI can reason about what makes a query challenging in ways that static test generation can't. Semantic similarity is nuanced - A 0.88 threshold for cache hits feels arbitrary, but it represents hours of tuning to balance hit rate vs. relevance. Small changes (0.85 vs 0.90) dramatically affect user experience. Observability is non-negotiable for production RAG - You can't optimize what you can't measure. Building comprehensive metrics from day one paid huge dividends in debugging and performance tuning. Rule-based systems still have a place - We initially over-engineered the query router with LLM classification. Sometimes simple keyword matching is faster and good enough. The middleware pattern is powerful - By sitting between the application and RAG stack, we can optimize without requiring any application code changes. Plug-and-play is a huge value proposition for enterprises. Collaboration clarity matters - With a 2-person team (backend/frontend split), clear directory structure and documented boundaries (COLLABORATION.md) kept us moving fast without stepping on each other's toes.
What's next for Maestro
- Real Vector DB Integrations - Production adapters for Pinecone, Weaviate, Qdrant, and Chroma (currently using mock for demos)
- Multi-LLM Support - Route different query types to different LLMs (Claude for reasoning, GPT-4 for creativity, Gemini for speed)
- Advanced Analytics - A/B testing framework, query trend analysis, anomaly detection, and automated performance reports
- Enterprise Features - Multi-tenant support, RBAC, audit compliance, SLA tracking, and cost allocation by team/project
- Expanded Adversarial Testing - Bias detection, hallucination testing, reasoning chain validation, and automated knowledge base improvement suggestions
- Distributed Caching - Redis/Memcached integration for multi-instance deployments with shared cache
- Query Rewriting - Automatic query expansion and reformulation to improve retrieval quality
- Benchmarking Suite - Compare performance across different vector DBs, embedding models, and LLMs with standardized test sets
Built With
- fastapi
- next.js
- python
- rag
- railway
- react
- typescript

Log in or sign up for Devpost to join the conversation.