Spaces:
Sleeping
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
- Clone the repository:
git clone https://github.com/bhoomika-254/Math-Agentic-RAG.git
cd Math-Agentic-RAG
- 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
- Navigate to backend directory:
cd backend
- Create and activate virtual environment:
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Start the backend server:
python main.py
The backend will be available at http://localhost:8000
Frontend Setup
- Navigate to frontend directory (in a new terminal):
cd frontend
- Install dependencies:
npm install
- Start the development server:
npm start
The frontend will be available at http://localhost:3000
Database Setup
- Navigate to database directory:
cd database
- Install dependencies:
pip install -r requirements.txt
- Ingest sample math data:
python ingest.py
๐ Usage Guide
Basic Usage
Open the application in your browser at
http://localhost:3000
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?"
View the solution with step-by-step explanations and beautiful mathematical notation
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 solvingPOST /api/feedback
- Submit user feedback on solutionsGET /api/health
- Health check endpoint
System Configuration
The system uses a three-tier approach for solving math problems:
- Knowledge Base Search (Primary): High-confidence semantic search in Qdrant
- Web Search via MCP (Secondary): Real-time web search for current information
- 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