Devrajsinh bharatsinh gohil commited on
Commit
25ff05b
Β·
1 Parent(s): 7e87bb7

docs: Add comprehensive README with deployment info and architecture

Browse files
Files changed (1) hide show
  1. README.md +358 -12
README.md CHANGED
@@ -1,15 +1,361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- title: Mexar Ultimate
3
- emoji: 🧠
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: docker
7
- app_port: 7860
8
- app_file: backend/Dockerfile
9
- pinned: false
10
- license: mit
11
  ---
12
- # MEXAR Ultimate - AI Reasoning Assistant
13
 
14
- This Space hosts the backend API for MEXAR Ultimate.
15
- Frontend is deployed separately on Vercel.
 
 
 
 
1
+ # MEXAR Ultimate 🧠
2
+
3
+ **Multimodal Explainable AI Reasoning Assistant**
4
+
5
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
6
+ [![React 18](https://img.shields.io/badge/react-18-61dafb.svg)](https://reactjs.org/)
7
+ [![FastAPI](https://img.shields.io/badge/fastapi-0.109-009688.svg)](https://fastapi.tiangolo.com/)
8
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
9
+ [![Deployed](https://img.shields.io/badge/status-live-brightgreen.svg)](https://mexar.vercel.app)
10
+
11
+ > Create domain-specific intelligent agents from your data with transparent, explainable AI responses using RAG (Retrieval-Augmented Generation) with source attribution and faithfulness scoring.
12
+
13
+ **πŸš€ Live Demo**: [https://mexar.vercel.app](https://mexar.vercel.app)
14
+ **πŸ“‘ Backend API**: [https://devrajsinh2012-mexar.hf.space](https://devrajsinh2012-mexar.hf.space)
15
+
16
+ ---
17
+
18
+ ## ✨ Key Features
19
+
20
+ | Feature | Description |
21
+ |---------|-------------|
22
+ | πŸ” **Hybrid Search** | Combines semantic (vector) + keyword search with RRF fusion for optimal retrieval |
23
+ | 🎯 **Cross-Encoder Reranking** | Improves retrieval precision using sentence-transformers |
24
+ | πŸ“Š **Source Attribution** | Inline citations `[1]`, `[2]` linking answers to source data |
25
+ | βœ… **Faithfulness Scoring** | Measures how well answers are grounded in retrieved context |
26
+ | πŸ—£οΈ **Multimodal Input** | Audio (Whisper), Images (Vision), Video support |
27
+ | πŸ” **Domain Guardrails** | Prevents hallucinations outside knowledge base |
28
+ | πŸ”Š **Text-to-Speech** | ElevenLabs + Web Speech API integration |
29
+ | πŸ“ **5 File Types** | CSV, PDF, DOCX, JSON, TXT |
30
+
31
+ ---
32
+
33
+ ## πŸ—οΈ Architecture
34
+
35
+ ```
36
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
37
+ β”‚ MEXAR Ultimate Stack β”‚
38
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
39
+ β”‚ β”‚
40
+ β”‚ [React Frontend - Vercel] β”‚
41
+ β”‚ ↓ β”‚
42
+ β”‚ [FastAPI Backend - Hugging Face Spaces] β”‚
43
+ β”‚ ↓ β”‚
44
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
45
+ β”‚ β”‚ πŸ”„ Data Validator (5 file types) β”‚ β”‚
46
+ β”‚ β”‚ πŸ€– Prompt Analyzer (LLM-based) β”‚ β”‚
47
+ β”‚ β”‚ πŸ“¦ Knowledge Compiler (FastEmbed) β”‚ β”‚
48
+ β”‚ β”‚ 🧠 Reasoning Engine β”‚ β”‚
49
+ β”‚ β”‚ β”œβ”€ Hybrid Search β”‚ β”‚
50
+ β”‚ β”‚ β”œβ”€ Cross-Encoder Reranker β”‚ β”‚
51
+ β”‚ β”‚ β”œβ”€ Source Attribution β”‚ β”‚
52
+ β”‚ β”‚ └─ Faithfulness Scorer β”‚ β”‚
53
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
54
+ β”‚ ↓ β”‚
55
+ β”‚ [External Services] β”‚
56
+ β”‚ β”œβ”€ Supabase (PostgreSQL + pgvector + Storage) β”‚
57
+ β”‚ β”œβ”€ Groq API (LLM + Whisper + Vision) β”‚
58
+ β”‚ └─ ElevenLabs (Text-to-Speech) β”‚
59
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
60
+ ```
61
+
62
+ ---
63
+
64
+ ## πŸš€ Quick Start
65
+
66
+ ### Prerequisites
67
+
68
+ - **Python 3.9+** with pip
69
+ - **Node.js 18+** with npm
70
+ - **PostgreSQL** with `pgvector` extension (or use Supabase)
71
+ - **Groq API Key** - Get free at [console.groq.com](https://console.groq.com)
72
+
73
+ ### Local Development
74
+
75
+ #### 1. Backend Setup
76
+
77
+ ```bash
78
+ cd backend
79
+
80
+ # Create virtual environment
81
+ python -m venv venv
82
+
83
+ # Activate (Windows)
84
+ .\venv\Scripts\activate
85
+ # Activate (macOS/Linux)
86
+ source venv/bin/activate
87
+
88
+ # Install dependencies
89
+ pip install -r requirements.txt
90
+
91
+ # Configure environment
92
+ cp .env.example .env
93
+ # Edit .env and add your API keys
94
+
95
+ # Run server
96
+ python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
97
+ ```
98
+
99
+ **Backend will run at**: [http://localhost:8000](http://localhost:8000)
100
+
101
+ #### 2. Frontend Setup
102
+
103
+ ```bash
104
+ cd frontend
105
+
106
+ # Install dependencies
107
+ npm install
108
+
109
+ # Start development server
110
+ npm start
111
+ ```
112
+
113
+ **Frontend will run at**: [http://localhost:3000](http://localhost:3000)
114
+
115
+ ---
116
+
117
+ ## πŸ“ Project Structure
118
+
119
+ ```
120
+ mexar_ultimate/
121
+ β”œβ”€β”€ backend/ # FastAPI Backend
122
+ β”‚ β”œβ”€β”€ api/ # REST API endpoints
123
+ β”‚ β”‚ β”œβ”€β”€ auth.py # Authentication (JWT)
124
+ β”‚ β”‚ β”œβ”€β”€ agents.py # Agent CRUD
125
+ β”‚ β”‚ β”œβ”€β”€ chat.py # Chat + multimodal
126
+ β”‚ β”‚ β”œβ”€β”€ compile.py # Knowledge compilation
127
+ β”‚ β”‚ └── websocket.py # Real-time updates
128
+ β”‚ β”œβ”€β”€ core/ # Core configuration
129
+ β”‚ β”‚ β”œβ”€β”€ config.py # Settings
130
+ β”‚ β”‚ β”œβ”€β”€ database.py # SQLAlchemy setup
131
+ β”‚ β”‚ └── security.py # JWT handling
132
+ β”‚ β”œβ”€β”€ models/ # Database models
133
+ β”‚ β”‚ β”œβ”€β”€ user.py # User model
134
+ β”‚ β”‚ β”œβ”€β”€ agent.py # Agent + CompilationJob
135
+ β”‚ β”‚ β”œβ”€β”€ chunk.py # DocumentChunk (pgvector)
136
+ β”‚ β”‚ └── conversation.py # Chat history
137
+ β”‚ β”œβ”€β”€ modules/ # Core AI modules
138
+ β”‚ β”‚ β”œβ”€β”€ data_validator.py # File parsing
139
+ β”‚ β”‚ β”œβ”€β”€ prompt_analyzer.py # Domain extraction
140
+ β”‚ β”‚ β”œβ”€β”€ knowledge_compiler.py # Vector embeddings
141
+ β”‚ β”‚ β”œβ”€β”€ reasoning_engine.py # RAG pipeline
142
+ β”‚ β”‚ └── explainability.py # UI formatting
143
+ β”‚ β”œβ”€β”€ utils/ # Utilities
144
+ β”‚ β”‚ β”œβ”€β”€ groq_client.py # Groq API wrapper
145
+ β”‚ β”‚ β”œβ”€β”€ hybrid_search.py # RRF search fusion
146
+ β”‚ β”‚ β”œβ”€β”€ reranker.py # Cross-encoder
147
+ β”‚ β”‚ β”œβ”€β”€ faithfulness.py # Claim verification
148
+ β”‚ β”‚ └── source_attribution.py # Citation extraction
149
+ β”‚ β”œβ”€β”€ main.py # FastAPI entry point
150
+ β”‚ └── requirements.txt # Python dependencies
151
+ β”‚
152
+ β”œβ”€β”€ frontend/ # React Frontend
153
+ β”‚ β”œβ”€β”€ src/
154
+ β”‚ β”‚ β”œβ”€β”€ pages/ # React pages
155
+ β”‚ β”‚ β”‚ β”œβ”€β”€ Landing.jsx # Home page
156
+ β”‚ β”‚ β”‚ β”œβ”€β”€ Login.jsx # Authentication
157
+ β”‚ β”‚ β”‚ β”œβ”€β”€ Dashboard.jsx # User dashboard
158
+ β”‚ β”‚ β”‚ β”œβ”€β”€ AgentCreation.jsx # Create agent
159
+ β”‚ β”‚ β”‚ β”œβ”€β”€ CompilationProgress.jsx # Build progress
160
+ β”‚ β”‚ β”‚ └── Chat.jsx # Chat interface
161
+ β”‚ β”‚ β”œβ”€β”€ components/ # Reusable UI
162
+ β”‚ β”‚ β”œβ”€β”€ contexts/ # React contexts
163
+ β”‚ β”‚ β”œβ”€β”€ api/ # API client
164
+ β”‚ β”‚ └── App.jsx # Main component
165
+ β”‚ β”œβ”€β”€ package.json # Node dependencies
166
+ β”‚ └── vercel.json # Vercel config
167
+ β”‚
168
+ β”œβ”€β”€ Dockerfile # Docker config for HF Spaces
169
+ └── README.md # This file
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 🌐 Deployment
175
+
176
+ ### Current Deployment (Free Tier)
177
+
178
+ - **Frontend**: Vercel - [https://mexar.vercel.app](https://mexar.vercel.app)
179
+ - **Backend**: Hugging Face Spaces - [https://devrajsinh2012-mexar.hf.space](https://devrajsinh2012-mexar.hf.space)
180
+ - **Database**: Supabase (PostgreSQL with pgvector)
181
+ - **Storage**: Supabase Storage
182
+ - **Total Cost**: $0/month
183
+
184
+ ### Deploy Your Own Instance
185
+
186
+ #### Deploy Backend to Hugging Face Spaces
187
+
188
+ 1. Fork this repository
189
+ 2. Create a new Space at [huggingface.co/new-space](https://huggingface.co/new-space)
190
+ 3. Select **Docker** as SDK
191
+ 4. Connect your GitHub repository
192
+ 5. Add Repository Secrets:
193
+ - `GROQ_API_KEY`
194
+ - `DATABASE_URL`
195
+ - `SUPABASE_URL`
196
+ - `SUPABASE_KEY`
197
+ - `SECRET_KEY`
198
+ - `FRONTEND_URL`
199
+
200
+ #### Deploy Frontend to Vercel
201
+
202
+ 1. Import repository at [vercel.com](https://vercel.com)
203
+ 2. Set **Root Directory** to `frontend`
204
+ 3. Add Environment Variable:
205
+ - `REACT_APP_API_URL` = Your HF Spaces URL
206
+
207
+ ---
208
+
209
+ ## πŸ”§ Environment Variables
210
+
211
+ ### Backend (`backend/.env`)
212
+
213
+ ```env
214
+ # Required: Get from console.groq.com
215
+ GROQ_API_KEY=your_groq_api_key_here
216
+
217
+ # Supabase Database
218
+ DATABASE_URL=postgresql://user:password@host:5432/database
219
+
220
+ # JWT Security
221
+ SECRET_KEY=generate-a-secure-random-key
222
+
223
+ # Supabase Storage
224
+ SUPABASE_URL=https://your-project.supabase.co
225
+ SUPABASE_KEY=your_supabase_service_role_key
226
+
227
+ # Optional: ElevenLabs TTS
228
+ ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
229
+
230
+ # Frontend URL for CORS
231
+ FRONTEND_URL=https://mexar.vercel.app
232
+ ```
233
+
234
+ ### Frontend (`frontend/.env`)
235
+
236
+ ```env
237
+ # Backend API URL
238
+ REACT_APP_API_URL=https://your-backend.hf.space
239
+ ```
240
+
241
+ ---
242
+
243
+ ## πŸ” API Documentation
244
+
245
+ Once the backend is running, interactive API docs are available at:
246
+
247
+ - **Swagger UI**: `http://localhost:8000/docs`
248
+ - **ReDoc**: `http://localhost:8000/redoc`
249
+
250
+ ### Key Endpoints
251
+
252
+ | Method | Endpoint | Description |
253
+ |--------|----------|-------------|
254
+ | POST | `/api/auth/register` | Register new user |
255
+ | POST | `/api/auth/login` | Login (returns JWT) |
256
+ | GET | `/api/agents/` | List all agents |
257
+ | POST | `/api/compile/` | Start agent compilation |
258
+ | GET | `/api/compile/{name}/status` | Check compilation status |
259
+ | POST | `/api/chat/` | Send message to agent |
260
+ | POST | `/api/chat/multimodal` | Send with audio/image |
261
+
262
+ ---
263
+
264
+ ## πŸ§ͺ Technologies
265
+
266
+ ### Backend
267
+ - **FastAPI** - Modern async Python web framework
268
+ - **SQLAlchemy** - ORM for PostgreSQL
269
+ - **pgvector** - Vector similarity search
270
+ - **FastEmbed** - Local embedding generation (BAAI/bge-small-en-v1.5)
271
+ - **sentence-transformers** - Cross-encoder reranking
272
+ - **Groq API** - LLM (Llama 3.1/3.3), Whisper (audio), Vision (images)
273
+
274
+ ### Frontend
275
+ - **React 18** - UI framework
276
+ - **Material-UI (MUI)** - Component library
277
+ - **React Router** - Navigation
278
+ - **Axios** - HTTP client
279
+
280
+ ### External Services
281
+ - **Supabase** - Managed PostgreSQL + Storage
282
+ - **Groq** - Fast AI inference (LPU architecture)
283
+ - **ElevenLabs** - Text-to-Speech (optional)
284
+
285
+ ---
286
+
287
+ ## πŸ“Š How It Works
288
+
289
+ ### 1. Agent Creation Flow
290
+ ```
291
+ User uploads files β†’ DataValidator parses content
292
+ β†’ PromptAnalyzer extracts domain & keywords
293
+ β†’ KnowledgeCompiler creates embeddings
294
+ β†’ Stored in pgvector database
295
+ ```
296
+
297
+ ### 2. Query Processing Flow
298
+ ```
299
+ User query β†’ Domain Guardrail check
300
+ β†’ Hybrid Search (semantic + keyword)
301
+ β†’ Cross-Encoder Reranking (top 5 results)
302
+ β†’ LLM Generation with retrieved context
303
+ β†’ Source Attribution (extract citations)
304
+ β†’ Faithfulness Scoring (verify grounding)
305
+ β†’ Explainability Formatting
306
+ ```
307
+
308
+ ### 3. Confidence Calculation
309
+ Confidence score is calculated from:
310
+ - **Retrieval Quality** (35%) - Relevance of retrieved chunks
311
+ - **Rerank Score** (30%) - Cross-encoder confidence
312
+ - **Faithfulness** (25%) - Answer grounding in context
313
+ - **Base Floor** (10%) - For in-domain queries
314
+
315
+ ---
316
+
317
+ ## ⚠️ Known Limitations (Free Tier)
318
+
319
+ 1. **Cold Start Delay**: First request after 15 min idle takes 45-90 seconds
320
+ 2. **Model Download**: Initial startup takes 3-5 minutes (FastEmbed caching)
321
+ 3. **Groq Rate Limits**: 30 requests/min, 14,400/day (free tier)
322
+ 4. **Concurrent Users**: 1-2 recommended on free tier (2GB RAM limit)
323
+ 5. **Ephemeral Storage**: HF Spaces `/tmp` data lost on restart (Supabase used for persistence)
324
+
325
+ **Production Migration**: Upgrade to paid tiers for ~$54/month (persistent instances, higher limits)
326
+
327
+ ---
328
+
329
+ ## 🀝 Contributing
330
+
331
+ Contributions are welcome! Please feel free to submit a Pull Request.
332
+
333
+ 1. Fork the repository
334
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
335
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
336
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
337
+ 5. Open a Pull Request
338
+
339
+ ---
340
+
341
+ ## πŸ“„ License
342
+
343
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
344
+
345
  ---
346
+
347
+ ## πŸ™ Acknowledgments
348
+
349
+ - [Groq](https://groq.com) - Fast AI inference with LPU technology
350
+ - [Supabase](https://supabase.com) - PostgreSQL + Storage platform
351
+ - [FastEmbed](https://github.com/qdrant/fastembed) - Lightweight embeddings library
352
+ - [sentence-transformers](https://www.sbert.net) - Reranking models
353
+ - [Hugging Face](https://huggingface.co) - Free ML model hosting
354
+
355
  ---
 
356
 
357
+ ## πŸ“ž Support
358
+
359
+ For questions or support, please open an issue in the GitHub repository.
360
+
361
+ **Built with ❀️ using modern AI technologies**