Skip to content
B

Loading experience

CapstoneSJSU · DATA 298B Capstone · 2026

Professor in a Box: Personalized CS Tutoring via Fine-Tuned LLMs and Retrieval-Augmented Generation

Basanth Periyapatna Roopa Kumar, SJSU MSDA Team 2

San Jose State University — DATA 298B Capstone · Master of Data Science · Spring 2026

Abstract

Professor in a Box (PiAB) is a production-grade AI tutoring system that addresses two fundamental limitations of off-the-shelf large language models in educational settings: weak performance on low-frequency computer science sub-domains and hallucination on student-specific study material. The system fine-tunes open-weight 7B-parameter models using QLoRA and serves them via a real-time retrieval-augmented generation pipeline that dynamically injects student-uploaded document context into every inference call.

Students interact through a React dashboard that streams token-by-token responses from LoRA-adapted Mistral-7B and DeepSeek-R1-7B models running on serverless NVIDIA A10G GPUs via Modal. When fine-tuned inference is unavailable, a three-tier fallback chain (OpenAI, DeepSeek, Gemini) maintains uptime transparently. The backend orchestrates JWT-authenticated file ingestion through LlamaCloud, semantic chunking, dense embedding via Gemini text-embedding-004, and ChromaDB retrieval all within a single Node.js API gateway.

Fine-tuning domain-adapted LoRA adapters on curated CS Q&A corpora combined with per-user RAG memory reduces hallucination on personal study material and shifts LLM behavior from generic text completion toward grounded, pedagogically consistent tutoring.

Fine-Tuned Models

2

LoRA Rank

16

VRAM Footprint

~4 GB

RAG Chunk Size

800 chars

Retrieval Top-K

5

Fallback Providers

3

System Architecture

End-to-End System Architecture — Professor in a Box

React + Vite Frontend

Dashboard · Learning Path · AI Chat · Quiz Generator

Node.js + Express API Gateway

JWT Auth · Rate Limiting · SSE Streaming · Provider Fallback Chain

Persistence

SQLite + Prisma ORM

Users · Chat history · Learning paths

Semantic Memory

ChromaDB Vector Store

Per-user namespace · Gemini text-embedding-004

LlamaCloud (LlamaParse)

Multi-modal PDF/image OCR → Markdown chunks

Fine-Tuned Inference

Modal Serverless A10G

24 GB VRAM · min_containers=0

Mistral-7B-Instruct-v0.3

LoRA rank-16 · BasanthPR/mistral7b-cs-tutor

DeepSeek-R1-Distill-Qwen-7B

LoRA rank-16 · BasanthPR/deepseek-r1-7b-cs-tutor

Cloud AI Fallback Chain (auto-triggered on 401 / 429 / 402)

OpenAI gpt-4o-mini

Primary fallback

DeepSeek-chat

Secondary fallback

Gemini 2.0 Flash

Tertiary fallback

Research Context and Motivation

Large language models achieve strong average-case performance across general benchmarks but exhibit systematic degradation on low-frequency CS sub-domains such as competitive programming and advanced algorithms. They also hallucinate when queried about student-specific materials that fall outside the training distribution. PiAB addresses both failure modes with two complementary techniques that operate at different stages of the inference pipeline.

Supervised fine-tuning with LoRA adapts model behavior at training time by exposing the network to curated CS tutoring-style Q&A pairs. This shifts the base distribution toward pedagogically grounded responses and improves accuracy on domain-specific questions. Retrieval-augmented generation operates at inference time by fetching the most semantically relevant passages from a student's own uploaded notes and injecting them as grounded context, directly counteracting hallucination on personal study material.

Models and Fine-Tuning

Fine-Tuned Model Registry

ModelBaseAdapterHuggingFace Hub
Mistral CS TutorMistral-7B-Instruct-v0.3LoRA rank-16BasanthPR/mistral7b-cs-tutor
DeepSeek-R1 CS TutorDeepSeek-R1-Distill-Qwen-7BLoRA rank-16BasanthPR/deepseek-r1-7b-cs-tutor

LLM Fine-Tuning Pipeline — QLoRA on A100

Data Pipeline (Apache Airflow ETL)

LeetCode Problems

Competitive programming corpus

Codeforces Editorials

Algorithmic reasoning explanations

APPS Dataset

Interview-style problem solving

CS Textbook Chapters

Foundational curriculum content

Deduplication + Prompt Formatting

Instruction-tuning template · train/val splits

Hugging Face Parquet Upload

Versioned training dataset

QLoRA Training (Google Colab A100)

Base Model Load

Mistral-7B-Instruct-v0.3 / DeepSeek-R1-Distill-Qwen-7B

4-bit NF4 Quantization

BitsAndBytes · double quant · 14 GB → ~4 GB VRAM

PEFT LoRA Adapter

rank-16 · alpha-32 · target: q_proj, v_proj

Supervised Fine-Tuning

CS Q&A instruction pairs · cross-entropy loss

Adapter Push to HuggingFace Hub

BasanthPR/mistral7b-cs-tutor · deepseek-r1-7b-cs-tutor

QLoRA Training Configuration

Both models were quantized to 4-bit NF4 precision using BitsAndBytes with double quantization enabled, reducing each 14 GB model to approximately 4 GB VRAM. PEFT LoRA adapters were applied to the query and value projection matrices with rank 16, targeting the instruction-following heads most responsible for response style. The training data consists of multi-source CS Q&A pairs: LeetCode problems, Codeforces editorial-style explanations, the APPS dataset, and CS textbook chapter excerpts. An Apache Airflow ETL pipeline (Astronomer runtime) orchestrated raw ingestion from Hugging Face Hub, schema normalization, deduplication, and prompt formatting into the instruction-tuning template before uploading versioned Parquet files to the training bucket.

Inference Configuration (Modal Serverless)

Fine-tuned adapters are loaded onto NVIDIA A10G GPUs (24 GB VRAM) via Modal serverless functions with min_containers=0, eliminating GPU cost when idle. The batch endpoint (POST /ask) awaits full generation and returns JSON; the streaming endpoint (POST /ask-stream) emits SSE tokens as data: chunks for real-time display. Cold starts take approximately 60 to 90 seconds as weights load from Modal Volume cache. Warm requests complete in 5 to 15 seconds depending on response length. API keys for cloud providers are stored as Modal Secrets and fetched by the backend at runtime, removing secrets from source code and environment variables entirely.

RAG Pipeline

RAG Pipeline — Document Ingestion to Grounded Generation

Student Upload (PDF / Image)

Authenticated via JWT · POST /api/uploads

LlamaCloud (LlamaParse)

Multi-modal OCR · Markdown extraction

Semantic Chunking

~800-char chunks · 100-char overlap

Gemini text-embedding-004

Dense vector representation

ChromaDB (per-user namespace)

Keyed by userId · persistent vector store

Top-5 Nearest-Neighbor Retrieval

Cosine similarity · question embedded at query time

Structured Prompt Injection

Context + question → LLM with direct citations

SSE Token Stream

POST /api/ai/stream-rag · chunked response to client

Document Ingestion

Students upload study materials (PDFs or images) through an authenticated file upload endpoint. LlamaCloud (LlamaParse) handles multi-modal OCR, converting scanned PDFs and handwritten notes into structured Markdown. The extracted text is split into 800-character semantic chunks with 100-character overlap to preserve cross-sentence context at boundaries. Each chunk is encoded using Gemini text-embedding-004, a dense embedding model optimized for retrieval, and stored in a per-user ChromaDB collection keyed by userId. This namespace isolation ensures that every student's document memory remains private and independent.

Retrieval and Grounded Generation

At query time, the student's question is embedded with the same Gemini text-embedding-004 model and matched against their ChromaDB namespace using cosine similarity. The top-5 nearest chunks are retrieved and injected into a structured system prompt alongside the question. The resulting prompt is forwarded to the selected inference provider; the response streams back via SSE with direct citations to the retrieved passages. If the primary provider returns a 401, 429, or 402 status, the gateway automatically retries through OpenAI, DeepSeek, and Gemini in sequence without surfacing an error to the user.

API Design

AI Inference and RAG Endpoints

MethodEndpointAuthDescription
POST/api/ai/generateNoBatch JSON generation for path and quiz content
POST/api/ai/stream-generateNoSSE streaming — plain text response
POST/api/ai/ask-ragJWTBatch RAG answer from user document memory
POST/api/ai/stream-ragJWTStreaming RAG via SSE with context injection
GET/api/ai/warmupNoPre-warm Modal container before demo
GET/api/ai/refreshNoForce-reload API keys from Modal secret store

Supported Inference Providers (provider field in request body)

ProviderModelType
geminiGemini 2.0 FlashCloud API
openaigpt-4o-miniCloud API
deepseekdeepseek-chatCloud API
finetuned-mistralMistral-7B LoRA (A10G)Fine-tuned serverless
finetuned-deepseekDeepSeek-R1-7B LoRA (A10G)Fine-tuned serverless

Deployment Infrastructure

Render — Web Services

The Node.js API gateway and React frontend are deployed on Render via a render.yaml manifest. The backend service runs in a Docker container with a 1 GB persistent disk for SQLite and ChromaDB state. The frontend compiles to a Vite static bundle with SPA rewrite rules. Push to main triggers automatic redeploy from the manifest. GitHub Actions CI builds the Vite bundle and deploys to Render static hosting on every push to main.

Modal — Serverless GPU Inference

Modal provides elastic GPU compute that scales to zero between requests. On first cold start, model weights download from Hugging Face Hub and cache to a Modal Volume (~15 to 20 minutes). Subsequent cold starts load from the volume cache (~60 to 90 seconds). A /warmup endpoint lets demonstrators pre-heat the container roughly 90 seconds before a live demo. All cloud provider API keys are stored in Modal Secrets and fetched by the backend at runtime via a /config endpoint, rotating without requiring a redeploy.

Conclusion

Professor in a Box demonstrates how combining parameter-efficient fine-tuning with retrieval-augmented generation produces a tutoring system that is simultaneously more accurate on domain-specific CS content and more grounded in each student's personal study materials. The serverless deployment model on Modal eliminates idle GPU cost while maintaining sub-15-second warm inference latency, and the three-tier fallback chain ensures continuous availability independent of any single provider.

The system architecture separates concerns cleanly: ETL and data quality live in Airflow, fine-tuning happens offline on cloud GPUs, inference runs on Modal, semantic memory lives in ChromaDB, and the API gateway handles authentication, routing, and fallback logic without coupling any of these layers. This design makes each component independently replaceable as the underlying model landscape evolves.

Tech Stack

Mistral-7B-Instruct-v0.3DeepSeek-R1-Distill-Qwen-7BQLoRAPEFTBitsAndBytes NF4ChromaDBLlamaCloud (LlamaParse)Gemini text-embedding-004RAGModal (A10G)Hugging Face HubOpenAI gpt-4o-miniGemini 2.0 FlashNode.js 20Express 4Prisma ORMSQLiteReact 18ViteTailwind CSSJWT AuthSSE StreamingApache AirflowRenderGitHub Actions