Mexar / README.md
devrajsinh2012's picture
Initial commit of MEXAR Ultimate - Phase 2 cleanup complete
b0b150b
|
raw
history blame
10.8 kB

MEXAR Ultimate 🧠

Multimodal Explainable AI Reasoning Assistant

Python 3.9+ React 18 FastAPI License: MIT

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