Spaces:
Sleeping
Sleeping
MEXAR Ultimate π§
Multimodal Explainable AI Reasoning Assistant
MEXAR is an explainable AI system that creates domain-specific intelligent agents from your data. It uses RAG (Retrieval-Augmented Generation) with source attribution and faithfulness scoring to provide transparent, verifiable answers.
β¨ Key Features
| Feature | Description |
|---|---|
| π Hybrid Search | Combines semantic (vector) + keyword search with RRF fusion |
| π― Cross-Encoder Reranking | Improves retrieval precision using sentence-transformers |
| π Source Attribution | Inline citations [1], [2] linking answers to sources |
| β Faithfulness Scoring | Measures how well answers are grounded in context |
| π£οΈ Multimodal Input | Audio (Whisper), Images (Vision), Video support |
| π Domain Guardrails | Prevents hallucinations outside knowledge base |
| π Text-to-Speech | ElevenLabs + Web Speech API support |
| π 5 File Types | CSV, PDF, DOCX, JSON, TXT |
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MEXAR Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β [User] βββΊ [React Frontend] β
β β β
β βΌ β
β [FastAPI Backend] β
β β β
β ββββΊ Data Validator (CSV/PDF/DOCX/JSON/TXT) β
β ββββΊ Prompt Analyzer (LLM-based domain extraction) β
β ββββΊ Knowledge Compiler (FastEmbed β pgvector) β
β ββββΊ Reasoning Engine β
β β β
β ββββΊ Hybrid Search (semantic + keyword) β
β ββββΊ Reranker (cross-encoder) β
β ββββΊ Source Attribution (inline citations) β
β ββββΊ Faithfulness Scorer (claim verification) β
β β
β [External Services] β
β ββββΊ Supabase (PostgreSQL + 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
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 Variables:
Create backend/.env:
# Required
GROQ_API_KEY=your_groq_api_key_here
DATABASE_URL=postgresql://user:password@host:5432/database
SECRET_KEY=your_secure_secret_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
Run Server:
python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
2. Frontend Setup
cd frontend
# Install dependencies
npm install
# Start development server
npm start
Open http://localhost:3000 in your browser.
π Project Structure
mexar_ultimate/
βββ 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
β β βββ multimodal_processor.py # Audio/Image/Video
β β βββ explainability.py # UI formatting
β βββ utils/ # Utility modules
β β βββ 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
β βββ services/ # External services
β β βββ tts_service.py # Text-to-speech
β β βββ storage_service.py # Supabase storage
β βββ main.py # FastAPI app entry
β βββ requirements.txt # Python dependencies
β
βββ 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
β
βββ README.md
π§ API Reference
Authentication
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login (returns JWT) |
| GET | /api/auth/me |
Get current user |
Agents
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/agents/ |
List all agents |
| GET | /api/agents/{name} |
Get agent details |
| DELETE | /api/agents/{name} |
Delete agent |
Compilation
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/compile/ |
Start compilation (multipart) |
| GET | /api/compile/{name}/status |
Check compilation status |
Chat
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/chat/ |
Send message |
| POST | /api/chat/multimodal |
Send with audio/image |
| GET | /api/chat/{agent}/history |
Get chat history |
| POST | /api/chat/transcribe |
Transcribe audio |
π§ͺ 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 - Component library
- React Router - Navigation
- Axios - HTTP client
External Services
- Supabase - Managed PostgreSQL + Storage
- Groq - Fast AI inference
- ElevenLabs - Text-to-Speech (optional)
π How It Works
1. Agent Creation
User uploads files β DataValidator parses β PromptAnalyzer extracts domain
β KnowledgeCompiler creates embeddings
β Stored in pgvector
2. Query Processing
User query β Domain Guardrail check
β Hybrid Search (semantic + keyword)
β Cross-Encoder Reranking (top 5)
β LLM Generation with context
β Source Attribution (citations)
β Faithfulness Scoring
β Explainability formatting
3. Confidence Scoring
Confidence is calculated from:
- Retrieval Quality (35%) - How relevant the retrieved chunks are
- Rerank Score (30%) - Cross-encoder confidence
- Faithfulness (25%) - How grounded the answer is
- Base Floor (10%) - For in-domain queries
π Deployment
See implementation_plan.md for detailed deployment instructions covering:
- GitHub repository setup
- Vercel (frontend)
- Render.com (backend)
- Neon PostgreSQL (database)
π License
MIT License - See LICENSE for details.
π Acknowledgments
- Groq - Fast AI inference
- Supabase - Postgres + Storage
- FastEmbed - Embeddings
- sentence-transformers - Reranking models