Mexar / README.md
Devrajsinh bharatsinh gohil
fix: Add HF Spaces YAML config and brain emoji favicon
1e638b2
metadata
title: MEXAR Ultimate
emoji: 🧠
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit

MEXAR Ultimate 🧠

Multimodal Explainable AI Reasoning Assistant

Python 3.9+ React 18 FastAPI License: MIT Deployed

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 pgvector extension (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)

Deploy Your Own Instance

Deploy Backend to Hugging Face Spaces

  1. Fork this repository
  2. Create a new Space at 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
  2. Set Root Directory to frontend
  3. 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)

  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 file for details.


πŸ™ Acknowledgments


πŸ“ž Support

For questions or support, please open an issue in the GitHub repository.

Built with ❀️ using modern AI technologies