Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
|
@@ -5,51 +5,388 @@ colorFrom: purple
|
|
| 5 |
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
-
license:
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
- **Multi-KB Support** β Create and query multiple independent knowledge bases
|
| 19 |
-
- **Hybrid Retrieval** β BM25 + semantic vector search fused with RRF + cross-encoder reranking
|
| 20 |
-
- **Fast Transcription** β Groq Whisper API (~300ms turnaround)
|
| 21 |
-
- **Smart LLM Fallback** β Groq Llama-3.1-70B β Gemini 1.5 Flash
|
| 22 |
-
- **Source Citations** β Every answer is traceable to source documents and page numbers
|
| 23 |
-
- **Document Support** β PDF, DOCX, HTML, Markdown, TXT
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|--------|-------------|
|
| 31 |
-
| `GROQ_API_KEY` | Required β powers Whisper transcription and Llama LLM |
|
| 32 |
-
| `GEMINI_API_KEY` | Optional β Gemini 1.5 Flash fallback LLM |
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
-
|
| 41 |
-
- **spaCy** β Semantic chunking
|
| 42 |
|
| 43 |
##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iceVault
|
| 14 |
|
| 15 |
+
**Voice-First RAG Knowledge Agent**
|
| 16 |
|
| 17 |
+
*Speak to your documents. Get cited answers back.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
[](https://www.python.org/)
|
| 20 |
+
[](https://fastapi.tiangolo.com/)
|
| 21 |
+
[](LICENSE)
|
| 22 |
+
[](tests/)
|
| 23 |
+
[](https://huggingface.co/spaces/NinjainPJs/VoiceVault)
|
| 24 |
|
| 25 |
+
[**Live Demo β**](https://huggingface.co/spaces/NinjainPJs/VoiceVault) | [**Documentation β**](DOCS/) | [**Project Plan β**](PLAN.md)
|
| 26 |
|
| 27 |
+
</div>
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## Overview
|
| 32 |
+
|
| 33 |
+
VoiceVault is a production-grade, voice-first Retrieval-Augmented Generation (RAG) system built entirely from scratch. It enables users to record or type questions and receive answers grounded in their own private document collections β with inline citations pointing back to the exact source, page, and paragraph.
|
| 34 |
+
|
| 35 |
+
The project was built in 6 phases over several weeks, with a full test suite (328 tests), enterprise-grade security practices (bcrypt, parameterized SQL, SHA-256 audit logs, SSRF prevention), and deployment to Hugging Face Spaces via Docker.
|
| 36 |
+
|
| 37 |
+
**What makes this different from typical RAG demos:**
|
| 38 |
+
- **Hybrid retrieval** β BM25 keyword search + semantic vector search, fused with Reciprocal Rank Fusion (RRF) + cross-encoder reranking. Most tutorials use only one retrieval method.
|
| 39 |
+
- **Voice-native pipeline** β Groq Whisper API for ~300ms cloud transcription with local Whisper fallback; Web Speech API for TTS output.
|
| 40 |
+
- **Faithfulness guard** β Detects when the LLM cannot answer from retrieved context and returns a grounded refusal instead of hallucinating.
|
| 41 |
+
- **Multi-KB support** β Multiple independent knowledge bases, each optionally password-protected.
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## Screenshots
|
| 46 |
+
|
| 47 |
+
<div align="center">
|
| 48 |
+
|
| 49 |
+
### Ask VoiceVault β Voice Query Interface
|
| 50 |
+
*Record your question via microphone or type it. The mic button pulses when recording.*
|
| 51 |
+
|
| 52 |
+
<img src="Screenshots/1.png" alt="Ask VoiceVault β main voice query interface with dark glassmorphism UI" width="800"/>
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
### Knowledge Base Management
|
| 57 |
+
*Create named knowledge bases, upload documents (PDF, DOCX, HTML, MD, TXT), and manage them.*
|
| 58 |
+
|
| 59 |
+
<img src="Screenshots/2.png" alt="Knowledge Bases panel β empty state with New Knowledge Base button" width="800"/>
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
### Analytics Dashboard
|
| 64 |
+
*Real-time query statistics: total queries, average latency, citation counts, and daily breakdowns.*
|
| 65 |
+
|
| 66 |
+
<img src="Screenshots/3.png" alt="Analytics dashboard showing query statistics" width="800"/>
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
### Full App in Action
|
| 71 |
+
*A populated knowledge base (358 chunks from 1 document) and a live conversation with the RAG pipeline.*
|
| 72 |
|
| 73 |
+
<img src="Screenshots/4.png" alt="Full VoiceVault app with a knowledge base and active conversation" width="800"/>
|
| 74 |
+
|
| 75 |
+
</div>
|
| 76 |
+
|
| 77 |
+
---
|
|
|
|
| 78 |
|
| 79 |
## Architecture
|
| 80 |
|
| 81 |
```
|
| 82 |
+
INGESTION PATH (one-time per document set)
|
| 83 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 84 |
+
User uploads PDF / HTML / DOCX / MD / TXT
|
| 85 |
+
β
|
| 86 |
+
βΌ
|
| 87 |
+
DocumentParser β text + metadata per page
|
| 88 |
+
β (PyMuPDF, BS4, python-docx)
|
| 89 |
+
βΌ
|
| 90 |
+
SemanticChunker β sentence-aware chunks
|
| 91 |
+
β (spaCy sentences + cosine boundary)
|
| 92 |
+
βΌ
|
| 93 |
+
IndexBuilder β ChromaDB (vector) + BM25 (keyword)
|
| 94 |
+
+ SQLite (metadata)
|
| 95 |
+
|
| 96 |
+
QUERY PATH (real-time, per question)
|
| 97 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 98 |
+
Browser mic β WAV β POST /api/transcribe
|
| 99 |
+
β
|
| 100 |
+
βΌ
|
| 101 |
+
GroqTranscriber β Groq Whisper API (~300ms)
|
| 102 |
+
β [fallback: local Whisper CPU]
|
| 103 |
+
βΌ
|
| 104 |
+
QueryPreprocessor β filler removal, intent classification
|
| 105 |
+
β (factual / summary / compare)
|
| 106 |
+
βΌ
|
| 107 |
+
HybridRetriever β BM25 top-20 + Vector top-20
|
| 108 |
+
β β RRF merge (k=60)
|
| 109 |
+
β β CrossEncoder rerank (ms-marco-MiniLM-L12-v2)
|
| 110 |
+
β β diversity filter (max 2 chunks/page)
|
| 111 |
+
βΌ
|
| 112 |
+
ContextBuilder β formatted context with [Source:N] markers
|
| 113 |
+
βΌ
|
| 114 |
+
LangChain LCEL β Groq Llama-3.1-70B (primary)
|
| 115 |
+
β [fallback: Gemini 1.5 Flash]
|
| 116 |
+
βΌ
|
| 117 |
+
FaithfulnessGuard β refusal detection, confidence scoring
|
| 118 |
+
β
|
| 119 |
+
CitationInjector β resolve [Source:N] β filename + page
|
| 120 |
+
βΌ
|
| 121 |
+
JSON response β answer + citations + confidence + tts_text
|
| 122 |
+
β
|
| 123 |
+
βΌ
|
| 124 |
+
SPA Frontend β chat display + Web Speech API TTS
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## Features
|
| 130 |
+
|
| 131 |
+
| Feature | Detail |
|
| 132 |
+
|---------|--------|
|
| 133 |
+
| **Voice Input** | Browser microphone β WAV conversion β Groq Whisper API (~300ms) |
|
| 134 |
+
| **Hybrid Retrieval** | BM25 + semantic vector search, RRF fusion, cross-encoder reranking |
|
| 135 |
+
| **Multi-KB** | Create multiple independent knowledge bases per session |
|
| 136 |
+
| **KB Access Control** | Optional bcrypt password protection (work factor 12) per KB |
|
| 137 |
+
| **Document Formats** | PDF, DOCX, HTML, Markdown, TXT (OCR fallback for scanned PDFs) |
|
| 138 |
+
| **Source Citations** | Every answer traceable to source file + page number |
|
| 139 |
+
| **Faithfulness Guard** | Detects hallucinations; returns grounded refusal when context is insufficient |
|
| 140 |
+
| **Conversation Memory** | Rolling 5-turn conversation window passed to the LLM |
|
| 141 |
+
| **LLM Fallback** | Groq Llama-3.1-70B β Gemini 1.5 Flash automatic fallback |
|
| 142 |
+
| **TTS Output** | Web Speech API reads answer aloud with citation markers stripped |
|
| 143 |
+
| **Analytics** | SQLite audit log: query counts, latency, citation rates (7-day window) |
|
| 144 |
+
| **Privacy** | Raw queries never stored β SHA-256 hash only in audit log |
|
| 145 |
+
| **328 Tests** | Integration + unit tests across all 6 phases |
|
| 146 |
+
|
| 147 |
+
---
|
| 148 |
+
|
| 149 |
+
## Tech Stack
|
| 150 |
+
|
| 151 |
+
| Layer | Technology | Purpose |
|
| 152 |
+
|-------|-----------|---------|
|
| 153 |
+
| **API** | FastAPI + uvicorn | REST backend with async endpoints |
|
| 154 |
+
| **Frontend** | HTML5 / CSS3 / Vanilla JS | Premium dark SPA (no framework) |
|
| 155 |
+
| **ASR** | Groq Whisper API | Cloud transcription (~300ms) |
|
| 156 |
+
| **ASR Fallback** | OpenAI Whisper Large-v3 | Local CPU transcription |
|
| 157 |
+
| **Embeddings** | sentence-transformers `all-MiniLM-L6-v2` | Dense vector representations |
|
| 158 |
+
| **Reranking** | `cross-encoder/ms-marco-MiniLM-L12-v2` | Semantic relevance scoring |
|
| 159 |
+
| **Vector Store** | ChromaDB | In-process vector database |
|
| 160 |
+
| **Keyword Search** | rank-bm25 (BM25Okapi) | Lexical keyword matching |
|
| 161 |
+
| **Chunking** | spaCy `en_core_web_sm` | Sentence boundary detection |
|
| 162 |
+
| **LLM (primary)** | Groq Llama-3.1-70B | Fast inference via Groq cloud |
|
| 163 |
+
| **LLM (fallback)** | Gemini 1.5 Flash | Google generative AI fallback |
|
| 164 |
+
| **Orchestration** | LangChain LCEL | LLM pipeline composition |
|
| 165 |
+
| **Metadata** | SQLite | KB registry, doc index, audit log |
|
| 166 |
+
| **Security** | bcrypt (work factor 12) | KB password hashing |
|
| 167 |
+
| **Config** | Pydantic-settings | Centralized, type-safe config |
|
| 168 |
+
| **Deployment** | Docker on Hugging Face Spaces | Container-based cloud hosting |
|
| 169 |
+
|
| 170 |
+
---
|
| 171 |
+
|
| 172 |
+
## Project Structure
|
| 173 |
+
|
| 174 |
+
```
|
| 175 |
+
Project-VoiceVault/
|
| 176 |
+
βββ server.py # FastAPI entry point (run this)
|
| 177 |
+
βββ app.py # Gradio entry point (legacy / tests)
|
| 178 |
+
βββ config.py # Centralized Pydantic-settings config
|
| 179 |
+
βββ requirements.txt # All dependencies
|
| 180 |
+
βββ Dockerfile # HF Spaces Docker deployment
|
| 181 |
+
βββ .env.example # Environment variable template
|
| 182 |
+
β
|
| 183 |
+
βββ api/ # FastAPI REST API
|
| 184 |
+
β βββ __init__.py
|
| 185 |
+
β οΏ½οΏ½ββ routes.py # All /api/* endpoints
|
| 186 |
+
β
|
| 187 |
+
βββ static/ # SPA frontend assets
|
| 188 |
+
β βββ index.html # Single-page application shell
|
| 189 |
+
β βββ style.css # Dark glassmorphism design system
|
| 190 |
+
β βββ app.js # Full SPA logic (recording, chat, KB CRUD)
|
| 191 |
+
β
|
| 192 |
+
βββ voicevault/ # Core package
|
| 193 |
+
β βββ models.py # Pydantic data models
|
| 194 |
+
β βββ asr/
|
| 195 |
+
β β βββ groq_transcriber.py # Groq Whisper cloud ASR (~300ms)
|
| 196 |
+
β β βββ whisper_transcriber.py # Local Whisper CPU/GPU fallback
|
| 197 |
+
β β βββ query_preprocessor.py # Filler removal, intent classification
|
| 198 |
+
β βββ ingestion/
|
| 199 |
+
β β βββ document_parser.py # PDF/HTML/DOCX/MD/TXT β structured text
|
| 200 |
+
β β βββ semantic_chunker.py # Sentence-aware chunking with topic boundaries
|
| 201 |
+
β β βββ index_builder.py # ChromaDB + BM25 + SQLite orchestration
|
| 202 |
+
β βββ retrieval/
|
| 203 |
+
β β βββ hybrid_retriever.py # BM25 + vector + RRF + cross-encoder
|
| 204 |
+
β β βββ bm25_retriever.py # BM25Okapi keyword search
|
| 205 |
+
β β βββ vector_retriever.py # ChromaDB semantic search
|
| 206 |
+
β β βββ context_builder.py # Context formatting + citation markers
|
| 207 |
+
β βββ generation/
|
| 208 |
+
β β βββ answer_chain.py # LangChain LCEL + Groq + Gemini fallback
|
| 209 |
+
β β βββ faithfulness_guard.py # Hallucination detection + refusal
|
| 210 |
+
β β βββ citation_injector.py # [Source:N] β filename + page resolution
|
| 211 |
+
β βββ kb/
|
| 212 |
+
β β βββ kb_manager.py # KB lifecycle, bcrypt auth, validation
|
| 213 |
+
β βββ storage/
|
| 214 |
+
β β βββ sqlite_store.py # Schema, CRUD, audit log queries
|
| 215 |
+
β β βββ chroma_store.py # ChromaDB wrapper
|
| 216 |
+
β βββ tts/
|
| 217 |
+
β βββ web_speech.py # TTS text preparation
|
| 218 |
+
β
|
| 219 |
+
βββ ui/ # Gradio UI components (legacy / app.py)
|
| 220 |
+
β βββ tabs/
|
| 221 |
+
β β βββ ask_tab.py
|
| 222 |
+
β β βββ kb_tab.py
|
| 223 |
+
β β βββ analytics_tab.py
|
| 224 |
+
β β βββ settings_tab.py
|
| 225 |
+
β βββ components/
|
| 226 |
+
β βββ citation_panel.py
|
| 227 |
+
β βββ audio_controls.py
|
| 228 |
+
β
|
| 229 |
+
βββ tests/ # Full test suite β 328 tests
|
| 230 |
+
β βββ conftest.py
|
| 231 |
+
β βββ test_api_routes.py # Integration tests (FastAPI + real methods)
|
| 232 |
+
β βββ test_phase0.py # Foundation tests
|
| 233 |
+
β βββ test_phase1.py # Ingestion tests
|
| 234 |
+
β βββ test_phase2.py # Retrieval tests
|
| 235 |
+
β βββ test_phase3.py # ASR tests
|
| 236 |
+
β βββ test_phase4.py # Generation tests
|
| 237 |
+
β βββ test_phase5.py # UI / access control tests
|
| 238 |
+
β
|
| 239 |
+
βββ DOCS/ # Detailed phase documentation
|
| 240 |
+
β βββ phase0_foundation.md
|
| 241 |
+
β βββ phase1_ingestion.md
|
| 242 |
+
β βββ phase2_retrieval.md
|
| 243 |
+
β βββ phase3_asr.md
|
| 244 |
+
β βββ phase4_generation.md
|
| 245 |
+
β βββ phase5_ui_access.md
|
| 246 |
+
β βββ phase6_deployment.md
|
| 247 |
+
β
|
| 248 |
+
βββ Screenshots/
|
| 249 |
+
βββ 1.png # Ask tab β voice query interface
|
| 250 |
+
βββ 2.png # Knowledge Bases panel
|
| 251 |
+
βββ 3.png # Analytics dashboard
|
| 252 |
+
βββ 4.png # Full app with KB and live conversation
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
---
|
| 256 |
+
|
| 257 |
+
## Quick Start
|
| 258 |
+
|
| 259 |
+
### Prerequisites
|
| 260 |
+
|
| 261 |
+
- Python 3.11+
|
| 262 |
+
- A Groq API key ([free at console.groq.com](https://console.groq.com))
|
| 263 |
+
- Optionally a Gemini API key ([free at aistudio.google.com](https://aistudio.google.com))
|
| 264 |
+
|
| 265 |
+
### 1. Clone and install
|
| 266 |
+
|
| 267 |
+
```bash
|
| 268 |
+
git clone https://github.com/ninjacode911/Project-VoiceVault.git
|
| 269 |
+
cd Project-VoiceVault
|
| 270 |
+
python -m venv .venv
|
| 271 |
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
| 272 |
+
pip install torch --index-url https://download.pytorch.org/whl/cpu # CPU-only (saves ~1.8GB)
|
| 273 |
+
pip install -r requirements.txt
|
| 274 |
+
python -m spacy download en_core_web_sm
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
### 2. Configure secrets
|
| 278 |
+
|
| 279 |
+
```bash
|
| 280 |
+
cp .env.example .env
|
| 281 |
+
# Edit .env and add:
|
| 282 |
+
# GROQ_API_KEY=gsk_...
|
| 283 |
+
# GEMINI_API_KEY=... (optional)
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
### 3. Run
|
| 287 |
+
|
| 288 |
+
```bash
|
| 289 |
+
python server.py
|
| 290 |
+
# Open http://localhost:7860
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
### 4. Use it
|
| 294 |
+
|
| 295 |
+
1. Navigate to **Knowledge Bases** β click **+ New Knowledge Base**
|
| 296 |
+
2. Name it (lowercase, hyphens only, e.g. `my-docs`) and upload your PDFs/documents
|
| 297 |
+
3. Go back to **Ask VoiceVault** β select your KB β record or type a question β click **Ask**
|
| 298 |
+
|
| 299 |
+
---
|
| 300 |
+
|
| 301 |
+
## Running Tests
|
| 302 |
+
|
| 303 |
+
```bash
|
| 304 |
+
pytest tests/ -v
|
| 305 |
+
# Expected: 328 passed
|
| 306 |
```
|
| 307 |
+
|
| 308 |
+
The integration tests in `tests/test_api_routes.py` use a real `KBManager` backed by a temp SQLite DB and exercise the actual FastAPI routes and method signatures β not mocked pipelines. This is intentional: it catches runtime `AttributeError` bugs that pure-mock unit tests miss.
|
| 309 |
+
|
| 310 |
+
---
|
| 311 |
+
|
| 312 |
+
## Deployment to Hugging Face Spaces
|
| 313 |
+
|
| 314 |
+
The project ships with a `Dockerfile` configured for HF Spaces. The Docker image:
|
| 315 |
+
- Uses Python 3.11-slim base
|
| 316 |
+
- Installs CPU-only PyTorch (~650MB vs 2.5GB GPU wheels)
|
| 317 |
+
- Pre-downloads `all-MiniLM-L6-v2` and `cross-encoder/ms-marco-MiniLM-L12-v2` at build time (no cold-start model downloads)
|
| 318 |
+
- Downloads `en_core_web_sm` spaCy model at build time
|
| 319 |
+
- Binds to `0.0.0.0:7860` (HF Spaces default port)
|
| 320 |
+
|
| 321 |
+
To deploy your own copy:
|
| 322 |
+
|
| 323 |
+
1. Create a [Hugging Face Space](https://huggingface.co/new-space) with **Docker** SDK
|
| 324 |
+
2. Push this repository to the Space's git remote
|
| 325 |
+
3. Add `GROQ_API_KEY` (and optionally `GEMINI_API_KEY`) as Space secrets
|
| 326 |
+
|
| 327 |
+
See [DOCS/phase6_deployment.md](DOCS/phase6_deployment.md) for the full deployment walkthrough.
|
| 328 |
+
|
| 329 |
+
---
|
| 330 |
+
|
| 331 |
+
## Configuration
|
| 332 |
+
|
| 333 |
+
All configuration is environment-driven via `.env`. See [`.env.example`](.env.example) for the full reference.
|
| 334 |
+
|
| 335 |
+
Key variables:
|
| 336 |
+
|
| 337 |
+
| Variable | Default | Description |
|
| 338 |
+
|----------|---------|-------------|
|
| 339 |
+
| `GROQ_API_KEY` | β | **Required.** Groq API key for Whisper + Llama |
|
| 340 |
+
| `GEMINI_API_KEY` | β | Optional Gemini fallback key |
|
| 341 |
+
| `HOST` | `0.0.0.0` | Server bind address |
|
| 342 |
+
| `PORT` | `7860` | Server port |
|
| 343 |
+
| `FINAL_TOP_K` | `5` | Number of chunks passed to LLM |
|
| 344 |
+
| `MAX_ANSWER_TOKENS` | `500` | LLM max output tokens |
|
| 345 |
+
| `CHUNK_SIZE_MAX` | `600` | Max tokens per document chunk |
|
| 346 |
+
| `BCRYPT_ROUNDS` | `12` | bcrypt work factor for KB passwords |
|
| 347 |
+
|
| 348 |
+
---
|
| 349 |
+
|
| 350 |
+
## Security
|
| 351 |
+
|
| 352 |
+
| Control | Implementation |
|
| 353 |
+
|---------|----------------|
|
| 354 |
+
| **No raw queries stored** | Audit log stores SHA-256 hash only |
|
| 355 |
+
| **KB access control** | bcrypt-hashed passwords (work factor 12) |
|
| 356 |
+
| **SQL injection prevention** | 100% parameterized queries β no f-string SQL |
|
| 357 |
+
| **Path traversal prevention** | KB names validated as slugs (`^[a-z0-9][a-z0-9\-]*[a-z0-9]$`) |
|
| 358 |
+
| **SSRF prevention** | URL ingestion via trafilatura with no internal-network access |
|
| 359 |
+
| **Upload whitelist** | Only `.pdf`, `.html`, `.docx`, `.md`, `.txt` accepted |
|
| 360 |
+
| **File size limit** | 50MB max per upload |
|
| 361 |
+
| **GPU isolation** | `CUDA_VISIBLE_DEVICES=-1` prevents CUDA crashes on incompatible hardware |
|
| 362 |
+
| **No secrets in git** | `.env` gitignored; HF secrets via Space settings API |
|
| 363 |
+
|
| 364 |
+
---
|
| 365 |
+
|
| 366 |
+
## Phase Documentation
|
| 367 |
+
|
| 368 |
+
Each phase has a detailed write-up covering design decisions, key code sections, and test results:
|
| 369 |
+
|
| 370 |
+
| Phase | Topic | Tests |
|
| 371 |
+
|-------|-------|-------|
|
| 372 |
+
| [Phase 0](DOCS/phase0_foundation.md) | Project Foundation (config, models, schema, scaffold) | 58 β
|
|
| 373 |
+
| [Phase 1](DOCS/phase1_ingestion.md) | Document Ingestion (parser, chunker, indexer) | 46 β
|
|
| 374 |
+
| [Phase 2](DOCS/phase2_retrieval.md) | Hybrid Retrieval (BM25 + vector + RRF + reranker) | 33 β
|
|
| 375 |
+
| [Phase 3](DOCS/phase3_asr.md) | ASR & Voice Input (Whisper, query preprocessor) | 47 β
|
|
| 376 |
+
| [Phase 4](DOCS/phase4_generation.md) | Generation & Citations (LangChain, faithfulness guard) | 72 β
|
|
| 377 |
+
| [Phase 5](DOCS/phase5_ui_access.md) | Full UI, TTS & Access Control | 55 β
|
|
| 378 |
+
| [Phase 6](DOCS/phase6_deployment.md) | FastAPI Server, SPA Frontend & HF Deployment | 17 β
|
|
| 379 |
+
|
| 380 |
+
**Total: 328 tests β all passing.**
|
| 381 |
+
|
| 382 |
+
---
|
| 383 |
+
|
| 384 |
+
## License
|
| 385 |
+
|
| 386 |
+
**Source Available β All Rights Reserved.** See [LICENSE](LICENSE) for full terms.
|
| 387 |
+
|
| 388 |
+
The source code is publicly visible for viewing and educational purposes. Any use in personal, commercial, or academic projects requires explicit written permission from the author.
|
| 389 |
+
|
| 390 |
+
To request permission: navnitamrutharaj1234@gmail.com
|
| 391 |
+
|
| 392 |
+
**Author:** Navnit Amrutharaj
|