This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A RAG (Retrieval-Augmented Generation) chatbot that answers questions about course materials. Users interact via a web chat UI; the backend uses ChromaDB for vector search and Anthropic's Claude API (with tool use) to generate answers.
cd backend && uv run uvicorn app:app --reload --port 8000Or use ./run.sh from the project root. The app serves at http://localhost:8000.
uv syncA .env file in the project root must contain ANTHROPIC_API_KEY=<key>. Loaded by python-dotenv in backend/config.py.
- Frontend (
frontend/script.js) POSTs{ query, session_id }to/api/query backend/app.pyFastAPI handler delegates toRAGSystem.query()RAGSystem(orchestrator) wraps the query, retrieves session history, and callsAIGenerator.generate_response()with asearch_course_contenttool definition- Claude decides whether to answer directly or call the search tool
- If tool is called:
CourseSearchTool→VectorStore.search()→ ChromaDB semantic search → results sent back to Claude in a second API call (without tools) for synthesis - Response + sources returned to frontend, rendered as markdown
backend/rag_system.py— Central orchestrator wiring all components togetherbackend/ai_generator.py— Anthropic API client; handles the two-call tool-use pattern (initial call with tools → tool execution → follow-up call without tools)backend/vector_store.py— ChromaDB wrapper with two collections:course_catalog(metadata, used for fuzzy course name resolution) andcourse_content(chunked text for search)backend/search_tools.py— AbstractToolbase class +CourseSearchTool+ToolManager; tools are registered and exposed to Claude as callable functionsbackend/document_processor.py— Parses course files (expected format: header lines for title/link/instructor, thenLesson N:markers), chunks text by sentence boundaries with overlapbackend/session_manager.py— In-memory per-session conversation history (max 2 exchanges), formatted as plain text for the system promptbackend/config.py— Dataclass with all settings (model, chunk size, embedding model, etc.)
Course text files in docs/ follow this structure:
Course Title: <title>
Course Link: <url>
Course Instructor: <name>
Lesson 0: <title>
Lesson Link: <url>
<content...>
Lesson 1: <title>
<content...>
On startup (app.py startup event), all .txt/.pdf/.docx files in docs/ are processed, chunked, embedded with all-MiniLM-L6-v2, and stored in ChromaDB (persisted at ./chroma_db). Existing courses are skipped by title.
Static HTML/CSS/JS served by FastAPI's StaticFiles mount. Uses marked.js for markdown rendering. No build step required.
- Python 3.13+, managed with uv
- FastAPI + uvicorn — web server
- ChromaDB — vector database (persistent, stored in
backend/chroma_db/) - sentence-transformers (
all-MiniLM-L6-v2) — embedding model - Anthropic SDK — Claude API with tool use (model:
claude-sonnet-4-20250514)
- Always use
uvfor package management, neverpip. Useuv addto add dependencies anduv syncto install. - Always use
uv runto execute Python files (e.g.,uv run python script.py), never barepython.
- All backend imports use bare module names (e.g.,
from config import config), so the server must be started from thebackend/directory - The tool system uses an abstract base class (
Tool) withget_tool_definition()andexecute()— new tools should follow this pattern and be registered withToolManager - Vector search supports optional
course_name(fuzzy-matched via catalog) andlesson_numberfilters