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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Math Agentic RAG - Intelligent Math Problem Solver
|
2 |
+
|
3 |
+
> 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.
|
4 |
+
|
5 |
+
## ๐ฏ Overview
|
6 |
+
|
7 |
+
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.
|
8 |
+
|
9 |
+
### Key Features
|
10 |
+
|
11 |
+
- **๐ง Multi-Source Intelligence**: Combines knowledge base, web search, and Gemini LLM for optimal results
|
12 |
+
- **๐ Step-by-Step Solutions**: Detailed explanations with mathematical reasoning
|
13 |
+
- **โก Intelligent Routing**: Automatically selects the best source based on confidence scores
|
14 |
+
- **๐จ Beautiful Math Rendering**: LaTeX-powered mathematical notation with KaTeX
|
15 |
+
- **๐ Analytics & Feedback**: Built-in performance tracking and user feedback system
|
16 |
+
- **๐ Input Validation**: Guardrails for safe and appropriate content
|
17 |
+
- **๐ Real-time Processing**: Fast response times with optimized caching
|
18 |
+
|
19 |
+
## ๐๏ธ Architecture
|
20 |
+
|
21 |
+
```
|
22 |
+
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
23 |
+
โ Frontend โ โ Backend โ โ External โ
|
24 |
+
โ (React) โโโโโบโ (FastAPI) โโโโโบโ Services โ
|
25 |
+
โ โ โ โ โ โ
|
26 |
+
โ โข Search UI โ โ โข API Routes โ โ โข Qdrant DB โ
|
27 |
+
โ โข Math Render โ โ โข Services โ โ โข Gemini LLM โ
|
28 |
+
โ โข KaTeX Display โ โ โข Guardrails โ โ โข MCP Service โ
|
29 |
+
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
30 |
+
```
|
31 |
+
|
32 |
+
### Technology Stack
|
33 |
+
|
34 |
+
**Frontend:**
|
35 |
+
- React 18 with modern hooks
|
36 |
+
- Tailwind CSS for styling
|
37 |
+
- KaTeX for mathematical rendering
|
38 |
+
- React Hot Toast for notifications
|
39 |
+
|
40 |
+
**Backend:**
|
41 |
+
- FastAPI for high-performance APIs
|
42 |
+
- Pydantic for data validation
|
43 |
+
- Structlog for comprehensive logging
|
44 |
+
- Python 3.11+
|
45 |
+
|
46 |
+
**AI & Data:**
|
47 |
+
- Qdrant vector database for semantic search
|
48 |
+
- Google Gemini 2.0 Flash for LLM processing
|
49 |
+
- Model Context Protocol (MCP) for web search
|
50 |
+
- Sentence Transformers for embeddings
|
51 |
+
|
52 |
+
## ๐ Quick Start
|
53 |
+
|
54 |
+
### Prerequisites
|
55 |
+
|
56 |
+
- Python 3.11 or higher
|
57 |
+
- Node.js 18+ and npm
|
58 |
+
- Git
|
59 |
+
|
60 |
+
### Environment Setup
|
61 |
+
|
62 |
+
1. **Clone the repository:**
|
63 |
+
```bash
|
64 |
+
git clone https://github.com/bhoomika-254/Math-Agentic-RAG.git
|
65 |
+
cd Math-Agentic-RAG
|
66 |
+
```
|
67 |
+
|
68 |
+
2. **Set up environment variables:**
|
69 |
+
```bash
|
70 |
+
# Create .env file in the root directory
|
71 |
+
touch .env
|
72 |
+
```
|
73 |
+
|
74 |
+
Add the following variables to your `.env` file:
|
75 |
+
```env
|
76 |
+
# Required API Keys
|
77 |
+
GEMINI_API_KEY=your_gemini_api_key_here
|
78 |
+
QDRANT_URL=your_qdrant_cluster_url
|
79 |
+
QDRANT_API_KEY=your_qdrant_api_key
|
80 |
+
|
81 |
+
# Optional configurations
|
82 |
+
BACKEND_PORT=8000
|
83 |
+
FRONTEND_PORT=3000
|
84 |
+
LOG_LEVEL=INFO
|
85 |
+
```
|
86 |
+
|
87 |
+
### Backend Setup
|
88 |
+
|
89 |
+
1. **Navigate to backend directory:**
|
90 |
+
```bash
|
91 |
+
cd backend
|
92 |
+
```
|
93 |
+
|
94 |
+
2. **Create and activate virtual environment:**
|
95 |
+
```bash
|
96 |
+
python -m venv venv
|
97 |
+
|
98 |
+
# On Windows:
|
99 |
+
venv\Scripts\activate
|
100 |
+
# On macOS/Linux:
|
101 |
+
source venv/bin/activate
|
102 |
+
```
|
103 |
+
|
104 |
+
3. **Install dependencies:**
|
105 |
+
```bash
|
106 |
+
pip install -r requirements.txt
|
107 |
+
```
|
108 |
+
|
109 |
+
4. **Start the backend server:**
|
110 |
+
```bash
|
111 |
+
python main.py
|
112 |
+
```
|
113 |
+
The backend will be available at `http://localhost:8000`
|
114 |
+
|
115 |
+
### Frontend Setup
|
116 |
+
|
117 |
+
1. **Navigate to frontend directory (in a new terminal):**
|
118 |
+
```bash
|
119 |
+
cd frontend
|
120 |
+
```
|
121 |
+
|
122 |
+
2. **Install dependencies:**
|
123 |
+
```bash
|
124 |
+
npm install
|
125 |
+
```
|
126 |
+
|
127 |
+
3. **Start the development server:**
|
128 |
+
```bash
|
129 |
+
npm start
|
130 |
+
```
|
131 |
+
The frontend will be available at `http://localhost:3000`
|
132 |
+
|
133 |
+
### Database Setup
|
134 |
+
|
135 |
+
1. **Navigate to database directory:**
|
136 |
+
```bash
|
137 |
+
cd database
|
138 |
+
```
|
139 |
+
|
140 |
+
2. **Install dependencies:**
|
141 |
+
```bash
|
142 |
+
pip install -r requirements.txt
|
143 |
+
```
|
144 |
+
|
145 |
+
3. **Ingest sample math data:**
|
146 |
+
```bash
|
147 |
+
python ingest.py
|
148 |
+
```
|
149 |
+
|
150 |
+
## ๐ Usage Guide
|
151 |
+
|
152 |
+
### Basic Usage
|
153 |
+
|
154 |
+
1. **Open the application** in your browser at `http://localhost:3000`
|
155 |
+
|
156 |
+
2. **Enter a math question** in the search box, such as:
|
157 |
+
- "Find the derivative of f(x) = 3xยฒ + 2x - 1"
|
158 |
+
- "Solve the quadratic equation: xยฒ + 5x + 6 = 0"
|
159 |
+
- "What is the integral of sin(x) dx?"
|
160 |
+
|
161 |
+
3. **View the solution** with step-by-step explanations and beautiful mathematical notation
|
162 |
+
|
163 |
+
4. **Provide feedback** using the thumbs up/down buttons to help improve the system
|
164 |
+
|
165 |
+
### Advanced Features
|
166 |
+
|
167 |
+
- **Copy solutions** to clipboard using the copy button
|
168 |
+
- **Share results** with the share functionality
|
169 |
+
- **View metadata** including confidence scores and processing time
|
170 |
+
- **Explore related solutions** when multiple results are available
|
171 |
+
|
172 |
+
## ๐ ๏ฟฝ๏ฟฝ API Documentation
|
173 |
+
|
174 |
+
The backend provides RESTful APIs accessible at `http://localhost:8000/docs` (Swagger UI).
|
175 |
+
|
176 |
+
### Main Endpoints
|
177 |
+
|
178 |
+
- `POST /api/search` - Submit math questions for solving
|
179 |
+
- `POST /api/feedback` - Submit user feedback on solutions
|
180 |
+
- `GET /api/health` - Health check endpoint
|
181 |
+
|
182 |
+
### Example API Usage
|
183 |
+
|
184 |
+
```bash
|
185 |
+
curl -X POST "http://localhost:8000/api/search" \
|
186 |
+
-H "Content-Type: application/json" \
|
187 |
+
-d '{"question": "Find the derivative of f(x) = 3x^2 + 2x - 1"}'
|
188 |
+
```
|
189 |
+
|
190 |
+
## ๐ง Configuration
|
191 |
+
|
192 |
+
### System Configuration
|
193 |
+
|
194 |
+
The system uses a three-tier approach for solving math problems:
|
195 |
+
|
196 |
+
1. **Knowledge Base Search** (Primary): High-confidence semantic search in Qdrant
|
197 |
+
2. **Web Search via MCP** (Secondary): Real-time web search for current information
|
198 |
+
3. **Gemini LLM** (Fallback): Direct AI problem solving when other sources have low confidence
|
199 |
+
|
200 |
+
### Confidence Thresholds
|
201 |
+
|
202 |
+
- High Confidence: โฅ 0.8 (Use KB results)
|
203 |
+
- Medium Confidence: 0.6-0.79 (Use MCP results)
|
204 |
+
- Low Confidence: < 0.6 (Use Gemini LLM)
|
205 |
+
|
206 |
+
## ๐งช Development
|
207 |
+
|
208 |
+
### Project Structure
|
209 |
+
|
210 |
+
```
|
211 |
+
Math-Agentic-RAG/
|
212 |
+
โโโ backend/ # FastAPI backend
|
213 |
+
โ โโโ main.py # Application entry point
|
214 |
+
โ โโโ routes/ # API route handlers
|
215 |
+
โ โโโ services/ # Business logic services
|
216 |
+
โ โโโ models/ # Pydantic models
|
217 |
+
โ โโโ requirements.txt # Python dependencies
|
218 |
+
โโโ frontend/ # React frontend
|
219 |
+
โ โโโ src/
|
220 |
+
โ โ โโโ components/ # Reusable components
|
221 |
+
โ โ โโโ pages/ # Page components
|
222 |
+
โ โ โโโ utils/ # Utility functions
|
223 |
+
โ โโโ public/ # Static assets
|
224 |
+
โ โโโ package.json # Node dependencies
|
225 |
+
โโโ database/ # Database setup and ingestion
|
226 |
+
โ โโโ ingest.py # Data ingestion script
|
227 |
+
โ โโโ qdrant_manager.py # Database management
|
228 |
+
โ โโโ utils.py # Database utilities
|
229 |
+
โโโ README.md # This file
|
230 |
+
```
|
231 |
+
|
232 |
+
### Running Tests
|
233 |
+
|
234 |
+
```bash
|
235 |
+
# Backend tests
|
236 |
+
cd backend
|
237 |
+
python -m pytest
|
238 |
+
|
239 |
+
# Frontend tests
|
240 |
+
cd frontend
|
241 |
+
npm test
|
242 |
+
```
|
243 |
+
|
244 |
+
### Contributing
|
245 |
+
|
246 |
+
1. Fork the repository
|
247 |
+
2. Create a feature branch: `git checkout -b feature-name`
|
248 |
+
3. Make your changes with proper tests
|
249 |
+
4. Commit your changes: `git commit -am 'Add feature'`
|
250 |
+
5. Push to the branch: `git push origin feature-name`
|
251 |
+
6. Submit a pull request
|
252 |
+
|
253 |
+
## ๐ Performance & Analytics
|
254 |
+
|
255 |
+
The system includes comprehensive analytics:
|
256 |
+
|
257 |
+
- **Response time tracking**
|
258 |
+
- **Confidence score monitoring**
|
259 |
+
- **Source usage statistics**
|
260 |
+
- **User feedback collection**
|
261 |
+
- **Quality assessment metrics**
|
262 |
+
|
263 |
+
## ๐ Security & Guardrails
|
264 |
+
|
265 |
+
- **Input validation** prevents malicious content
|
266 |
+
- **Output sanitization** ensures safe responses
|
267 |
+
- **Rate limiting** prevents abuse
|
268 |
+
- **API key protection** secures external services
|
269 |
+
|
270 |
+
## ๐ Troubleshooting
|
271 |
+
|
272 |
+
### Common Issues
|
273 |
+
|
274 |
+
**Backend won't start:**
|
275 |
+
- Check that all environment variables are set
|
276 |
+
- Verify Python version (3.11+)
|
277 |
+
- Ensure virtual environment is activated
|
278 |
+
|
279 |
+
**Frontend math not rendering:**
|
280 |
+
- Check browser console for KaTeX errors
|
281 |
+
- Verify mathematical expressions are properly formatted
|
282 |
+
- Clear browser cache
|
283 |
+
|
284 |
+
**No search results:**
|
285 |
+
- Verify Qdrant connection in backend logs
|
286 |
+
- Check if database has been ingested with sample data
|
287 |
+
- Confirm API keys are valid
|
288 |
+
|
289 |
+
### Getting Help
|
290 |
+
|
291 |
+
- Check the [Issues](https://github.com/bhoomika-254/Math-Agentic-RAG/issues) page
|
292 |
+
- Review the API documentation at `/docs`
|
293 |
+
- Check backend logs for detailed error information
|
294 |
+
|
295 |
+
## ๐ License
|
296 |
+
|
297 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
298 |
+
|
299 |
+
## ๐ค Acknowledgments
|
300 |
+
|
301 |
+
- **Qdrant** for vector database capabilities
|
302 |
+
- **Google Gemini** for advanced language modeling
|
303 |
+
- **KaTeX** for beautiful mathematical rendering
|
304 |
+
- **FastAPI** for high-performance backend framework
|
305 |
+
- **React** for modern frontend development
|
306 |
+
|
307 |
+
---
|
308 |
+
|
309 |
+
**Built with โค๏ธ for the mathematics education community**
|