A powerful Streamlit application that enables you to upload PDF documents and ask questions about their content using AI-powered Retrieval-Augmented Generation (RAG) technology.
Try it now: https://pdfanalyzerwithrag-ezbzxnaza2ng9lpd9fgf5x.streamlit.app/
Note: You'll need your own Gemini API key to use the live demo.
- PDF Upload & Processing: Upload PDF documents and extract text content
- Intelligent Text Chunking: Automatically splits documents into semantic chunks with overlap
- Vector Embeddings: Creates semantic embeddings using sentence transformers
- Semantic Search: Uses FAISS for efficient similarity search
- AI-Powered Q&A: Leverages Google Gemini models for generating contextual answers
- Multiple Model Support: Choose between different Gemini models (2.0 Flash, 1.5 Pro, 1.5 Flash)
- Interactive UI: Clean, user-friendly interface with suggested questions
- Source Context: View the document chunks used to generate answers
- Session Management: All processing happens in-memory with session state management
The outputs/ folder contains 4 demonstration screenshots showing the complete workflow:
Initial application interface with configuration panel, API key setup, and upload section

PDF processing in progress showing file upload confirmation and loading states
Successfully processed PDF with active Q&A interface and suggested questions
AI-generated response with source context and session information
-
Clone the repository
git clone <your-repo-url> cd pdf-rag-assistant
-
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Get a Gemini API key
- Visit Google AI Studio
- Create a new API key
- Keep it secure for use in the application
-
Start the application
streamlit run app.py
-
Configure the application
- Enter your Gemini API key in the sidebar
- Select your preferred Gemini model
-
Upload and process PDF
- Upload a PDF file using the file uploader
- Click "Process PDF" to extract text and create embeddings
-
Ask questions
- Enable question answering with the checkbox
- Type your question or use suggested questions
- View AI-generated answers with source context
- Text Extraction: PyPDF2 for extracting text from PDF files
- Text Chunking: Smart chunking with sentence boundary detection and overlap
- Embeddings:
all-MiniLM-L6-v2sentence transformer model - Vector Store: FAISS for efficient similarity search
- AI Model: Google Gemini for generating contextual answers
- Frontend: Streamlit for the web interface
- PDF Upload → Text extraction using PyPDF2
- Text Processing → Chunking with overlap and boundary detection
- Embedding Generation → Convert chunks to vector embeddings
- Vector Storage → Store embeddings in FAISS index
- Query Processing → Convert user question to embedding
- Similarity Search → Find relevant document chunks
- Answer Generation → Use Gemini to generate contextual answers
pdf-rag-assistant/
├── app.py # Main Streamlit application
├── requirements.txt # Python dependencies
├── README.md # This file
└── outputs/ # Output screenshots (4 files)
├── 1.jpg # Main interface
├── 2.jpg # PDF processing
├── 3.jpg # Q&A interface
└── 4.jpg # Generated answer
- gemini-2.0-flash-exp: Fastest response, good for quick queries
- gemini-1.5-pro: Most capable, best for complex questions
- gemini-1.5-flash: Balanced speed and capability
- Chunk Size: 1000 characters (configurable in code)
- Chunk Overlap: 200 characters (configurable in code)
- Similar Chunks Retrieved: 5 (configurable in code)
- Embedding Model: all-MiniLM-L6-v2 (cached for performance)
-
PDF Processing Fails
- Ensure the PDF contains readable text (not just images)
- Try with a different PDF file
- Check that the file is not corrupted
-
Slow Embedding Generation
- First-time model loading takes a few minutes
- Subsequent uses are faster due to caching
- Consider using smaller PDF files for testing
-
API Key Issues
- Verify your Gemini API key is valid
- Check that you have remaining quota
- Ensure the key has proper permissions
-
Memory Issues
- For large PDFs, consider splitting them into smaller sections
- The application stores all data in memory during the session
- Restart the application to clear memory if needed
- The embeddings model is cached for better performance
- Use the "Clear Session" button to reset if needed
- Smaller, focused questions often yield better results
- Try rephrasing questions if answers aren't satisfactory
- streamlit: Web application framework
- PyPDF2: PDF text extraction
- google-generativeai: Google Gemini API client
- sentence-transformers: Text embedding generation
- faiss-cpu: Efficient vector similarity search
- numpy: Numerical computations
- torch: PyTorch for transformer models
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google AI for the Gemini API
- Hugging Face for the sentence transformers
- Facebook Research for FAISS
- Streamlit team for the amazing framework
- Support for multiple file formats (DOCX, TXT, etc.)
- Batch processing of multiple PDFs
- Conversation history and chat interface
- Custom embedding model selection
- Document comparison features
- Export functionality for Q&A sessions
- Advanced filtering and search options
Happy Document Analysis! 🎉
For questions or support, please open an issue in the repository.