Skip to content

About

RAG-powered PDF assistant — upload a PDF, build a ChromaDB vector index, and chat with your document using Cohere + LangChain. Includes both Streamlit UI and CLI versions.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

🧠 PDF RAG Assistant

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.


🔗 Links


✨ Features

  • 📄 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

🛠️ Tech Stack

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

🚀 Getting Started

Prerequisites

  • 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

Installation

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.txt

Tip: Keep your virtual environment outside cloud-synced folders such as OneDrive or Google Drive. Syncing thousands of small package files can corrupt the environment.

Environment Variables

Create a .env file in the project root:

COHERE_API_KEY=your_cohere_api_key

Run — Web UI

streamlit run app.py

Run — CLI Version

Build the vector database first, then start the chat:

python create_database.py
python main.py

📁 Project Structure

PDF-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

🧭 How It Works

  1. Upload a PDF through the Streamlit UI
  2. Document is loaded with PyPDFLoader and split into ~1000-character chunks (100-char overlap)
  3. Chunks are embedded in batches via Cohere Embeddings and stored in ChromaDB
  4. On query, an MMR retriever (k=4, fetch_k=10) pulls the most relevant and diverse chunks
  5. Retrieved context + question are passed to command-a-03-2025, which answers strictly from the provided context
  6. Source chunks are displayed alongside the answer for full transparency

⚠️ Known Limitations

  • 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 TooManyRequests error. Wait a minute and retry, or use a production key.
  • Index is not persisted on cloud hosting: on Streamlit Community Cloud the local chroma_db folder resets when the app restarts, so the PDF needs to be re-indexed after a restart.
  • English-focused embeddings: embed-english-v3.0 is tuned for English. For other languages, switch to embed-multilingual-v3.0 (and rebuild the database — embeddings from different models are not interchangeable).

📄 License

This project is open source and available under the MIT License.


🙌 Acknowledgements

About

RAG-powered PDF assistant — upload a PDF, build a ChromaDB vector index, and chat with your document using Cohere + LangChain. Includes both Streamlit UI and CLI versions.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages