Upload a PDF · Build a vector database · Chat with your document
PDF RAG Assistant is a Retrieval-Augmented Generation (RAG) app that lets you upload any PDF, index it into a vector database, and ask natural-language questions grounded strictly in the document's content — with source chunks shown for every answer.
- 📄 PDF Upload & Indexing — drag-and-drop a PDF and build a vector database in one click
- 🔍 MMR-based Retrieval — balances relevance and diversity when fetching context chunks
- 💬 Chat Interface — ask follow-up questions with full conversation history
- 📎 Source Transparency — every answer shows the exact document chunks it was grounded in
- 🚫 Hallucination Guardrail — the assistant explicitly says when an answer isn't in the document
- ⏱️ Batched Embeddings — chunks are embedded in small batches with a progress bar, so large PDFs don't hit API rate limits
- 🖥️ Dual Interface — Streamlit web app + standalone CLI script
- 🎨 Custom dark-themed UI
| Layer | Technology |
|---|---|
| Frontend | Streamlit |
| LLM Orchestration | LangChain (LCEL) |
| LLM Provider | Cohere (command-a-03-2025) |
| Embeddings | Cohere Embeddings (embed-english-v3.0) |
| Vector Store | ChromaDB (persistent, MMR search) |
| Document Loading | pypdf |
| Environment Config | python-dotenv |
- Python 3.10, 3.11, or 3.12 (the newest Python releases may lack prebuilt wheels for some dependencies)
- Cohere API key — get a free trial key at dashboard.cohere.com/api-keys
git clone https://github.com/venom312004/PDF-RAG-Assistant.git
cd PDF-RAG-Assistant
# create and activate a virtual environment (Python 3.11 or 3.12)
py -3.11 -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# install dependencies
python -m pip install -r requirements.txtTip: Keep your virtual environment outside cloud-synced folders such as OneDrive or Google Drive. Syncing thousands of small package files can corrupt the environment.
Create a .env file in the project root:
COHERE_API_KEY=your_cohere_api_keystreamlit run app.pyBuild the vector database first, then start the chat:
python create_database.py
python main.pyPDF-RAG-Assistant/
├── app.py # Streamlit web UI — upload, index, and chat
├── create_database.py # CLI — load PDF, chunk, embed, and store in ChromaDB
├── main.py # CLI — terminal-based Q&A over the stored database
├── requirements.txt
├── .env # API keys (not committed)
└── .gitignore
- Upload a PDF through the Streamlit UI
- Document is loaded with
PyPDFLoaderand split into ~1000-character chunks (100-char overlap) - Chunks are embedded in batches via Cohere Embeddings and stored in ChromaDB
- On query, an MMR retriever (
k=4,fetch_k=10) pulls the most relevant and diverse chunks - Retrieved context + question are passed to
command-a-03-2025, which answers strictly from the provided context - Source chunks are displayed alongside the answer for full transparency
- Cohere trial key rate limits: the free trial key is rate-limited and has a monthly call quota. Very large PDFs or many uploads in a short time may return a
429 TooManyRequestserror. Wait a minute and retry, or use a production key. - Index is not persisted on cloud hosting: on Streamlit Community Cloud the local
chroma_dbfolder resets when the app restarts, so the PDF needs to be re-indexed after a restart. - English-focused embeddings:
embed-english-v3.0is tuned for English. For other languages, switch toembed-multilingual-v3.0(and rebuild the database — embeddings from different models are not interchangeable).
This project is open source and available under the MIT License.