Spaces:
Running
Running
File size: 13,332 Bytes
1e638b2 25ff05b b0b150b 25ff05b b0b150b 25ff05b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
---
title: MEXAR Ultimate
emoji: π§
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit
---
# MEXAR Ultimate π§
**Multimodal Explainable AI Reasoning Assistant**
[](https://www.python.org/downloads/)
[](https://reactjs.org/)
[](https://fastapi.tiangolo.com/)
[](LICENSE)
[](https://mexar.vercel.app)
> 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](https://mexar.vercel.app)
**π‘ Backend API**: [https://devrajsinh2012-mexar.hf.space](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 `pgvector` extension (or use Supabase)
- **Groq API Key** - Get free at [console.groq.com](https://console.groq.com)
### Local Development
#### 1. Backend Setup
```bash
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](http://localhost:8000)
#### 2. Frontend Setup
```bash
cd frontend
# Install dependencies
npm install
# Start development server
npm start
```
**Frontend will run at**: [http://localhost:3000](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](https://mexar.vercel.app)
- **Backend**: Hugging Face Spaces - [https://devrajsinh2012-mexar.hf.space](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
1. Fork this repository
2. Create a new Space at [huggingface.co/new-space](https://huggingface.co/new-space)
3. Select **Docker** as SDK
4. Connect your GitHub repository
5. Add Repository Secrets:
- `GROQ_API_KEY`
- `DATABASE_URL`
- `SUPABASE_URL`
- `SUPABASE_KEY`
- `SECRET_KEY`
- `FRONTEND_URL`
#### Deploy Frontend to Vercel
1. Import repository at [vercel.com](https://vercel.com)
2. Set **Root Directory** to `frontend`
3. Add Environment Variable:
- `REACT_APP_API_URL` = Your HF Spaces URL
---
## π§ Environment Variables
### Backend (`backend/.env`)
```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`)
```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)
1. **Cold Start Delay**: First request after 15 min idle takes 45-90 seconds
2. **Model Download**: Initial startup takes 3-5 minutes (FastEmbed caching)
3. **Groq Rate Limits**: 30 requests/min, 14,400/day (free tier)
4. **Concurrent Users**: 1-2 recommended on free tier (2GB RAM limit)
5. **Ephemeral Storage**: HF Spaces `/tmp` data 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.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
---
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## π Acknowledgments
- [Groq](https://groq.com) - Fast AI inference with LPU technology
- [Supabase](https://supabase.com) - PostgreSQL + Storage platform
- [FastEmbed](https://github.com/qdrant/fastembed) - Lightweight embeddings library
- [sentence-transformers](https://www.sbert.net) - Reranking models
- [Hugging Face](https://huggingface.co) - Free ML model hosting
---
## π Support
For questions or support, please open an issue in the GitHub repository.
**Built with β€οΈ using modern AI technologies**
|