An educational RAG (Retrieval-Augmented Generation) application that allows students to upload documents and understand how different components (ChromaDB, OpenAI, etc.) interact to provide answers. The system features detailed request/response logging for learning purposes.
- Upload and process PDF, TXT, and Markdown files
- Document chunking and embedding using ChromaDB
- Question answering using configurable OpenAI models (GPT-4, GPT-4-turbo, etc.)
- Interactive web interface with drag-and-drop support
- Source citations in answers
- Detailed system logs showing all interactions between components
- Knowledge base management (view, delete, reset)
- Educational insights into RAG system architecture
- Clone this repository
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile from.env.exampleand configure your settings:
cp .env.example .env
# Edit .env and add:
# - OPENAI_API_KEY: Your OpenAI API key
# - OPENAI_MODEL: Model to use (e.g., gpt-4, gpt-4-1106-preview)- Start the ChromaDB container:
docker-compose up -d- Run the Flask application:
python app.py- Open your browser and visit
http://localhost:8080
- Upload documents using drag-and-drop or file selection
- View uploaded documents in the Knowledge Base tab
- Delete individual documents or reset the entire knowledge base
- Switch to the Q&A tab
- Type your question in the text area
- Click "Ask Question" to get an answer
- View the detailed system logs to understand:
- How the frontend sends requests to the backend
- How ChromaDB finds relevant document chunks
- How OpenAI generates answers using the context
- The complete request/response flow
The system logs panel shows:
- Client requests to the backend
- Backend processing steps
- ChromaDB document retrieval
- OpenAI model interactions
- Response generation
Click on any log entry to view the detailed request/response data.
app.py: Flask application handling HTTP endpoints and file uploadsdocument_processor.py: Document parsing, text extraction, and chunkingrag_engine.py: RAG pipeline with ChromaDB integration and OpenAI interactiontemplates/index.html: Interactive web interface with system logging
.env: Configuration for OpenAI API key and model selectiondocker-compose.yml: ChromaDB container configurationrequirements.txt: Python dependenciesrestart.sh: Utility script for managing the Flask application
uploads/: Temporary storage for uploaded documentschroma_db/: ChromaDB persistent storagetemplates/: HTML templates
- Backend: Python, Flask
- Database: ChromaDB (vector store)
- AI: OpenAI API (configurable models)
- Frontend: HTML, JavaScript, Tailwind CSS
- Container: Docker (for ChromaDB)
- Documents are chunked into smaller pieces (default 1000 characters)
- ChromaDB handles document embedding and similarity search
- The system uses semantic search to find relevant context
- Answers include citations to help verify information
- Maximum file size: 16MB
- Supported formats: PDF, TXT, Markdown
- Default model: GPT-4o (configurable via .env)
- ChromaDB uses the default embedding model
- Keep documents focused and well-structured
- Use clear, specific questions
- Review system logs to understand the RAG process
- Monitor token usage through the OpenAI response logs
- API keys should never be committed to version control
- The .env file is excluded via .gitignore
- This is a development server, not for production use
- No authentication is implemented (add if needed)
