This document provides a comprehensive analysis of the IntelliDocs Enhanced RAG (Retrieval-Augmented Generation) system, detailing its architecture, technology stack, and operational workflow.
- Framework: FastAPI - High-performance web framework for building APIs.
- Vector Database: ChromaDB - Persistent vector storage for document embeddings.
- Embeddings: Sentence-Transformers (
all-MiniLM-L6-v2) - Local embedding generation using HuggingFace models. - Document Processing:
PyMuPDF(fitz): For high-quality PDF text and metadata extraction.python-docx: For parsing Microsoft Word documents.
- LLM Integration: Direct REST API integration with:
- OpenAI (GPT-3.5/4)
- Google Gemini (Pro/Flash)
- Anthropic Claude (Claude 3 family)
- Data Validation:
Pydantic&Pydantic-settingsfor robust configuration and schema management. - Session Management: Custom session handling via SQLite (
sessions.db) to manage user context and file limits.
- Structure: Semantic HTML5.
- Styling: Vanilla CSS with modern components, glassmorphism effects, and responsive design.
- Logic: Modular Vanilla JavaScript (ES6+) - no heavy frameworks, ensuring fast load times.
- Interactions: Drag-and-drop file uploads, real-time typing indicators, and progressive UI updates.
The project follows a modular architecture designed for scalability and maintainability:
- API Layer (
backend/api/):routes_upload.py: Handles file reception, validation, and triggering the ingestion pipeline.routes_rag.py: Manages the Q&A logic, retrieval, and LLM communication.routes_files.py: Provides endpoints for listing and deleting session files.
- Ingestion Engine (
backend/ingestion/):document_processor.py: Extracts raw text and metadata (author, pages, etc.).chunker.py: Implements semantic chunking to ensure context is preserved across text splits.
- Embedding Service (
backend/embedding/):- Manages local model loading and provides a caching layer (
embeddings_cache.db) to avoid re-embedding identical text across sessions.
- Manages local model loading and provides a caching layer (
- Vector Store interface (
backend/vector/):vectorstore.py: Abstracts ChromaDB operations (add, query, delete).retriever.py: Implements Hybrid Search (combining vector similarity with keyword matching) for better accuracy.
- LLM Provider Manager (
backend/llm/):- A unified interface to swap between OpenAI, Gemini, and Anthropic seamlessly.
- The user enters their name on the
welcome.htmlpage. - A unique
session_idis generated and stored. - The user configures their preferred AI provider and API key on the
auth.htmlpage (stored securely in the browser session).
- When a file is uploaded:
- Extraction: The
DocumentProcessorparses the PDF/DOCX. - Chunking: The text is split into overlapping "chunks" (default ~1000 characters).
- Embedding: Each chunk is converted into a high-dimensional vector using the local
Sentence-Transformersmodel. - Storage: Chunks and vectors are stored in ChromaDB, tagged with the
session_idandfilename.
- Extraction: The
- When a user asks a question:
- Embedding Query: The question is converted into a vector.
- Retrieval: The system searches ChromaDB for the Top-K (default 5) most relevant chunks related to the session.
- Context Construction: Relevant chunks and metadata (source files) are assembled into a structured context.
- Augmentation: An optimized prompt is sent to the chosen LLM containing the user's question + the retrieved document context.
- Response: The LLM generates an answer based only on the provided context, ensuring factual accuracy and citing the source document.
- Progressive Upload: Add new documents anytime without losing context from previous ones.
- Source Attribution: Every answer includes references to specific pages or files used.
- Hybrid Search: Uses both semantic meanings and exact keyword matches to find the best information.
- Zero Persistence (Privacy): Documents are tied to temporary sessions and can be cleared instantly.
- Local Embeddings: Sensitive document content is embedded locally on your machine before searching.
main.py: The application entry point (FastAPI).backend/: Core logic (API, LLM, Vector, Ingestion).frontend/: UI files (HTML, CSS, JS).chroma_store/: Persistent storage for document vectors.requirements.txt: List of all Python dependencies..env: Configuration settings (Server, Chunk size, etc.).