bhoomika19 commited on
Commit
0388791
ยท
1 Parent(s): 876ced4

added readme

Browse files
Files changed (1) hide show
  1. README.md +309 -1
README.md CHANGED
@@ -1 +1,309 @@
1
- # Math-Agentic-RAG
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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**