ComposableConsult/ragmodelwithllm
0
๐ง RAG Chatbot with Document Upload and PDF Support
This is a lightweight Retrieval-Augmented Generation (RAG) chatbot built using Gradio, FAISS, Hugging Face Transformers, and Sentence Transformers. It enables users to upload .pdf or .txt documents and ask natural language questions about their contents. The chatbot uses a combination of embedding-based semantic search and a generative language model to provide accurate and context-aware answers.
๐ Features
- โ
Upload
.txtand.pdffiles - โ Automatically extracts and chunks document content
- โ FAISS-powered semantic search over document chunks
- โ
all-MiniLM-L6-v2SentenceTransformer for embedding generation - โ
TinyLlama-1.1B-Chat-v1.0for answer generation - โ Interactive chatbot with session-based message history
- โ GPU acceleration (if available), falls back to CPU
- โ Clean, responsive UI with example prompts
๐ ๏ธ How It Works
๐ Upload Documents
Upload one or more .pdf or .txt files using the drag-and-drop UI.
๐งฑ Index Building
The app:
- Extracts text from each document
- Splits it into 500-character chunks
- Generates embeddings using
all-MiniLM-L6-v2 - Stores the chunks in a FAISS index for fast retrieval
โ Querying
When a user asks a question:
- The query is embedded and compared against all document chunks
- The top-3 most relevant chunks are retrieved
- A custom prompt is created combining those chunks and the question
๐ฌ Chatbot Response
The prompt is passed to the TinyLlama language model, which generates a relevant answer. The result is displayed in a persistent chat history window.
๐ป Requirements
Install the required Python packages:
pip install gradio faiss-cpu torch transformers sentence-transformers PyPDF2