Skip to content

Transform your documents into intelligent conversations. This open-source RAG chatbot combines semantic search with fine-tuned language models (LLaMA, Qwen2.5VL-3B) to deliver accurate, context-aware responses from your own knowledge base. Join our community!

Notifications You must be signed in to change notification settings

Kathan-max/RAG-Enhanced-Chatbot-with-LoRA-Fine-Tuning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Electric RAG - Advanced Retrieval-Augmented Generation System

๐Ÿ“Œ Overview

Electric RAG is a sophisticated Retrieval-Augmented Generation (RAG) system that combines document processing, semantic search, and multi-LLM orchestration to provide intelligent, context-aware responses. The system features a FastAPI backend with advanced document ingestion, embedding generation, and a React frontend for seamless user interaction.

UI

Chat UI

image

Document Ingestion

image

๐Ÿš€ Key Features

  • ๐Ÿ” Advanced RAG Pipeline: Complete document ingestion, chunking, embedding, and retrieval system
  • ๐Ÿง  Multi-LLM Orchestration: Support for multiple language models with jury-based decision making
  • ๐Ÿ“„ Multi-Format Document Processing: PDF parsing with OCR support, text extraction, and JSON storage
  • ๐ŸŽฏ Intelligent Chunking: Context-aware document segmentation with configurable overlap
  • ๐Ÿ”— Chain of Thought Processing: Enhanced reasoning capabilities with iterative thinking
  • ๐Ÿ–ผ๏ธ Image-Aware Processing: OCR-based image extraction and multi-modal content handling
  • ๐Ÿ“Š Vector Database Integration: Supabase vector database with analytics and monitoring
  • ๐ŸŒ Modern Web Interface: React frontend with Tailwind CSS for optimal user experience
  • โšก FastAPI Backend: High-performance API with CORS support and comprehensive endpoints

๐Ÿ› ๏ธ Tech Stack

Backend

  • Framework: FastAPI with Uvicorn
  • Language Models: GPT-4, Claude-3, Gemini-Pro, Llama-2, Mistral-7B
  • Embeddings: Sentence Transformers (all-mpnet-base-v2)
  • Vector Database: Supabase Vector Database
  • Document Processing: PyMuPDF, Mistral OCR
  • Chunking: Advanced sentence and page-based algorithms
  • Reranking: TF-IDF, keyword matching, and vector similarity

Frontend

  • Framework: React 19 with modern hooks
  • Styling: Tailwind CSS
  • Icons: Lucide React
  • Build Tool: Create React App

๐Ÿ“‚ Project Structure

RAG/
โ”œโ”€โ”€ backend/                          # FastAPI backend application
โ”‚   โ”œโ”€โ”€ chunking/                     # Document chunking algorithms
โ”‚   โ”‚   โ”œโ”€โ”€ chunker.py               # Main chunking interface
โ”‚   โ”‚   โ””โ”€โ”€ chunkers/                # Specific chunking implementations
โ”‚   โ”œโ”€โ”€ config/                       # Configuration settings
โ”‚   โ”‚   โ””โ”€โ”€ settings.py              # Global configuration parameters
โ”‚   โ”œโ”€โ”€ data/                         # Data storage and processing
โ”‚   โ”‚   โ”œโ”€โ”€ raw_document_data/       # Temporary document storage
โ”‚   โ”‚   โ””โ”€โ”€ raw_jsons/               # Processed JSON outputs
โ”‚   โ”œโ”€โ”€ database/                     # Database layer
โ”‚   โ”‚   โ”œโ”€โ”€ relational/               # Relational database components
โ”‚   โ”‚   โ””โ”€โ”€ vector/                   # Vector database integration
โ”‚   โ”‚       โ”œโ”€โ”€ vectorDB.py          # Vector database interface
โ”‚   โ”‚       โ””โ”€โ”€ vectorDBs/           # Specific vector DB implementations
โ”‚   โ”œโ”€โ”€ embedding/                    # Embedding generation
โ”‚   โ”‚   โ”œโ”€โ”€ encoder.py               # Main encoder interface
โ”‚   โ”‚   โ””โ”€โ”€ encoders/                # Specific encoder implementations
โ”‚   โ”œโ”€โ”€ generation/                   # LLM generation components
โ”‚   โ”œโ”€โ”€ helpers/                      # Utility helper modules
โ”‚   โ”œโ”€โ”€ ingestion/                    # Document ingestion pipeline
โ”‚   โ”‚   โ””โ”€โ”€ ingestion.py             # Main ingestion orchestrator
โ”‚   โ”œโ”€โ”€ llmservice/                   # LLM service layer
โ”‚   โ”‚   โ”œโ”€โ”€ multillmorchestrator.py  # Multi-LLM orchestration
โ”‚   โ”‚   โ”œโ”€โ”€ adaptiveJsonExtractor.py # JSON response extraction
โ”‚   โ”‚   โ”œโ”€โ”€ llmmodels.py             # LLM model definitions
โ”‚   โ”‚   โ””โ”€โ”€ prompts.py               # System prompts
โ”‚   โ”œโ”€โ”€ parsing/                      # Document parsing
โ”‚   โ”‚   โ”œโ”€โ”€ parser.py                # Main parser interface
โ”‚   โ”‚   โ””โ”€โ”€ parsers/                 # Specific parser implementations
โ”‚   โ”œโ”€โ”€ retriever/                    # Retrieval system
โ”‚   โ”‚   โ”œโ”€โ”€ retriever.py             # Main retrieval logic
โ”‚   โ”‚   โ””โ”€โ”€ reranker/                # Reranking algorithms
โ”‚   โ”œโ”€โ”€ utils/                        # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ logger.py                # Logging configuration
โ”‚   โ””โ”€โ”€ main.py                      # FastAPI application entry point
โ”œโ”€โ”€ frontend/                         # React frontend application
โ”‚   โ””โ”€โ”€ electric-rag/                # Main frontend package
โ”‚       โ”œโ”€โ”€ src/                     # React source code
โ”‚       โ”œโ”€โ”€ public/                  # Static assets
โ”‚       โ””โ”€โ”€ package.json             # Frontend dependencies
โ”œโ”€โ”€ requirements.txt                  # Python dependencies
โ””โ”€โ”€ README.md                        # Project documentation

โœ… Core Functionality

Document Processing

  • Multi-format Support: PDF, text, and scanned documents
  • OCR Integration: Mistral OCR for image-based content extraction
  • Smart Chunking: Configurable chunk sizes with overlap optimization
  • Content Preservation: Maintains document structure and formatting

Retrieval System

  • Semantic Search: Vector similarity-based document retrieval
  • Multi-modal Retrieval: Text and image content matching
  • Reranking: Combines TF-IDF, keyword matching, and vector similarity
  • Configurable Top-K: Adjustable number of retrieved chunks

LLM Orchestration

  • Multi-LLM Support: Integration with multiple language model providers
  • Jury-based Decisions: Consensus-based response generation
  • Chain of Thought: Iterative reasoning for complex queries
  • Expert LLM Selection: Specialized model selection for specific tasks

API Endpoints

  • Chat Interface: /api/chat - Main conversation endpoint
  • Document Upload: /api/upload - File ingestion with optional training
  • Analytics: /api/analytics - Vector database statistics
  • Health Check: /api/health - System status monitoring
  • LLM Models: /api/llm-models - Available model information

๐Ÿงช Getting Started

Prerequisites

  • Python 3.8+
  • Node.js 16+ (for frontend)
  • Supabase account (for vector database)
  • API keys for LLM providers

Backend Setup

  1. Clone the repository:

    git clone <repository-url>
    cd RAG/backend
  2. Install Python dependencies:

    pip install -r requirements.txt
  3. Configure environment variables: Create a .env file with:

    ENCODER_NAME=sentence_encoder
    ENCODING_MODEL=all-mpnet-base-v2
    PARSER=mistral_ocr
    CHUNKER=group_embedding
  4. Start the backend server:

    python main.py

    The API will be available at http://localhost:8000

Frontend Setup

  1. Navigate to frontend directory:

    cd ../frontend/electric-rag
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm start

    The frontend will be available at http://localhost:3000


๐Ÿ”ง Configuration

Backend Settings (backend/config/settings.py)

  • Chunking: DEFAULT_CHUNK_LENGTH, DEFAULT_OVER_LAP
  • Retrieval: TOP_K, SIMILARITY_TH
  • Processing: DEFAULT_TEMPERATURE, DEFAULT_THINKING_ITERATIONS
  • Storage: TEMP_FILES_DOC, TEMP_FILES_JSONS

Vector Database

  • Configure Supabase connection in backend/database/vector/vectorDBs/supabasevdb.py
  • Set up appropriate indexes for optimal search performance

LLM Providers

  • Configure API keys for supported providers
  • Adjust model selection in backend/llmservice/llmmodels.py

๐Ÿ“Š API Usage

Chat Request

{
  "query": "What is the main topic of the document?",
  "multiLLM": false,
  "fetchChains": true,
  "noOfNeighbours": 5,
  "activeLLMs": [],
  "expertLLM": "GPT-4",
  "chainOfThought": true
}

Document Upload

curl -X POST "http://localhost:8000/api/upload" \
  -F "files=@document.pdf" \
  -F "train_model=false"

๐Ÿš€ Deployment

Production Considerations

  • Use proper environment variable management
  • Implement authentication and authorization
  • Set up monitoring and logging
  • Configure CORS origins for production domains
  • Use production-grade vector database instances

Docker Support

  • Backend can be containerized with FastAPI
  • Frontend can be built and served statically
  • Use environment-specific configuration files

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use TypeScript for frontend components
  • Add comprehensive tests for new features
  • Update documentation for API changes

๐Ÿ“ž Support

  • Issues: Create GitHub issues for bugs or feature requests
  • Discussions: Use GitHub Discussions for questions and ideas
  • Documentation: Check the codebase for implementation details

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ”ฎ Roadmap

  • Enhanced multi-modal support
  • Advanced reranking algorithms
  • Real-time collaboration features
  • Mobile application
  • Advanced analytics dashboard
  • Plugin system for custom processors

About

Transform your documents into intelligent conversations. This open-source RAG chatbot combines semantic search with fine-tuned language models (LLaMA, Qwen2.5VL-3B) to deliver accurate, context-aware responses from your own knowledge base. Join our community!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published