Provides AI-powered tutoring capabilities using GPT-4 for generating personalized learning responses and educational content
ai-tutor
AI Tutoring RAG System - Setup & Testing Guide
๐ Table of Contents
๐ฏ Overview
This is an AI-powered tutoring system that uses RAG (Retrieval-Augmented Generation) to provide personalized learning experiences. The system consists of two main components:
RAG MCP Server (Port 9000) - Provides RAG tools via MCP protocol
MCP Host (Port 8000) - Agent orchestration layer with FastAPI
Key Features:
Personalized knowledge base for each student
PDF and DOCX file processing and indexing
Semantic search across student's learning materials
Intent analysis and risk detection
Azure Blob Storage integration
OpenAI GPT-4 powered responses
๐ง Prerequisites
Before you begin, ensure you have the following installed:
Python 3.13+
uv package manager (Installation guide)
Git
Install uv
Required API Keys
You'll need accounts and API keys for:
OpenAI - Get API Key
Pinecone - Get API Key
Azure Storage - Get Connection String
๐ฟ Installation
1. Create Virtual Environment
2. Install Dependencies
โ๏ธ Configuration
1. Create Environment File
Create a .env file in the project root:
2. Configure Environment Variables
Edit .env and add your credentials:
3. Generate Authentication Token
Generate a JWT token for MCP server authentication:
Copy the generated token and update it in mcp_host/app.py:
๐ Running the Services
You need to run both services in separate terminal windows.
Terminal 1: Start RAG MCP Server
Expected Output:
Terminal 2: Start MCP Host
Expected Output:
Verify Services are Running
Open your browser and check:
MCP Host API Docs: http://localhost:8000/docs
RAG MCP Server: http://localhost:9000/
๐งช Testing the System
Test 1: Create Sample PDF
First, create a sample PDF for testing:
This creates sample.pdf with calculus study content.
Test 2: Upload a File
Use curl to upload a file:
Expected Response:
Test 3: Chat with the Tutor
Send a chat message to query the uploaded content:
Expected Response: The system should retrieve relevant content from the uploaded PDF and provide a personalized response about derivatives.
Test 4: Query Knowledge Base Directly
Test the RAG retrieval directly:
Test 5: View Session History
Get the conversation history:
Test 6: Run Complete Test Workflow
Run the automated test suite:
This will:
Upload a file to Azure
Process and index the file
Query the indexed content
List uploaded files
Test 7: Test File Processing
Test PDF and DOCX processing:
๐ก API Endpoints
MCP Host (Port 8000)
POST /chats/tutor-rag-agent
Start a chat session with the AI tutor.
Request:
Response: Streaming text response
POST /upload-student-file
Upload a PDF or DOCX file for processing.
Form Data:
file: The file to uploadstudent_id: Student identifiersubject: Subject categorytopic: Specific topicdifficulty_level: 1-10
GET /session/{session_id}/history
Get conversation history for a session.
DELETE /session/{session_id}/memory
Clear memory for a specific session.
GET /agent/info
Get information about the agent configuration.
RAG MCP Server (Port 9000)
POST /mcp
MCP protocol endpoint for tool calls.
Available Tools:
knowledge_base_retrieval- Search user's knowledge baseupload_student_file- Process and index uploaded files
๐ Testing with Python
Interactive Testing
Create a Python script test_interactive.py:
Run it:
๐ Troubleshooting
Port Already in Use
Error: Address already in use
Solution:
Pinecone Connection Error
Error: Failed to connect to Pinecone
Solutions:
Verify your
PINECONE_API_KEYis correctCheck your Pinecone index exists
Ensure
PINECONE_ENVIRONMENTmatches your Pinecone region
OpenAI API Error
Error: Incorrect API key provided
Solutions:
Verify your
OPENAI_API_KEYis correctCheck you have credits in your OpenAI account
Ensure the key has the required permissions
Azure Storage Error
Error: Azure Storage connection failed
Solutions:
Verify your
AZURE_STORAGE_CONNECTION_STRINGis correctCheck the storage account exists and is accessible
Ensure the container name matches in
azure_storage.py
MCP Authentication Error
Error: Unauthorized: token verification failed
Solutions:
Generate a new token:
python get_auth_token.pyUpdate the token in
mcp_host/app.pyRestart both servers
Dependencies Not Found
Error: ModuleNotFoundError: No module named 'X'
Solution:
File Processing Fails
Error: Failed to extract text from PDF
Solutions:
Ensure PDF is not password-protected
Check file is not corrupted
Verify PyMuPDF is installed:
uv pip install pymupdf
๐ Monitoring and Logs
View Detailed Logs
Both servers print detailed logs. To save logs:
Check System Health
๐ Example Workflows
Workflow 1: Complete Student Onboarding
Workflow 2: Multi-Subject Learning
๐ Additional Resources
๐ค Support
If you encounter issues:
Check the Troubleshooting section
Review logs from both servers
Ensure all environment variables are set correctly
Verify all prerequisites are installed
๐ Notes
The system uses JWT authentication between services
Files are stored in Azure Blob Storage and indexed in Pinecone
Each student has an isolated knowledge base
Sessions maintain conversation history
The agent autonomously decides when to use RAG tools
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables personalized AI tutoring by allowing students to upload PDF/DOCX study materials that are processed and indexed for semantic search. Provides intelligent responses based on the student's own learning materials using RAG technology.