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-tutor
npm install
# start postgresql and build/run the embeddings service
docker-compose up -d
# verify the embeddings service is running
curl http://localhost:8000/health
The 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.js
Start the development server:
npm run dev
The 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_name
To 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