StudyFetch AI Tutor is a web application that helps students understand PDF documents through an interactive split-screen interface. Users can upload PDFs and chat with an AI about the document's content, with the AI able to reference and highlight relevant parts of the PDF in real-time.
- π User Authentication: Secure email/password signup and login with session management
- π PDF Upload & Viewing: Upload, store, and navigate PDF documents
- π¬ AI Chat Interface: Interact with the AI about document content via text
- π Smart Document Search: Vector embeddings power semantic retrieval of relevant document content
- π Context-Aware Responses: AI references specific page numbers and content from the PDF
- π Persistent Conversations: Chat history is saved and can be resumed later
- π Multi-Document Support: Upload and manage multiple documents with separate conversation histories
- Next.js 15+ with App Router
- React 19
- TailwindCSS for styling
- React PDF for PDF rendering
- Next.js API Routes
- PostgreSQL with pgvector extension for vector similarity search
- Prisma ORM for database operations
- AWS S3 for PDF storage
- OpenAI GPT-4 for chat responses
- Custom Embeddings Service using sentence-transformers
- LangChain for document processing
Image credit: https://www.dailydoseofds.com/
The application follows a Retrieval Augmented Generation (RAG) approach:
- PDF documents are processed into chunks
- Each chunk gets a vector embedding representing its semantic meaning
- When the user asks a question, relevant chunks are retrieved via similarity search
- The AI generates a response based on the retrieved context
- Web Application: Next.js app for frontend and API routes
- Embeddings Service: FastAPI service for document processing and embedding generation
- PostgreSQL Database: Stores user data, documents, conversations, and vector embeddings
- Node.js v18+
- Docker and Docker Compose
- OpenAI API key
- AWS S3 credentials (for production deployment)
git clone https://github.com/CruiseDevice/ai-tutor
cd ai-tutornpm install# start postgresql and build/run the embeddings service
docker-compose up -d
# verify the embeddings service is running
curl http://localhost:8000/healthThe embeddings service runs in a Docker container and exposes the following endpoints:
GET /health: Check if the service is runningPOST /embeddings: Generate embeddings for a single textPOST /batch-embeddings: Generate embeddings for multiple textsPOST /process-document: Process a PDF document into chunks with embeddings
Create a .env file in the root directory:
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/studyfetch"
# S3 Storage
AWS_REGION="us-east-1"
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
S3_PDFBUCKET_NAME="your-bucket-name"
# Embeddings Service
EMBEDDINGS_SERVICE_URL="http://localhost:8000"
# Environment
NODE_ENV="development"npx prisma generate
npx prisma db push
node scripts/setup-pgvector.jsStart the development server:
npm run devThe application will be available at http://localhost:3000
- Register/Login: Create an account or sign in
- API Setup: Navigate to API Settings and add your OpenAI API key
- Upload a PDF: On the dashboard, click "Upload PDF" to begin
- Chat with the Document: Ask questions about the PDF content
- Document History: Access previous documents from the sidebar
/
βββ embeddings/ # Embeddings service (FastAPI)
β βββ document_processor.py # PDF processing logic
β βββ embeddings_service.py # API endpoints
βββ prisma/ # Database schema and migrations
βββ public/ # Static assets
βββ scripts/ # Setup scripts
βββ src/
β βββ app/ # Next.js app directory
β β βββ api/ # API routes
β β βββ dashboard/ # Dashboard page
β β βββ login/ # Login page
β β βββ register/ # Registration page
β βββ components/ # React components
β β βββ ChatInterface.tsx # Chat UI
β β βββ Dashboard.tsx # Main application component
β β βββ EnhancedPDFViewer.tsx # PDF viewer with annotation
β βββ lib/ # Utility libraries
β βββ auth.ts # Authentication utilities
β βββ db.ts # Database client
β βββ pgvector.ts # Vector search functions
βββ docker-compose.yml # Docker services configuration
/api/auth/*: Authentication endpoints (login, register, logout)/api/documents: PDF upload and processing/api/conversations: Conversation management/api/chat: AI messaging endpoint
After schema changes:
npx prisma migrate dev --name your_migration_nameTo change the embeddings model, update the model name in:
/embeddings/document_processor.py/embeddings/embeddings_service.py
The application can be deployed on Vercel with the following considerations:
- Set up a PostgreSQL database with pgvector extension (e.g., using Supabase or Neon)
- Deploy the embeddings service separately (e.g., on a server or containerized service)
- Configure environment variables in your hosting platform
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- OpenAI for the GPT API
- Sentence Transformers for embeddings
- LangChain for document processing utilities
- Vercel for Next.js hosting infrastructure