ComposableConsult/RAGwith3BModel
0
๐ RAG Assistant โ Retrieval-Augmented Generation with Uploads, Chat, and GPU Support
This app is a lightweight, production-ready Retrieval-Augmented Generation (RAG) chatbot built for Hugging Face Spaces. It allows you to upload .txt and .pdf documents, and ask questions grounded in the content of those documents. It uses local embedding + retrieval to enhance the accuracy and relevance of its answers.
๐ Features
โ
Upload and index multiple documents (PDF and TXT supported) โ
GPU acceleration when available (CPU fallback) โ
Lightweight language model for cost-effective deployment (TinyLlama) โ
Persistent chat interface for follow-up questions โ
SentenceTransformer + FAISS for semantic retrieval โ
Clean Gradio UI
๐ง How It Works
- Document Upload: Upload one or more
.txtor.pdffiles. - Embedding: The content is split into 500-character chunks and embedded using
all-MiniLM-L6-v2. - Indexing: FAISS is used to index the embeddings for fast similarity search.
- Retrieval: When a user asks a question, the most relevant chunks are retrieved based on cosine similarity.
- Generation: A small LLM (
TinyLlama-1.1B) uses the retrieved context to generate an answer.
๐งฑ Tech Stack
- LLM:
TinyLlama/TinyLlama-1.1B-Chat-v1.0(can be swapped for any HF-compatible model) - Embeddings:
sentence-transformers/all-MiniLM-L6-v2 - Vector Store: FAISS (in-memory)
- PDF Parsing:
PyPDF2 - UI: Gradio Blocks
- Device: Auto GPU/CPU via
torch.cuda.is_available()anddevice_map="auto"(requiresaccelerate)
๐งฉ Optional Extensions
- ๐ Add support for long-term chat memory
- ๐ฌ Replace Gradio chatbot with streaming output
- ๐ง Use quantized GGUF models via
llama.cpp+ctransformersfor faster CPU-only inference
๐ Setup (Local Dev)
pip install -r requirements.txt
python app.py
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
