--- title: RAG Document Assistant emoji: 📄 colorFrom: green colorTo: blue sdk: static app_file: index.html pinned: false license: mit short_description: Grounded, cited answers from your own documents. tags: - rag - retrieval - embeddings - question-answering --- # RAG Document Assistant Ask questions about your own documents — answers are grounded in your text, cited to the source, and the assistant says **"I don't know"** instead of guessing. Runs entirely in your browser. ## What it does 1. Upload `.txt` / `.md` files (or **Load sample docs** — a fictional company handbook). 2. Build the index. 3. Ask a question → get an answer, the retrieval mode, and the exact source chunks it came from. Try: *"What is the refund window?"*, *"How do I reset my password?"*, *"What are the support hours?"* ## How the RAG pipeline works - **Chunking** — overlapping, sentence-aware windows so context isn't cut at boundaries. - **Embeddings** — a TF-IDF vectoriser computed in-browser (transparent and instant). - **Retrieval** — cosine similarity over chunk vectors returns the top matches. - **Grounding** — answers are assembled only from retrieved chunks and cited; below a similarity threshold it returns an explicit "I don't know". ## About this demo This live Space is the **extractive**, in-browser version (free to host as a Hugging Face **Static** Space, no key, no server). The full Python project adds neural `sentence-transformers` embeddings and optional grounded LLM generation (Gemini/OpenAI) with a graceful key-free fallback: 🔗 **Source:** https://github.com/furqunali/rag-document-assistant Sample docs are fictional. Uploaded files are processed **in-memory** and never leave your device. ## Files - `index.html` — UI - `logic.js` — chunk → TF-IDF embed → cosine retrieve → grounded answer (also runnable under Node) ## Limitations - Extractive mode returns the most relevant passage; the full version adds synthesised generative answers. - TF-IDF is keyword-semantic; the Python version's neural embeddings capture meaning more deeply. - Designed for demo-sized document sets held in memory. ## License MIT.