Skip to content

shu7620/rag_database_routing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧭 RAG Database Routing System

Python Framework LLM

📖 Project Overview

The RAG Database Routing system is an intelligent query orchestration layer designed to optimize information retrieval. Instead of querying every available data source (which is slow and expensive), this system uses an LLM-based Router to analyze user intent and direct the query to the most relevant specialized database.

Why Routing?

  • Efficiency: Reduces latency by skipping irrelevant data stores.
  • Accuracy: Ensures structured questions go to SQL and semantic questions go to Vector DBs.
  • Scalability: Easily plug in new data sources (GraphDB, APIs, etc.) without breaking the pipeline.

🛠️ System Architecture

The pipeline follows a multi-stage process:

  1. Query Analysis: The LLM evaluates the user prompt.
  2. Routing Logic: The router classifies the query into categories (e.g., structured_data, semantic_search, or general_knowledge).
  3. Execution: * SQL Route: Converts natural language to SQL for structured databases.
    • Vector Route: Performs similarity search for unstructured documents.
    • Fallback: Standard LLM response for general queries.
  4. Synthesis: Combines retrieved data into a final coherent answer.

📂 Project Structure

├── agents/             # Routing logic and LLM agent definitions
├── config/             # Connection strings and API configurations
├── data/               # Sample datasets and vector embeddings
├── notebooks/          # Research and experimentation scripts
├── src/                
│   ├── routers/        # Logic for query classification
│   ├── retrievers/     # SQL and Vector search implementations
│   └── main.py         # Application entry point
├── requirements.txt    # Project dependencies
└── .env.example        # Environment variables template

Installation & usage

1. Clone the repository:

   git clone [https://github.com/shu7620/rag_database_routing.git](https://github.com/shu7620/rag_database_routing.git)
   cd rag_database_routing
   cd Spam_Sms_Detection

2. Set up virtual environment:

    python -m venv venv

    source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies:

   pip install -r requirements.txt

4. Environment Variables: Create a .env file and add your keys:

   OPENAI_API_KEY=your_key_here
   DATABASE_URL=your_sql_connection_string
   VECTOR_STORE_API=your_vector_key

📊 Performance & Routing Logic Table

Query Type Destination Methodology
"What was the total revenue in Q3?" SQL Database Text-to-SQL Conversion
"Explain the company policy on remote work." Vector Store Semantic Embedding Search
"Who is the CEO?" Knowledge Graph Relationship Mapping
"Hello, how are you?" LLM Chat Direct Response (No Retrieval)

License

Maintained By shu7620

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages