math-routing-agent / README.md
bhoomika19's picture
updated readme
a62f47b
|
raw
history blame
7.2 kB

Math Agentic RAG - Intelligent Math Problem Solver

An advanced AI-powered mathematics tutoring system that combines knowledge base search, web search, and LLM capabilities to provide comprehensive step-by-step solutions to mathematical problems.

๐ŸŽฏ Overview

Math Agentic RAG is a sophisticated educational platform that leverages multiple AI technologies to solve mathematical problems with detailed explanations. The system intelligently routes queries through different knowledge sources to provide the most accurate and comprehensive solutions.

Key Features

  • ๐Ÿง  Multi-Source Intelligence: Combines knowledge base, web search, and Gemini LLM for optimal results
  • ๐Ÿ“š Step-by-Step Solutions: Detailed explanations with mathematical reasoning
  • โšก Intelligent Routing: Automatically selects the best source based on confidence scores
  • ๐ŸŽจ Beautiful Math Rendering: LaTeX-powered mathematical notation with KaTeX
  • ๐Ÿ“Š Analytics & Feedback: Built-in performance tracking and user feedback system
  • ๐Ÿ”’ Input Validation: Guardrails for safe and appropriate content
  • ๐Ÿš€ Real-time Processing: Fast response times with optimized caching

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend      โ”‚    โ”‚    Backend      โ”‚    โ”‚   External      โ”‚
โ”‚   (React)       โ”‚โ—„โ”€โ”€โ–บโ”‚   (FastAPI)     โ”‚โ—„โ”€โ”€โ–บโ”‚   Services      โ”‚
โ”‚                 โ”‚    โ”‚                 โ”‚    โ”‚                 โ”‚
โ”‚ โ€ข Search UI     โ”‚    โ”‚ โ€ข API Routes    โ”‚    โ”‚ โ€ข Qdrant DB    โ”‚
โ”‚ โ€ข Math Render   โ”‚    โ”‚ โ€ข Services      โ”‚    โ”‚ โ€ข Gemini LLM   โ”‚
โ”‚ โ€ข KaTeX Display โ”‚    โ”‚ โ€ข Guardrails    โ”‚    โ”‚ โ€ข MCP Service  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Technology Stack

Frontend:

  • React 18 with modern hooks
  • Tailwind CSS for styling
  • KaTeX for mathematical rendering
  • React Hot Toast for notifications

Backend:

  • FastAPI for high-performance APIs
  • Pydantic for data validation
  • Structlog for comprehensive logging
  • Python 3.11+

AI & Data:

  • Qdrant vector database for semantic search
  • Google Gemini 2.0 Flash for LLM processing
  • Model Context Protocol (MCP) for web search
  • Sentence Transformers for embeddings

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.11 or higher
  • Node.js 18+ and npm
  • Git

Environment Setup

  1. Clone the repository:
git clone https://github.com/bhoomika-254/Math-Agentic-RAG.git
cd Math-Agentic-RAG
  1. Set up environment variables:
# Create .env file in the root directory
touch .env

Add the following variables to your .env file:

# Required API Keys
GEMINI_API_KEY=your_gemini_api_key_here
QDRANT_URL=your_qdrant_cluster_url
QDRANT_API_KEY=your_qdrant_api_key
QDRANT_COLLECTION=collection_name

Backend Setup

  1. Navigate to backend directory:
cd backend
  1. Create and activate virtual environment:
python -m venv venv

# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Start the backend server:
python main.py

The backend will be available at http://localhost:8000

Frontend Setup

  1. Navigate to frontend directory (in a new terminal):
cd frontend
  1. Install dependencies:
npm install
  1. Start the development server:
npm start

The frontend will be available at http://localhost:3000

Database Setup

  1. Navigate to database directory:
cd database
  1. Install dependencies:
pip install -r requirements.txt
  1. Ingest sample math data:
python ingest.py

๐Ÿ“– Usage Guide

Basic Usage

  1. Open the application in your browser at http://localhost:3000

  2. Enter a math question in the search box, such as:

    • "Find the derivative of f(x) = 3xยฒ + 2x - 1"
    • "Solve the quadratic equation: xยฒ + 5x + 6 = 0"
    • "What is the integral of sin(x) dx?"
  3. View the solution with step-by-step explanations and beautiful mathematical notation

  4. Provide feedback using the thumbs up/down buttons to help improve the system

Advanced Features

  • Copy solutions to clipboard using the copy button
  • Share results with the share functionality
  • View metadata including confidence scores and processing time
  • Explore related solutions when multiple results are available

๐Ÿ› ๏ธ API Documentation

The backend provides RESTful APIs accessible at http://localhost:8000/docs (Swagger UI).

Main Endpoints

  • POST /api/search - Submit math questions for solving
  • POST /api/feedback - Submit user feedback on solutions
  • GET /api/health - Health check endpoint

System Configuration

The system uses a three-tier approach for solving math problems:

  1. Knowledge Base Search (Primary): High-confidence semantic search in Qdrant
  2. Web Search via MCP (Secondary): Real-time web search for current information
  3. Gemini LLM (Fallback): Direct AI problem solving when other sources have low confidence

Confidence Thresholds

  • High Confidence: โ‰ฅ 0.8 (Use KB results)
  • Medium Confidence: 0.6-0.79 (Use MCP results)
  • Low Confidence: < 0.6 (Use Gemini LLM)

๐Ÿงช Development

Project Structure

Math-Agentic-RAG/
โ”œโ”€โ”€ backend/               # FastAPI backend
โ”‚   โ”œโ”€โ”€ main.py           # Application entry point
โ”‚   โ”œโ”€โ”€ routes/           # API route handlers
โ”‚   โ”œโ”€โ”€ services/         # Business logic services
โ”‚   โ”œโ”€โ”€ models/           # Pydantic models
โ”‚   โ””โ”€โ”€ requirements.txt  # Python dependencies
โ”œโ”€โ”€ frontend/             # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/   # Reusable components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/        # Page components
โ”‚   โ”‚   โ””โ”€โ”€ utils/        # Utility functions
โ”‚   โ”œโ”€โ”€ public/           # Static assets
โ”‚   โ””โ”€โ”€ package.json      # Node dependencies
โ”œโ”€โ”€ database/             # Database setup and ingestion
โ”‚   โ”œโ”€โ”€ ingest.py         # Data ingestion script
โ”‚   โ”œโ”€โ”€ qdrant_manager.py # Database management
โ”‚   โ””โ”€โ”€ utils.py          # Database utilities
โ””โ”€โ”€ README.md             # This file

๐Ÿ”’ Security & Guardrails

  • Input validation prevents malicious content
  • Output sanitization ensures safe responses
  • Rate limiting prevents abuse
  • API key protection secures external services

๐Ÿค Acknowledgments

  • Qdrant for vector database capabilities
  • Google Gemini for advanced language modeling
  • KaTeX for beautiful mathematical rendering
  • FastAPI for high-performance backend framework
  • React for modern frontend development

Built with โค๏ธ by bhoomi