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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π€ RAG Chatbot β Application Report
|
| 2 |
+
|
| 3 |
+
**Course:** Makers Lab (Term 3) | **Institute:** SPJIMR
|
| 4 |
+
**Date:** February 10, 2026
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## 1. What Is This Application?
|
| 9 |
+
|
| 10 |
+
This is an **AI-powered chatbot** that can answer questions by reading through your own documents. Instead of searching the internet, it looks through a personal "knowledge base" β a folder of text files you provide β and gives you accurate, sourced answers.
|
| 11 |
+
|
| 12 |
+
Think of it like having a **personal assistant who has read all your documents** and can instantly recall information from them when you ask a question.
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## 2. The Core Idea: RAG (Retrieval-Augmented Generation)
|
| 17 |
+
|
| 18 |
+
**RAG** stands for **Retrieval-Augmented Generation**. In simple terms, it combines two steps:
|
| 19 |
+
|
| 20 |
+
| Step | What Happens | Analogy |
|
| 21 |
+
|------|-------------|---------|
|
| 22 |
+
| **1. Retrieval** | The system searches your documents and finds the most relevant paragraphs related to your question | Like flipping through a textbook to find the right page |
|
| 23 |
+
| **2. Generation** | An AI model reads those paragraphs and writes a clear, human-like answer | Like a student summarizing what they found in their own words |
|
| 24 |
+
|
| 25 |
+
> [!IMPORTANT]
|
| 26 |
+
> The AI **only answers from your documents** β it does not make things up or pull information from the internet. If the answer isn't in your files, it will tell you.
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## 3. How It Works (Step by Step)
|
| 31 |
+
|
| 32 |
+
```mermaid
|
| 33 |
+
flowchart LR
|
| 34 |
+
A["π Your Documents"] --> B["βοΈ Split into Chunks"]
|
| 35 |
+
B --> C["π’ Convert to Numbers\n(Embeddings)"]
|
| 36 |
+
C --> D["ποΈ Store in FAISS\n(Vector Database)"]
|
| 37 |
+
E["β Your Question"] --> F["π’ Convert to Numbers"]
|
| 38 |
+
F --> G["π Find Similar Chunks"]
|
| 39 |
+
D --> G
|
| 40 |
+
G --> H["π€ AI Generates Answer"]
|
| 41 |
+
H --> I["π¬ Response Shown"]
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### Breaking it down:
|
| 45 |
+
|
| 46 |
+
1. **You add documents** β Place `.txt` files in the `knowledge_base` folder (e.g., company policies, notes, research papers)
|
| 47 |
+
|
| 48 |
+
2. **Documents are split** β Large files are broken into smaller, manageable pieces called "chunks" (like cutting a book into individual pages)
|
| 49 |
+
|
| 50 |
+
3. **Chunks become numbers** β Each chunk is converted into a list of numbers (called an "embedding") that captures its meaning. This is done by an **Embedding Model** running on HuggingFace's servers
|
| 51 |
+
|
| 52 |
+
4. **Numbers are stored** β These numerical representations are saved in a **FAISS database** (a fast search engine for numbers)
|
| 53 |
+
|
| 54 |
+
5. **You ask a question** β Your question is also converted into numbers the same way
|
| 55 |
+
|
| 56 |
+
6. **Similar chunks are found** β The system compares your question's numbers with all the chunk numbers to find the closest matches (like finding the most relevant pages)
|
| 57 |
+
|
| 58 |
+
7. **AI writes the answer** β The matching chunks are sent to a **Language Model (LLM)** which reads them and generates a clear, natural-language answer
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
## 4. Key Features
|
| 63 |
+
|
| 64 |
+
### π Custom Knowledge Base
|
| 65 |
+
- Add any `.txt` files to the `knowledge_base` folder
|
| 66 |
+
- Reload anytime using the sidebar button
|
| 67 |
+
- Currently loaded with 6 documents (profile, experience, skills, projects, achievements, goals)
|
| 68 |
+
|
| 69 |
+
### π€ Multiple AI Models
|
| 70 |
+
The app lets you choose from different AI models:
|
| 71 |
+
|
| 72 |
+
| Model | Best For |
|
| 73 |
+
|-------|----------|
|
| 74 |
+
| Mistral 7B Instruct | General-purpose, reliable |
|
| 75 |
+
| Zephyr 7B | Conversational, friendly |
|
| 76 |
+
| Phi-3 Mini | Fast, efficient |
|
| 77 |
+
| Llama 3.2 3B | Meta's latest compact model |
|
| 78 |
+
| Gemma 2 2B | Google's lightweight model |
|
| 79 |
+
|
| 80 |
+
### π Configurable Retrieval
|
| 81 |
+
- **Chunk Size** (500β2000): Controls how big each document piece is
|
| 82 |
+
- **Number of Results** (1β5): How many relevant pieces to retrieve
|
| 83 |
+
|
| 84 |
+
### π Source Citations
|
| 85 |
+
Every answer includes an expandable section showing exactly which document fragments were used β so you can verify the answer.
|
| 86 |
+
|
| 87 |
+
### β‘ 100% Free
|
| 88 |
+
All processing happens via HuggingFace's free Inference API β no paid subscriptions or expensive GPU hardware needed.
|
| 89 |
+
|
| 90 |
+
### π¬ Chat History
|
| 91 |
+
The app remembers your conversation, so you can ask follow-up questions naturally.
|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
## 5. Technology Stack
|
| 96 |
+
|
| 97 |
+
| Component | Technology | Role |
|
| 98 |
+
|-----------|-----------|------|
|
| 99 |
+
| User Interface | **Streamlit** | Creates the web-based chat interface |
|
| 100 |
+
| Document Loading | **LangChain** | Reads and processes text files |
|
| 101 |
+
| Text Splitting | **RecursiveCharacterTextSplitter** | Breaks documents into chunks intelligently |
|
| 102 |
+
| Embeddings | **HuggingFace API** (e.g., all-MiniLM-L6-v2) | Converts text into numerical representations |
|
| 103 |
+
| Vector Database | **FAISS** (Facebook AI Similarity Search) | Stores and searches embeddings efficiently |
|
| 104 |
+
| Answer Generation | **HuggingFace Inference API** | Runs the LLM to generate answers |
|
| 105 |
+
| Environment Mgmt | **python-dotenv** | Manages configuration securely |
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 6. How to Use the Application
|
| 110 |
+
|
| 111 |
+
### First-Time Setup
|
| 112 |
+
1. **Get a free HuggingFace account** at [huggingface.co](https://huggingface.co/join)
|
| 113 |
+
2. **Create a token** at [Settings β Tokens](https://huggingface.co/settings/tokens)
|
| 114 |
+
- Choose **"Fine-grained"** type
|
| 115 |
+
- Enable **"Make calls to Inference Providers"**
|
| 116 |
+
3. **Install dependencies**: `pip install -r requirements.txt`
|
| 117 |
+
4. **Add documents** to the `knowledge_base/` folder
|
| 118 |
+
|
| 119 |
+
### Running the App
|
| 120 |
+
```
|
| 121 |
+
streamlit run app.py
|
| 122 |
+
```
|
| 123 |
+
Then open `http://localhost:8501` in your browser.
|
| 124 |
+
|
| 125 |
+
### Asking Questions
|
| 126 |
+
1. Paste your HuggingFace token in the sidebar
|
| 127 |
+
2. Wait for the knowledge base to load (green β
confirmation)
|
| 128 |
+
3. Type your question in the chat box
|
| 129 |
+
4. View the AI-generated answer and optionally expand source documents
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## 7. Project File Structure
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
ApplicationTest1/
|
| 137 |
+
βββ app.py β Main application (320 lines)
|
| 138 |
+
βββ requirements.txt β Python package dependencies
|
| 139 |
+
βββ .env β Stores your HuggingFace token
|
| 140 |
+
βββ README.md β Quick-start guide
|
| 141 |
+
βββ knowledge_base/ β Your documents go here
|
| 142 |
+
β βββ profile.txt
|
| 143 |
+
β βββ experience.txt
|
| 144 |
+
β βββ skills.txt
|
| 145 |
+
β βββ projects.txt
|
| 146 |
+
β βββ achievements.txt
|
| 147 |
+
β βββ goals.txt
|
| 148 |
+
βββ venv_rag/ β Python virtual environment
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
## 8. Error Handling
|
| 154 |
+
|
| 155 |
+
The application includes user-friendly error handling:
|
| 156 |
+
|
| 157 |
+
| Error | What It Means | Solution |
|
| 158 |
+
|-------|--------------|----------|
|
| 159 |
+
| **403 Forbidden** | Token doesn't have correct permissions | Recreate token with "Inference Providers" enabled |
|
| 160 |
+
| **Model loading** | AI model is starting up on the server | Wait 20β30 seconds and retry |
|
| 161 |
+
| **No documents found** | Knowledge base folder is empty | Add `.txt` files and reload |
|
| 162 |
+
| **Embedding error** | Issue converting text to numbers | Check token and selected model |
|
| 163 |
+
|
| 164 |
+
---
|
| 165 |
+
|
| 166 |
+
## 9. Key Takeaways
|
| 167 |
+
|
| 168 |
+
> [!TIP]
|
| 169 |
+
> **Why RAG matters:** Traditional AI models can "hallucinate" β make up information. RAG solves this by grounding AI answers in your actual documents, making it far more reliable for business and academic use.
|
| 170 |
+
|
| 171 |
+
- **RAG = Search + AI** β Combines document retrieval with AI generation
|
| 172 |
+
- **Your data stays private** β Documents are processed in your session only
|
| 173 |
+
- **Completely free** β No paid APIs, no GPU required
|
| 174 |
+
- **Customizable** β Swap models, tune chunk sizes, change the knowledge base anytime
|
| 175 |
+
- **Transparent** β Always shows which sources were used for each answer
|
| 176 |
+
|
| 177 |
+
---
|
| 178 |
+
|
| 179 |
+
*Report prepared for Makers Lab, SPJIMR β Term 3*
|
README.md
CHANGED
|
@@ -1,73 +1,73 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: RAG Chatbot
|
| 3 |
-
emoji: π€
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: streamlit
|
| 7 |
-
sdk_version: 1.
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
# π€ RAG Chatbot
|
| 14 |
-
|
| 15 |
-
An intelligent chatbot powered by Retrieval Augmented Generation (RAG) that answers questions based on your custom knowledge base.
|
| 16 |
-
|
| 17 |
-
## β¨ Features
|
| 18 |
-
|
| 19 |
-
- π **Custom Knowledge Base**: Upload your own documents (.txt files)
|
| 20 |
-
- π **Smart Retrieval**: Uses FAISS for efficient similarity search
|
| 21 |
-
- π€ **Multiple LLM Options**: Choose from various open-source models
|
| 22 |
-
- π¬ **Chat Interface**: Interactive conversation with context
|
| 23 |
-
- π **Source Citations**: See which documents were used for answers
|
| 24 |
-
- π **100% Free**: Uses HuggingFace's free inference API
|
| 25 |
-
|
| 26 |
-
## π How to Use
|
| 27 |
-
|
| 28 |
-
1. **Get a HuggingFace Token** (free):
|
| 29 |
-
- Visit [HuggingFace Settings](https://huggingface.co/settings/tokens)
|
| 30 |
-
- Create a **Fine-grained** token
|
| 31 |
-
- β
Enable **'Make calls to Inference Providers'**
|
| 32 |
-
- Copy the token
|
| 33 |
-
|
| 34 |
-
2. **Enter Your Token**:
|
| 35 |
-
- Paste it in the sidebar
|
| 36 |
-
|
| 37 |
-
3. **Ask Questions**:
|
| 38 |
-
- The chatbot will answer based on the knowledge base documents
|
| 39 |
-
- View source documents for each answer
|
| 40 |
-
|
| 41 |
-
## π Knowledge Base
|
| 42 |
-
|
| 43 |
-
The knowledge base contains documents that the chatbot uses to answer questions. You can customize it by:
|
| 44 |
-
|
| 45 |
-
1. Adding .txt files to the `knowledge_base/` folder
|
| 46 |
-
2. Clicking "π Reload Knowledge Base" in the sidebar
|
| 47 |
-
|
| 48 |
-
## π οΈ Configuration Options
|
| 49 |
-
|
| 50 |
-
- **Embedding Model**: Choose how text is converted to vectors
|
| 51 |
-
- **LLM Model**: Select the language model for generating answers
|
| 52 |
-
- **Chunk Size**: Control how documents are split
|
| 53 |
-
- **Number of Results**: How many document chunks to retrieve
|
| 54 |
-
|
| 55 |
-
## π Privacy
|
| 56 |
-
|
| 57 |
-
- Your token is only used to call HuggingFace APIs
|
| 58 |
-
- Conversations are not stored
|
| 59 |
-
- Documents remain private to your session
|
| 60 |
-
|
| 61 |
-
## π Troubleshooting
|
| 62 |
-
|
| 63 |
-
**Model is loading**: Wait 20-30 seconds and try again
|
| 64 |
-
**Token error**: Make sure 'Make calls to Inference Providers' is enabled
|
| 65 |
-
**No documents found**: Add .txt files to the knowledge_base folder
|
| 66 |
-
|
| 67 |
-
## π License
|
| 68 |
-
|
| 69 |
-
Apache 2.0
|
| 70 |
-
|
| 71 |
-
---
|
| 72 |
-
|
| 73 |
Built with β€οΈ using Streamlit, LangChain, and HuggingFace
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: RAG Chatbot
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.28.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# π€ RAG Chatbot
|
| 14 |
+
|
| 15 |
+
An intelligent chatbot powered by Retrieval Augmented Generation (RAG) that answers questions based on your custom knowledge base.
|
| 16 |
+
|
| 17 |
+
## β¨ Features
|
| 18 |
+
|
| 19 |
+
- π **Custom Knowledge Base**: Upload your own documents (.txt files)
|
| 20 |
+
- π **Smart Retrieval**: Uses FAISS for efficient similarity search
|
| 21 |
+
- π€ **Multiple LLM Options**: Choose from various open-source models
|
| 22 |
+
- π¬ **Chat Interface**: Interactive conversation with context
|
| 23 |
+
- π **Source Citations**: See which documents were used for answers
|
| 24 |
+
- π **100% Free**: Uses HuggingFace's free inference API
|
| 25 |
+
|
| 26 |
+
## π How to Use
|
| 27 |
+
|
| 28 |
+
1. **Get a HuggingFace Token** (free):
|
| 29 |
+
- Visit [HuggingFace Settings](https://huggingface.co/settings/tokens)
|
| 30 |
+
- Create a **Fine-grained** token
|
| 31 |
+
- β
Enable **'Make calls to Inference Providers'**
|
| 32 |
+
- Copy the token
|
| 33 |
+
|
| 34 |
+
2. **Enter Your Token**:
|
| 35 |
+
- Paste it in the sidebar
|
| 36 |
+
|
| 37 |
+
3. **Ask Questions**:
|
| 38 |
+
- The chatbot will answer based on the knowledge base documents
|
| 39 |
+
- View source documents for each answer
|
| 40 |
+
|
| 41 |
+
## π Knowledge Base
|
| 42 |
+
|
| 43 |
+
The knowledge base contains documents that the chatbot uses to answer questions. You can customize it by:
|
| 44 |
+
|
| 45 |
+
1. Adding .txt files to the `knowledge_base/` folder
|
| 46 |
+
2. Clicking "π Reload Knowledge Base" in the sidebar
|
| 47 |
+
|
| 48 |
+
## π οΈ Configuration Options
|
| 49 |
+
|
| 50 |
+
- **Embedding Model**: Choose how text is converted to vectors
|
| 51 |
+
- **LLM Model**: Select the language model for generating answers
|
| 52 |
+
- **Chunk Size**: Control how documents are split
|
| 53 |
+
- **Number of Results**: How many document chunks to retrieve
|
| 54 |
+
|
| 55 |
+
## π Privacy
|
| 56 |
+
|
| 57 |
+
- Your token is only used to call HuggingFace APIs
|
| 58 |
+
- Conversations are not stored
|
| 59 |
+
- Documents remain private to your session
|
| 60 |
+
|
| 61 |
+
## π Troubleshooting
|
| 62 |
+
|
| 63 |
+
**Model is loading**: Wait 20-30 seconds and try again
|
| 64 |
+
**Token error**: Make sure 'Make calls to Inference Providers' is enabled
|
| 65 |
+
**No documents found**: Add .txt files to the knowledge_base folder
|
| 66 |
+
|
| 67 |
+
## π License
|
| 68 |
+
|
| 69 |
+
Apache 2.0
|
| 70 |
+
|
| 71 |
+
---
|
| 72 |
+
|
| 73 |
Built with β€οΈ using Streamlit, LangChain, and HuggingFace
|