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.


- ๐ 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
- 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
- Framework: React 19 with modern hooks
- Styling: Tailwind CSS
- Icons: Lucide React
- Build Tool: Create React App
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
- 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
- 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
- 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
- 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
- Python 3.8+
- Node.js 16+ (for frontend)
- Supabase account (for vector database)
- API keys for LLM providers
-
Clone the repository:
git clone <repository-url> cd RAG/backend
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure environment variables: Create a
.env
file with:ENCODER_NAME=sentence_encoder ENCODING_MODEL=all-mpnet-base-v2 PARSER=mistral_ocr CHUNKER=group_embedding
-
Start the backend server:
python main.py
The API will be available at
http://localhost:8000
-
Navigate to frontend directory:
cd ../frontend/electric-rag
-
Install dependencies:
npm install
-
Start the development server:
npm start
The frontend will be available at
http://localhost:3000
- 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
- Configure Supabase connection in
backend/database/vector/vectorDBs/supabasevdb.py
- Set up appropriate indexes for optimal search performance
- Configure API keys for supported providers
- Adjust model selection in
backend/llmservice/llmmodels.py
{
"query": "What is the main topic of the document?",
"multiLLM": false,
"fetchChains": true,
"noOfNeighbours": 5,
"activeLLMs": [],
"expertLLM": "GPT-4",
"chainOfThought": true
}
curl -X POST "http://localhost:8000/api/upload" \
-F "files=@document.pdf" \
-F "train_model=false"
- 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
- Backend can be containerized with FastAPI
- Frontend can be built and served statically
- Use environment-specific configuration files
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow PEP 8 for Python code
- Use TypeScript for frontend components
- Add comprehensive tests for new features
- Update documentation for API changes
- Issues: Create GitHub issues for bugs or feature requests
- Discussions: Use GitHub Discussions for questions and ideas
- Documentation: Check the codebase for implementation details
This project is licensed under the MIT License - see the LICENSE file for details.
- Enhanced multi-modal support
- Advanced reranking algorithms
- Real-time collaboration features
- Mobile application
- Advanced analytics dashboard
- Plugin system for custom processors