Cookies

With your permission, we use Google Analytics cookies to measure visits and improve the site. Necessary cookies are always on. You can change your choice or withdraw consent anytime in the footer, under Cookie settings. Cookie Policy

Skip to content

RAG and Knowledge ·Intermediate

RAG Agent with Database Routing

About this app

A Streamlit application that demonstrates an advanced implementation of RAG Agent with intelligent query routing. The system combines multiple specialized databases with smart fallback mechanisms to ensure reliable and accurate responses to user queries.

  • Complete open-source code
  • Step-by-step tutorial

Technical sheet

Category
RAG and Knowledge
Difficulty
Intermediate
Models
OpenAI
Frameworks
Agno, LangChain
Runs locally?
Needs cloud APIs
Required keys
OPENAI_API_KEY

License Apache-2.0 · content curated and maintained by Doutor AI.

Full tutorial

🎓 FREE Step-by-Step Tutorial

👉 Click here to follow our complete step-by-step tutorial and learn how to build this from scratch with detailed code walkthroughs, explanations, and best practices.

A Streamlit application that demonstrates an advanced implementation of RAG Agent with intelligent query routing. The system combines multiple specialized databases with smart fallback mechanisms to ensure reliable and accurate responses to user queries.

Features

  • Document Upload: Users can upload multiple PDF documents related to a particular company. These documents are processed and stored in one of the three databases: Product Information, Customer Support & FAQ, or Financial Information.
  • Natural Language Querying: Users can ask questions in natural language. The system automatically routes the query to the most relevant database using a agno agent as the router.
  • RAG Orchestration: Utilizes Langchain for orchestrating the retrieval augmented generation process, ensuring that the most relevant information is retrieved and presented to the user.
  • Fallback Mechanism: If no relevant documents are found in the databases, a LangGraph agent with a DuckDuckGo search tool is used to perform web research and provide an answer.

How to Run?

  1. Clone the Repository:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
cd rag_tutorials/rag_database_routing
  1. Install Dependencies:
pip install -r requirements.txt
  1. Run the Application:
streamlit run rag_database_routing.py
  1. Get OpenAI API Key: Obtain an OpenAI API key and set it in the application. This is required for initializing the language models used in the application.
  1. Setup Qdrant Cloud
  • Visit Qdrant Cloud
  • Create an account or sign in
  • Create a new cluster
  • Get your credentials:
  • Qdrant API Key: Found in API Keys section
  • Qdrant URL: Your cluster URL (format: https://xxx-xxx.aws.cloud.qdrant.io)
  1. Upload Documents: Use the document upload section to add PDF documents to the desired database.
  1. Ask Questions: Enter your questions in the query section. The application will route your question to the appropriate database and provide an answer.

Technologies Used

  • Langchain: For RAG orchestration, ensuring efficient retrieval and generation of information.
  • Agno Agent: Used as the router agent to determine the most relevant database for a given query.
  • LangGraph Agent: Acts as a fallback mechanism, utilizing DuckDuckGo for web research when necessary.
  • Streamlit: Provides a user-friendly interface for document upload and querying.
  • Qdrant: Used for managing the databases, storing and retrieving document embeddings efficiently.

How It Works?

1. Query Routing

The system uses a three-stage routing approach:

  • Vector similarity search across all databases
  • LLM-based routing for ambiguous queries
  • Web search fallback for unknown topics

2. Document Processing

  • Automatic text extraction from PDFs
  • Smart text chunking with overlap
  • Vector embedding generation
  • Efficient database storage

3. Answer Generation

  • Context-aware retrieval
  • Smart document combination
  • Confidence-based responses
  • Web research integration

From the same category

RAG and KnowledgeIntermediate

Agentic RAG Embedding Gemma

This Streamlit app demonstrates an agentic Retrieval-Augmented Generation (RAG) Agent using Google's EmbeddingGemma for embeddings and Llama 3.2 as th…

  • Llama
  • local
RAG and KnowledgeIntermediate

Agentic RAG with GPT-5

An agentic RAG application built with the Agno framework, featuring GPT-5 and LanceDB for efficient knowledge retrieval and question answering.

  • OpenAI

Need a tailor-made solution?

Not sure where to start with AI in your business? Get a free assessment and a tailored plan - no commitment.

Save hours every week with AI, no hassle

Doutor AI gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further.

See plans