A simple RAG (Retrieval-Augmented Generation) chatbot built with Streamlit, LangChain, and Google Gemini that allows you to upload a PDF and ask questions about its contents.
- 📂 Upload any PDF document
- ✂️ Automatically splits the document into chunks
- 🔍 Creates embeddings using Google's Gemini Embedding model
- 🗂️ Stores embeddings in an in-memory vector database
- 💬 Chat interface powered by Streamlit
- 🤖 Answers questions using Gemini Flash with Retrieval-Augmented Generation (RAG)
- Python
- Streamlit
- LangChain
- Google Gemini API
- PyPDFLoader
- RecursiveCharacterTextSplitter
- InMemoryVectorStore
.
├── app.py
├── .env
├── .gitignore
├── requirements.txt
├── README.md
└── uploaded_document.pdf # Generated after upload
git clone https://github.com/your-username/pdf-bot.git
cd pdf-botMac/Linux
python3 -m venv venv
source venv/bin/activateWindows
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root.
GOOGLE_API_KEY=your_google_api_keystreamlit run app.pyOpen the local URL shown in the terminal (usually http://localhost:8501).
- Upload a PDF.
- The PDF is loaded using
PyPDFLoader. - The document is split into smaller chunks.
- Gemini Embeddings generate vector representations of each chunk.
- The vectors are stored in an in-memory vector database.
- When a question is asked:
- The most relevant chunks are retrieved using similarity search.
- Retrieved context and the user's question are sent to Gemini Flash.
- The generated answer is displayed in the chat interface.
Upload PDF
│
▼
Load PDF
│
▼
Split into Chunks
│
▼
Generate Embeddings
│
▼
Store in Vector Database
│
▼
User asks Question
│
▼
Similarity Search
│
▼
Gemini Flash
│
▼
Answer
- streamlit
- python-dotenv
- langchain
- langchain-community
- langchain-google-genai
- pypdf
Install them using:
pip install -r requirements.txt- Support multiple PDF uploads
- Persistent vector database (FAISS or Chroma)
- Display source citations/pages
- Conversation memory
- PDF highlighting for retrieved answers
- Support for DOCX and TXT files
- Better prompt engineering
- Deploy on Streamlit Cloud
Made with ❤️ using Streamlit, LangChain, and Google Gemini.