A comprehensive RAG (Retrieval Augmented Generation) system built with LlamaIndex, featuring document indexing, semantic search, question-answering, and an interactive chatbot interface. The system supports multiple LLM providers with automatic fallback mechanisms.
-
π Document Indexing (Q1): Advanced document processing with metadata extraction
- Support for PDF, DOCX, and Markdown files
- Intelligent text chunking with configurable overlap
- Advanced RAG pipeline with title and Q&A extraction
- ChromaDB vector store for efficient storage
-
π Semantic Search (Q2): Powerful document retrieval
- Vector similarity search with HuggingFace embeddings
- Configurable top-k results
- Similarity scoring and ranking
- Metadata filtering support
-
π¬ Question Answering (Q3): LLM-powered Q&A system
- Context-aware answer generation
- Source citation and confidence scoring
- Custom prompt templates optimized for RAG
- Document-specific filtering
-
π Evaluation (Q4): System performance assessment
- Relevance metrics
- Accuracy evaluation
- Quality checks
-
π€ Interactive Chatbot (Q5): Conversational interface
- Multi-session support
- Conversation history management
- Context-aware responses
- Session persistence
- π LLM Fallback System: Automatic failover between Groq and Gemini
- π RESTful API: FastAPI backend with Swagger documentation
- π» Modern Frontend: React-based web interface
- βοΈ Flexible Configuration: YAML-based configuration system
- π File Management: Upload, organize, and manage documents via API
The system follows a modular architecture with five core modules:
RAG System Architecture
βββ Q1: Document Indexer (indexer.py)
β βββ Document loading and parsing
β βββ Text chunking with overlap
β βββ Advanced metadata extraction (titles, Q&A)
β βββ Vector embedding and storage
β
βββ Q2: Document Retriever (retriever.py)
β βββ Vector similarity search
β βββ Top-k retrieval
β βββ Similarity scoring
β
βββ Q3: QA System (qa_system.py)
β βββ Context retrieval
β βββ LLM-based answer generation
β βββ Source citation
β
βββ Q4: Evaluator (evaluator.py)
β βββ Relevance metrics
β βββ Accuracy assessment
β
βββ Q5: Chatbot (chatbot.py)
βββ Conversation management
βββ Session handling
βββ Context building
Backend:
- Python 3.9+
- LlamaIndex (vector store and RAG framework)
- ChromaDB (vector database)
- FastAPI (REST API)
- HuggingFace (embeddings)
- Groq & Gemini (LLM providers)
Frontend:
- React + Vite
- Tailwind CSS
- Axios (API client)
- Python 3.9 or higher
- Node.js 16+ (for frontend)
- pip package manager
-
Clone the repository
git clone <repository-url> cd TP_RAG_CENTRALE_CASABLANCA
-
Create a virtual environment (recommended)
python -m venv venv # On Windows venv\Scripts\activate # On Linux/Mac source venv/bin/activate
-
Install Python dependencies
pip install -r requirements.txt
-
Configure the system Edit
Config.yamland add your API keys:groq: api_key: "your_groq_api_key" gemini: api_key: "your_gemini_api_key"
-
Navigate to frontend directory
cd frontend -
Install dependencies
npm install
-
Start development server
npm run dev
The system is configured via Config.yaml. Key settings:
paths:
data_dir: "./data/files" # Documents to index
vectorstore_dir: "./data/vectorstore" # Vector database
chat_sessions_dir: "./data/chat_sessions" # Chat historyembedding:
model_name: "BAAI/bge-large-en-v1.5" # HuggingFace modeldocument_processing:
chunk_size: 1024 # Characters per chunk
chunk_overlap: 128 # Overlap between chunksgroq:
api_key: "your_key"
model: "llama-3.3-70b-versatile"
temperature: 0.7
gemini:
api_key: "your_key"
model: "gemini-2.0-flash"
temperature: 0.7The system provides a CLI for all operations:
python Cli.py buildThis will:
- Load documents from
data/files/ - Process and chunk documents
- Extract metadata (if advanced RAG enabled)
- Generate embeddings
- Store in ChromaDB
python Cli.py search "your query" -k 10Returns top-k most relevant documents with similarity scores.
python Cli.py ask "What is machine learning?"Generates an answer using retrieved context and LLM.
python Cli.py evaluate --quickRuns quality checks and performance metrics.
python Cli.py chatStarts an interactive chatbot session.
Start the API server:
# From project root
python -m src.backend.api
# Or from src/backend
cd src/backend
python api.pyThe API will be available at http://127.0.0.1:8000
File Management:
GET /api/files- List all files and foldersPOST /api/upload- Upload a documentPOST /api/create-folder- Create a folderDELETE /api/delete?path=<file_path>- Delete file/folder
RAG Operations:
POST /api/build-index- Build or rebuild the indexPOST /api/search- Search documents{ "query": "your search query", "k": 10 }
Chat:
POST /api/chat- Send a chat message{ "message": "your question", "session_id": "optional_session_id" }GET /api/sessions- List all chat sessionsPOST /api/session/new- Create a new sessionGET /api/session/{id}- Get session history
Interactive API Documentation:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
-
Start the backend API (see above)
-
Start the frontend
cd frontend npm run dev -
Access the web interface
- Open http://localhost:5173 (or the port shown in terminal)
-
Use the interface
- Upload documents via the file explorer
- Build the index
- Search documents
- Chat with the AI assistant
The system includes an intelligent fallback system for LLM providers:
- Primary: Attempts to use Groq API
- Fallback: Automatically switches to Gemini if Groq fails
- Transparent: No code changes needed - works automatically
The fallback is configured in Config.yaml and works across all modules (Q1, Q3, Q5).
TP_RAG_CENTRALE_CASABLANCA/
βββ Config.yaml # Main configuration file
βββ Cli.py # Command-line interface
βββ requirements.txt # Python dependencies
βββ README.md # This file
β
βββ data/ # Data directory
β βββ files/ # Documents to index
β βββ vectorstore/ # ChromaDB storage
β βββ chat_sessions/ # Chat history
β
βββ src/ # Source code
β βββ backend/
β β βββ api.py # FastAPI backend
β β βββ README.md # Backend documentation
β β
β βββ indexer.py # Q1: Document indexing
β βββ retriever.py # Q2: Document retrieval
β βββ qa_system.py # Q3: Question answering
β βββ evaluator.py # Q4: System evaluation
β βββ chatbot.py # Q5: Interactive chatbot
β βββ rag_system.py # Complete RAG system
β βββ llm_fallback.py # LLM fallback mechanism
β
βββ frontend/ # React frontend
βββ src/
β βββ components/ # React components
β βββ services/ # API client
β βββ App.jsx # Main app component
βββ package.json
βββ vite.config.js
# Test CLI commands
python Cli.py build
python Cli.py search "test query"
# Test API endpoints
curl http://127.0.0.1:8000/api/health- New LLM Provider: Extend
llm_fallback.py - New Document Type: Update
indexer.pydocument loader - New API Endpoint: Add to
src/backend/api.py - Frontend Component: Add to
frontend/src/components/
curl -X POST http://127.0.0.1:8000/api/upload \
-F "file=@document.pdf"curl -X POST http://127.0.0.1:8000/api/build-indexcurl -X POST http://127.0.0.1:8000/api/search \
-H "Content-Type: application/json" \
-d '{"query": "machine learning", "k": 5}'curl -X POST http://127.0.0.1:8000/api/chat \
-H "Content-Type: application/json" \
-d '{"message": "What is AI?", "session_id": "session_1"}'Import Errors:
- Ensure all dependencies are installed:
pip install -r requirements.txt - Check Python version:
python --version(should be 3.9+)
API Key Issues:
- Verify API keys in
Config.yaml - Check API key permissions and quotas
- The system will automatically fallback to Gemini if Groq fails
Index Not Found:
- Build the index first:
python Cli.py buildorPOST /api/build-index - Ensure documents exist in
data/files/
Port Already in Use:
- Change port in
src/backend/api.pyor kill the process using port 8000
This project is part of an academic assignment.
- OUANZOUGUI Abdelhak
- BELLMIR Omar
- BOURHAIM Ayoub
- DAHHASSI Chaymae
- AIT BIHI Laila
- EL ABDI Ibrahim
- LlamaIndex for the RAG framework
- ChromaDB for vector storage
- HuggingFace for embedding models
- Groq and Google for LLM APIs
- LlamaIndex Documentation
- ChromaDB Documentation
- FastAPI Documentation
- Groq API Documentation
- Google Gemini API Documentation
Happy RAG-ing! π