This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Retrieval-Augmented Generation (RAG) system for course materials that enables users to query educational content and receive AI-powered responses. The system uses ChromaDB for vector storage, Anthropic's Claude for AI generation, and provides a web interface for interaction.
Quick Start (Recommended):
chmod +x run.sh
./run.shManual Start:
cd backend
uv run uvicorn app:app --reload --port 8000The application will be available at:
- Web Interface:
http://localhost:8000 - API Documentation:
http://localhost:8000/docs
-
Install dependencies:
uv sync
-
Set up environment variables:
cp .env.example .env # Edit .env and add your ANTHROPIC_API_KEY
- Python package management: Uses
uvinstead of pip - Python version: Requires Python 3.13 or higher
- Live reload: Enabled with
--reloadflag during development
The RAG system follows a modular architecture with clear separation of concerns:
Backend Layer (backend/):
app.py- FastAPI web server and API endpointsrag_system.py- Main orchestrator coordinating all componentsdocument_processor.py- Handles parsing and chunking of course documentsvector_store.py- ChromaDB integration for semantic searchai_generator.py- Claude API integration with tool callingsearch_tools.py- Tool system for intelligent course content searchingsession_manager.py- Conversation history and session management
Frontend Layer (frontend/):
- Vanilla JavaScript web interface
- Real-time chat interface with loading states
- Source attribution display
Data Layer:
docs/- Course materials in structured text formatchroma_db/- Vector database storage (auto-created)
RAG Flow:
- User query → FastAPI endpoint
- RAG system constructs prompt with conversation history
- Claude AI determines if course content search is needed
- If needed: Vector search → Formatted results → Claude generates response
- Response + sources returned to frontend
Document Processing Pipeline:
- Documents follow structured format: Course metadata → Lesson markers → Content
- Smart chunking with overlap for context preservation
- Context enrichment: Each chunk gets course/lesson metadata
Tool System:
- Claude can call
search_course_contenttool with filters (course name, lesson number) - Tools managed through
ToolManagerwith source tracking - Enables intelligent, context-aware course content retrieval
Session Management:
- Stateless API with session IDs for conversation continuity
- Limited history (2 rounds) to manage context window
- Automatic session creation on first interaction
Course documents must follow this structure:
Course Title: [title]
Course Link: [url] (optional)
Course Instructor: [name] (optional)
Lesson 0: [lesson title]
Lesson Link: [url] (optional)
[lesson content...]
Lesson 1: [next lesson title]
[lesson content...]
Key settings in backend/config.py:
CHUNK_SIZE: 800- Text chunk size for vector storageCHUNK_OVERLAP: 100- Overlap between chunks for contextMAX_RESULTS: 5- Search results limitMAX_HISTORY: 2- Conversation rounds to rememberANTHROPIC_MODEL: "claude-sonnet-4-20250514"- AI model version
POST /api/query- Main chat endpoint with session managementGET /api/courses- Course statistics and available titlesGET /docs- Interactive API documentation (Swagger UI)
Tool Calling Integration:
- The system uses Anthropic's tool calling feature for intelligent search
- Search results are automatically tracked for source attribution
- Tools are designed to be stateless and composable
Vector Search Strategy:
- Semantic search with metadata filtering capabilities
- Supports course name partial matching and lesson-specific filtering
- Results include context headers for better AI understanding
Error Handling:
- Graceful degradation when documents are missing
- Input validation with helpful error messages
- Frontend loading states for better UX
Development Considerations:
- No test suite currently implemented
- Uses SQLite-backed ChromaDB for development
- Frontend uses marked.js for Markdown rendering