Spaces:
Running
title: MEXAR Ultimate
emoji: π§
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit
MEXAR Ultimate π§
Multimodal Explainable AI Reasoning Assistant
Create domain-specific intelligent agents from your data with transparent, explainable AI responses using RAG (Retrieval-Augmented Generation) with source attribution and faithfulness scoring.
π Live Demo: https://mexar.vercel.app
π‘ Backend API: https://devrajsinh2012-mexar.hf.space
β¨ Key Features
| Feature | Description |
|---|---|
| π Hybrid Search | Combines semantic (vector) + keyword search with RRF fusion for optimal retrieval |
| π― Cross-Encoder Reranking | Improves retrieval precision using sentence-transformers |
| π Source Attribution | Inline citations [1], [2] linking answers to source data |
| β Faithfulness Scoring | Measures how well answers are grounded in retrieved context |
| π£οΈ Multimodal Input | Audio (Whisper), Images (Vision), Video support |
| π Domain Guardrails | Prevents hallucinations outside knowledge base |
| π Text-to-Speech | ElevenLabs + Web Speech API integration |
| π 5 File Types | CSV, PDF, DOCX, JSON, TXT |
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MEXAR Ultimate Stack β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β [React Frontend - Vercel] β
β β β
β [FastAPI Backend - Hugging Face Spaces] β
β β β
β βββββββββββββββββββββββββββββββββββββββ β
β β π Data Validator (5 file types) β β
β β π€ Prompt Analyzer (LLM-based) β β
β β π¦ Knowledge Compiler (FastEmbed) β β
β β π§ Reasoning Engine β β
β β ββ Hybrid Search β β
β β ββ Cross-Encoder Reranker β β
β β ββ Source Attribution β β
β β ββ Faithfulness Scorer β β
β βββββββββββββββββββββββββββββββββββββββ β
β β β
β [External Services] β
β ββ Supabase (PostgreSQL + pgvector + Storage) β
β ββ Groq API (LLM + Whisper + Vision) β
β ββ ElevenLabs (Text-to-Speech) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quick Start
Prerequisites
- Python 3.9+ with pip
- Node.js 18+ with npm
- PostgreSQL with
pgvectorextension (or use Supabase) - Groq API Key - Get free at console.groq.com
Local Development
1. Backend Setup
cd backend
# Create virtual environment
python -m venv venv
# Activate (Windows)
.\venv\Scripts\activate
# Activate (macOS/Linux)
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env and add your API keys
# Run server
python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
Backend will run at: http://localhost:8000
2. Frontend Setup
cd frontend
# Install dependencies
npm install
# Start development server
npm start
Frontend will run at: http://localhost:3000
π Project Structure
mexar_ultimate/
βββ backend/ # FastAPI Backend
β βββ api/ # REST API endpoints
β β βββ auth.py # Authentication (JWT)
β β βββ agents.py # Agent CRUD
β β βββ chat.py # Chat + multimodal
β β βββ compile.py # Knowledge compilation
β β βββ websocket.py # Real-time updates
β βββ core/ # Core configuration
β β βββ config.py # Settings
β β βββ database.py # SQLAlchemy setup
β β βββ security.py # JWT handling
β βββ models/ # Database models
β β βββ user.py # User model
β β βββ agent.py # Agent + CompilationJob
β β βββ chunk.py # DocumentChunk (pgvector)
β β βββ conversation.py # Chat history
β βββ modules/ # Core AI modules
β β βββ data_validator.py # File parsing
β β βββ prompt_analyzer.py # Domain extraction
β β βββ knowledge_compiler.py # Vector embeddings
β β βββ reasoning_engine.py # RAG pipeline
β β βββ explainability.py # UI formatting
β βββ utils/ # Utilities
β β βββ groq_client.py # Groq API wrapper
β β βββ hybrid_search.py # RRF search fusion
β β βββ reranker.py # Cross-encoder
β β βββ faithfulness.py # Claim verification
β β βββ source_attribution.py # Citation extraction
β βββ main.py # FastAPI entry point
β βββ requirements.txt # Python dependencies
β
βββ frontend/ # React Frontend
β βββ src/
β β βββ pages/ # React pages
β β β βββ Landing.jsx # Home page
β β β βββ Login.jsx # Authentication
β β β βββ Dashboard.jsx # User dashboard
β β β βββ AgentCreation.jsx # Create agent
β β β βββ CompilationProgress.jsx # Build progress
β β β βββ Chat.jsx # Chat interface
β β βββ components/ # Reusable UI
β β βββ contexts/ # React contexts
β β βββ api/ # API client
β β βββ App.jsx # Main component
β βββ package.json # Node dependencies
β βββ vercel.json # Vercel config
β
βββ Dockerfile # Docker config for HF Spaces
βββ README.md # This file
π Deployment
Current Deployment (Free Tier)
- Frontend: Vercel - https://mexar.vercel.app
- Backend: Hugging Face Spaces - https://devrajsinh2012-mexar.hf.space
- Database: Supabase (PostgreSQL with pgvector)
- Storage: Supabase Storage
- Total Cost: $0/month
Deploy Your Own Instance
Deploy Backend to Hugging Face Spaces
- Fork this repository
- Create a new Space at huggingface.co/new-space
- Select Docker as SDK
- Connect your GitHub repository
- Add Repository Secrets:
GROQ_API_KEYDATABASE_URLSUPABASE_URLSUPABASE_KEYSECRET_KEYFRONTEND_URL
Deploy Frontend to Vercel
- Import repository at vercel.com
- Set Root Directory to
frontend - Add Environment Variable:
REACT_APP_API_URL= Your HF Spaces URL
π§ Environment Variables
Backend (backend/.env)
# Required: Get from console.groq.com
GROQ_API_KEY=your_groq_api_key_here
# Supabase Database
DATABASE_URL=postgresql://user:password@host:5432/database
# JWT Security
SECRET_KEY=generate-a-secure-random-key
# Supabase Storage
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your_supabase_service_role_key
# Optional: ElevenLabs TTS
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
# Frontend URL for CORS
FRONTEND_URL=https://mexar.vercel.app
Frontend (frontend/.env)
# Backend API URL
REACT_APP_API_URL=https://your-backend.hf.space
π API Documentation
Once the backend is running, interactive API docs are available at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
Key Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login (returns JWT) |
| GET | /api/agents/ |
List all agents |
| POST | /api/compile/ |
Start agent compilation |
| GET | /api/compile/{name}/status |
Check compilation status |
| POST | /api/chat/ |
Send message to agent |
| POST | /api/chat/multimodal |
Send with audio/image |
π§ͺ Technologies
Backend
- FastAPI - Modern async Python web framework
- SQLAlchemy - ORM for PostgreSQL
- pgvector - Vector similarity search
- FastEmbed - Local embedding generation (BAAI/bge-small-en-v1.5)
- sentence-transformers - Cross-encoder reranking
- Groq API - LLM (Llama 3.1/3.3), Whisper (audio), Vision (images)
Frontend
- React 18 - UI framework
- Material-UI (MUI) - Component library
- React Router - Navigation
- Axios - HTTP client
External Services
- Supabase - Managed PostgreSQL + Storage
- Groq - Fast AI inference (LPU architecture)
- ElevenLabs - Text-to-Speech (optional)
π How It Works
1. Agent Creation Flow
User uploads files β DataValidator parses content
β PromptAnalyzer extracts domain & keywords
β KnowledgeCompiler creates embeddings
β Stored in pgvector database
2. Query Processing Flow
User query β Domain Guardrail check
β Hybrid Search (semantic + keyword)
β Cross-Encoder Reranking (top 5 results)
β LLM Generation with retrieved context
β Source Attribution (extract citations)
β Faithfulness Scoring (verify grounding)
β Explainability Formatting
3. Confidence Calculation
Confidence score is calculated from:
- Retrieval Quality (35%) - Relevance of retrieved chunks
- Rerank Score (30%) - Cross-encoder confidence
- Faithfulness (25%) - Answer grounding in context
- Base Floor (10%) - For in-domain queries
β οΈ Known Limitations (Free Tier)
- Cold Start Delay: First request after 15 min idle takes 45-90 seconds
- Model Download: Initial startup takes 3-5 minutes (FastEmbed caching)
- Groq Rate Limits: 30 requests/min, 14,400/day (free tier)
- Concurrent Users: 1-2 recommended on free tier (2GB RAM limit)
- Ephemeral Storage: HF Spaces
/tmpdata lost on restart (Supabase used for persistence)
Production Migration: Upgrade to paid tiers for ~$54/month (persistent instances, higher limits)
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Groq - Fast AI inference with LPU technology
- Supabase - PostgreSQL + Storage platform
- FastEmbed - Lightweight embeddings library
- sentence-transformers - Reranking models
- Hugging Face - Free ML model hosting
π Support
For questions or support, please open an issue in the GitHub repository.
Built with β€οΈ using modern AI technologies