Spaces:
Sleeping

File size: 6,143 Bytes
1574054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
---
title: QueryVault
emoji: ๐Ÿ’ฌ
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: "5.0.1"
python_version: "3.11"
app_file: app.py
pinned: false
license: mit
---

# ๐Ÿ“„ QueryVault โ€” PDF Question Answering Bot

> Ask questions about any PDF document and get intelligent, context-aware answers powered by **Groq API (Llama-3.3 70B Instruct)**, **LangChain RAG**, and an **ephemeral ChromaDB**.

![Python](https://img.shields.io/badge/Python-3.11-blue?logo=python)
![LangChain](https://img.shields.io/badge/LangChain-RAG-green)
![Groq](https://img.shields.io/badge/Groq-API-orange)
![Gradio](https://img.shields.io/badge/UI-Gradio-orange)
![License](https://img.shields.io/badge/License-MIT-lightgrey)

๐Ÿš€ **Live Demo:** [Try QueryVault on Hugging Face Spaces!](https://huggingface.co/spaces/Padmini1/queryvault)

---

## ๐Ÿง  How It Works

QueryVault implements a full **Retrieval-Augmented Generation (RAG)** pipeline:

![QueryVault Detailed Workflow](assets/workflow.png)


### ASCII Representation:
```
PDF Upload
    โ”‚
    โ–ผ
PyPDFLoader  โ”€โ”€โ”€โ”€ loads raw text from all pages
    โ”‚
    โ–ผ
RecursiveCharacterTextSplitter  โ”€โ”€โ”€โ”€ splits into ~1000-char chunks
    โ”‚
    โ–ผ
HuggingFace Local Embeddings  โ”€โ”€โ”€โ”€ converts each chunk to a vector
    โ”‚
    โ–ผ
ChromaDB  โ”€โ”€โ”€โ”€ stores and indexes all vectors in-memory (per PDF)
    โ”‚
    โ–ผ
User Question โ”€โ”€โ–บ similarity search โ”€โ”€โ–บ top-3 relevant chunks retrieved
    โ”‚
    โ–ผ
Llama-3.3 70B Instruct (ChatGroq)  โ”€โ”€โ”€โ”€ reads context + question โ†’ generates answer
    โ”‚
    โ–ผ
Gradio UI  โ”€โ”€โ”€โ”€ displays the answer to the user
```

---

## ๐Ÿ—‚๏ธ Project Structure

```
queryvault/
โ”‚
โ”œโ”€โ”€ app.py                  # Gradio web interface โ€” run this to start the app
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ qabot.py            # Full RAG pipeline: loader โ†’ splitter โ†’ embedder โ†’ retriever โ†’ LLM โ†’ chain
โ”‚
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ DECISION_STRUCTURE.md   # Full design decisions explained in plain English
โ”‚
โ”œโ”€โ”€ requirements.txt        # All Python dependencies
โ”œโ”€โ”€ .env.example            # Credential template (rename to .env and fill in)
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md
```

---

## โš™๏ธ Setup & Installation

### 1. Clone the repository

```bash
git clone https://github.com/YOUR_USERNAME/queryvault.git
cd queryvault
```

### 2. Create a virtual environment

```bash
python -m venv venv

# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate
```

### 3. Install dependencies

```bash
pip install -r requirements.txt
```

### 4. Add your Groq API credentials

To run this app locally, you need a free API key from Groq:

1. Create a file named `.env` in the root folder.
2. Open the `.env` file and add the following lines:

```env
GROQ_API_KEY=your_groq_api_key
```

> **How to get a free key:**
> 1. Sign up at [console.groq.com](https://console.groq.com/)
> 2. Go to API Keys and generate a new key

### 5. Run the app

```bash
python app.py
```

Open `http://127.0.0.1:7860` in your browser.

---

## ๐Ÿ–ฅ๏ธ Usage

1. Click **Upload PDF** and select any PDF document.
2. Type your question in the **Your Question** box.
3. Click **Get Answer**.
4. The bot retrieves relevant sections from your document and generates a clear answer.

---

## ๐ŸŒ Sharing & Deployment

### Temporary Public Link (The Easiest Way)
Because this app uses Gradio, you don't even need to deploy it to share it with your friends or recruiters! 
When you run `python app.py` on your computer, Gradio automatically generates a temporary public URL (e.g., `https://1234abcd.gradio.live`). 
- Simply copy that `gradio.live` link from your terminal and send it to anyone!
- *Note: This link only works while the terminal is actively running on your PC.*

### Permanent Free Deployment (Hugging Face Spaces)
If you want the app to be available 24/7 without keeping your computer on, you can deploy it for free using Hugging Face:
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces) and create a free account.
2. Click **Create new Space**.
3. Enter a Space name, choose **Gradio** as the Space SDK, and click Create.
4. In the Settings tab of your new Space, go to **Variables and secrets**. Add your `.env` variable as a **Secret** (`GROQ_API_KEY`).
5. Upload all the files from this repository (except `venv` and `.env`) directly into the "Files" tab of your Space.
6. The Space will automatically build and launch your app permanently!

---

## ๐Ÿงฉ Component Decisions

| Component | Choice | Why |
|---|---|---|
| Document Loader | `PyPDFLoader` | Handles multi-page PDFs reliably |
| Text Splitter | `RecursiveCharacterTextSplitter` | Preserves context at chunk boundaries |
| Embedding Model | HuggingFace `all-MiniLM-L6-v2` | Optimized for semantic similarity; runs locally for free |
| Vector Database | ChromaDB (In-Memory) | Lightweight, completely isolates each PDF upload |
| LLM | Llama-3.3 70B Instruct | State-of-the-art instruction-following; powerful reasoning |
| Orchestration | LangChain | Clean pipeline abstraction, easy to extend |
| UI | Gradio | Zero-config web app, file upload built-in |

---

## ๐Ÿ“Š Performance (on structured PDFs)

| Metric | Score |
|---|---|
| Exact Match Rate | 97% |
| F1 Score | 0.9862 |
| Semantic Similarity | 0.9936 |
| Avg. Response Time | < 3 seconds |

---

## ๐Ÿ”ฎ Future Enhancements

- [ ] Support for DOCX and TXT file formats
- [ ] Multi-document querying
- [ ] Conversation memory (multi-turn chat)
- [ ] Voice input / output (accessibility)
- [ ] Multilingual support
- [ ] Cloud deployment (HuggingFace Spaces / AWS)
- [ ] User feedback loop for continuous improvement

---

## ๐Ÿ“š Tech Stack

- [LangChain](https://docs.langchain.com) โ€” RAG pipeline orchestration
- [Groq](https://groq.com/) โ€” Lightning-fast LLM inference
- [ChromaDB](https://www.trychroma.com) โ€” Vector database
- [Gradio](https://www.gradio.app) โ€” Web UI
- [PyPDF](https://pypdf.readthedocs.io) โ€” PDF parsing

---

## ๐Ÿ“„ License

MIT License โ€” see [LICENSE](LICENSE) for details.