A powerful PDF question-answering chatbot built with LangChain, Groq, and Gradio. Upload any PDF document and ask questions about its content using advanced RAG (Retrieval-Augmented Generation) technology.
- 📄 Upload and process PDF documents
- 🤖 Ask questions about PDF content using natural language
- 🚀 Fast responses powered by Groq's Mixtral model
- 🎯 Accurate answers using RAG with vector similarity search
- 🖥️ Clean and intuitive web interface with Gradio
- 🔍 MMR (Maximal Marginal Relevance) search for diverse results
- LangChain: Framework for building LLM applications
- Groq: Ultra-fast LLM inference
- HuggingFace Embeddings: Sentence transformers for text embeddings
- ChromaDB: Vector database for efficient similarity search
- Gradio: Web UI framework
- PyPDF: PDF processing
- Python 3.8 or higher
- Groq API key (get it from console.groq.com)
- Clone the repository
git clone <your-repo-url>
cd pdf-chatbot- Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies
pip install gradio langchain-groq langchain-community langchain-core langchain-text-splitters chromadb pypdf sentence-transformers python-dotenv torch- Set up environment variables
Create a .env file in the project root:
touch .envAdd your Groq API key to the .env file:
GROQ_API_KEY=gsk_your_actual_api_key_here
- Add
.envto.gitignore(to keep your API key secure)
echo ".env" >> .gitignore- Run the application
python app.py- Open your browser
Navigate to http://localhost:7860
- Upload and Ask
- Click on the file upload area and select a PDF
- Type your question in the text box
- Click Submit to get your answer
pdf-chatbot/
├── .venv/ # Virtual environment
├── app.py # Main application file
├── .env # Environment variables (API keys)
├── .gitignore # Git ignore file
└── README.md # This file
- Visit console.groq.com
- Sign up or log in
- Navigate to the API Keys section
- Create a new API key
- Copy the key and add it to your
.envfile
- Document Processing: The PDF is loaded and split into chunks
- Embeddings: Text chunks are converted to vector embeddings
- Vector Storage: Embeddings are stored in ChromaDB
- Query Processing: User questions are converted to embeddings
- Retrieval: Similar chunks are retrieved using MMR search
- Generation: Groq's Mixtral model generates answers based on retrieved context
You can modify these parameters in app.py:
- Model: Change
mixtral-8x7b-32768to other Groq models - Temperature: Adjust creativity (0.0-1.0)
- Max Tokens: Control response length
- Chunk Size: Modify document splitting (default: 1000)
- Chunk Overlap: Adjust context continuity (default: 200)
- K value: Number of documents to retrieve (default: 5)
Issue: ModuleNotFoundError
pip install --upgrade pip
pip install -r requirements.txtIssue: API Key Error
- Ensure your
.envfile exists in the project root - Verify the API key is correct
- Check that
python-dotenvis installed
Issue: PDF Not Loading
- Ensure the PDF is not password-protected
- Check that the file is a valid PDF format
- Try with a smaller PDF first
- "What is the main topic of this document?"
- "Can you summarize the key points?"
- "What does the document say about [specific topic]?"
- "Who are the authors mentioned?"
- "What are the conclusions?"
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
- LangChain for the RAG framework
- Groq for lightning-fast LLM inference
- Gradio for the web interface
- HuggingFace for embeddings models
If you encounter any issues or have questions, please open an issue on GitHub.
Made with ❤️ using LangChain and Groq