Advanced RAG/Advanced Patterns
Advanced9 min

Router-Based RAG: Multi-Source Knowledge

Route queries to different retrieval sources based on classification — vector stores, SQL databases, APIs, or specialized indexes — for optimal answers from the right source.

Quick Reference

  • Router-Based RAG classifies the query first, then routes to the optimal retrieval source
  • Sources can include vector stores, SQL databases, APIs, graph databases, or web search
  • Use structured output classification to select the source with highest relevance probability
  • Fallback chains: if the primary source returns no results, try the secondary source
  • Multi-source fusion: query multiple sources in parallel and merge results
  • Critical for enterprise systems with heterogeneous data across multiple backends

Why Route Queries?

QueryRouter (classify)structured outputVector StoreProduct docsSQL DatabaseMetrics, usersWeb SearchReal-time dataGenerate Answer

Classify query → route to the best data source → generate grounded answer

Most real-world knowledge bases aren't a single vector store. A company has product docs in Pinecone, customer data in PostgreSQL, financial reports as PDFs, and real-time data from APIs. Router-Based RAG classifies each query and sends it to the source most likely to have the answer — rather than searching everything and hoping for the best.

Query TypeBest SourceWhy
'How do I configure OAuth?'Vector store (docs)Semantic search on documentation
'How many users signed up last month?'SQL databaseExact numerical query
'What's the current stock price?'API (real-time data)Needs live data, not static docs
'Who reports to the CTO?'Graph databaseRelationship traversal
'What did the CEO say in Q3 earnings?'Vector store (transcripts)Semantic search on unstructured text