How smil7/ai-teaching-assistant works
Project Type and Purpose
• This is a full-stack application with two main parts: a backend that implements a Retrieval-Augmented Generation (RAG) pipeline to serve context-aware AI responses, and a frontend web interface (built with React) for interactive user access.
• The application is designed to assist students by answering course-related questions. It ingests course documents (PDFs, CSVs, etc.) into a vector database (Chroma) and uses lightweight embedding models (all-MiniLM-L6-v2) along with a quantized Llama-2-7b-Chat-GGUF model to generate answers grounded in course material.
Analyzing the File Structure
• There are two main directories:
a. "Backend-RAG" – Contains backend modules, scripts, and utility functions. Key files include:
• ingest.py – For processing and ingesting course material into Chroma.
• load_models.py, prompt_template_utils.py, crawl.py, constants.py – Supporting modules for model loading and query handling.
• run_localGPT.py, run_localGPT_API.py, localGPT_UI.py – Entry points for running the system as a command-line tool, API service, or local UI.
• Dockerfile and related configuration files – For containerizing the application.
• SOURCE_DOCUMENTS – Where raw course materials and PDF assignments are stored.
b. "ai-teaching-assistant" – Contains the frontend code (React project) as well as a backend folder mirroring some functionalities (likely to support the API endpoints and serve the front-end).
• In the src/backend folder, you have server.py (likely the API server linking frontend to backend services), ingestion-related modules, and utility scripts.
• In the src/frontend folder, you have components (ChatbotInterface, WelcomePage, FormPage) and styles for rendering the UI.
Main Components and Their Roles
a. Ingestion Module:
• Responsible for processing course documents by splitting them into chunks, embedding these using the all-MiniLM-L6-v2 model, and storing them in the Chroma vector database.
• Files: ingest.py, and similar ingestion code under ai-teaching-assistant/src/backend/ingest_class.py.
b. Retrieval Component:
• Processes user queries by converting them into embeddings and retrieving the most relevant document chunks from the vector database.
• Files: Prompt/template utilities, qa_retrieval_class.py.
c. Generation Component:
• Uses the Llama-2-7b-Chat-GGUF model to generate context-aware responses based on the retrieved document chunks.
• Files: load_models.py, run_localGPT.py, run_localGPT_API.py.
d. API / Command-line Interface:
• Provides endpoints or a terminal-based interface for client interaction.
• File: server.py (in the frontend's backend submodule) and localGPT_UI.py for local interactive sessions.
e. Frontend UI:
• A React-based web application serving as the interactive interface for end-users.
• Files: Located under ai-teaching-assistant/src/frontend, including ChatbotInterface.js, FormPage.js, and WelcomePage.js.
f. Storage and Data:
• Course documents in the "SOURCE_DOCUMENTS" folder (both in the Backend-RAG and the ai-teaching-assistant/src/backend folders).
• A Chroma vector database (conceptually represented) acting as the intermediary data store for embeddings.
Relationships and Data Flow
• User initiates a query via the frontend UI.
• The query is sent to the backend server (server.py or one of the run_*.py entry points) through an API call.
• The query is embedded and used to query the Chroma vector database, which holds document embeddings generated from the course materials (using ingest.py).
• The retrieved relevant document chunks are then fed into the generation module (Llama-2-7b-Chat-GGUF) to produce the final response.
• The generated answer is sent back to the frontend and displayed in the chatbot interface.
• Additionally, there is a data ingestion pipeline that is typically run as a preprocessing step to prepare the Chroma DB from SOURCE_DOCUMENTS.
Architectural Patterns and Technologies
• MVC/MVVM pattern: The separation of concerns between the frontend (view and controller layers) and the backend (model and business logic).
• Microservice-like separation: Although contained within one repository, there is a clear separation between backend processing (ingest, retrieval, generation) and frontend UI.
• Use of containerization: Dockerfiles are present to build standardized runtime environments.
• Key Libraries & Frameworks:
• langchain for chaining generative processes.
• transformers and llama-cpp-python for model inference.
• pytorch for model execution.
• chromadb as the vector database.
• React for the frontend UI.
• Others: click, nltk, sentence-transformers, etc.