Transform any document into an interactive AI conversation using RAG (Retrieval Augmented Generation)
Document RAG Assistant is a Streamlit web application that enables you to have intelligent conversations with your document content. Simply upload a PDF or text file, and the app will process the document to create a searchable knowledge base that you can query using natural language.
Try it out here: Document RAG Assistant Live Demo
- π Multi-format Support: Process PDF and text files seamlessly
- π€ Multiple AI Models: Support for various Google Gemini models (2.5 Pro, Flash, 2.0 Flash, etc.)
- π¬ Interactive Chat: Natural language conversation with document content
- π Smart Search: Vector-based similarity search using FAISS
- π Session Management: Chat history, export functionality, and session persistence
- π¨ Modern UI: Clean, responsive Streamlit interface with real-time updates
- π Progress Tracking: Visual feedback during document processing
- π Streaming Responses: Real-time AI response streaming with typing indicators
- π‘οΈ Fallback System: Automatic HuggingFace embeddings if Google quota exceeded
- Frontend: Streamlit
- AI/ML: Google Gemini API, LangChain
- Vector Store: FAISS (Facebook AI Similarity Search)
- Embeddings: Google Generative AI Embeddings
- Document Processing: PyPDFLoader, TextLoader
- Environment: Python 3.11+, Docker support
- Python 3.11 or higher
- Google Gemini API Key (Get one here)
- Internet connection for API access
git clone https://github.com/ZohaibCodez/document-qa-rag-system.git
cd document-qa-rag-system
uv sync
uv venv
# Edit .env and add your Google API key
streamlit run app.py
Open your browser and navigate to http://localhost:8501
Create a .env
file in the root directory:
GOOGLE_API_KEY=your_google_gemini_api_key_here
Alternatively, you can enter your API key directly in the app's sidebar.
gemini-2.5-pro
(Most capable, recommended for complex analysis)gemini-2.5-flash
(Balanced performance and speed)gemini-2.5-flash-lite
(Lightweight and fast)gemini-2.0-flash
(Fast responses, good accuracy)gemini-1.5-pro
(Reliable baseline)gemini-1.5-flash
(Quick processing)
CHUNK_SIZE = 1000 # Text chunk size for processing
CHUNK_OVERLAP = 100 # Overlap between chunks for context
RETRIEVER_K = 4 # Number of similar chunks to retrieve
EMBEDDING_MODEL = "models/gemini-embedding-exp-03-07"
- Enter API Key: Add your Google Gemini API key in the sidebar
- Upload Document: Click "π Upload your document" and select a PDF or TXT file
- Process Document: Click "π Process Document" to extract and index the content
- Start Chatting: Ask questions about the document content in natural language
- Export Chat: Download your conversation history anytime using the sidebar
- PDF:
.pdf
files (text-based, not scanned images) - Text:
.txt
files (plain text documents) - Size Limit: Up to 100MB (recommended: <10MB for optimal performance)
- "What is the main topic of this document?"
- "Summarize the key findings in chapter 3"
- "What does the author say about machine learning?"
- "List all the recommendations mentioned"
- "Explain the methodology used in this research"
- File Types: Currently supports only PDF and TXT formats
- Language: Optimized for English documents
- Processing Time: Large documents (>50 pages) may take longer to process
- API Limits: Subject to Google Gemini API rate limits and quotas
- Scanned PDFs: Does not support OCR for image-based PDFs
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β File Upload βββββΆβ Text Splitter βββββΆβ Embeddings β
β (PDF/TXT) β β (Chunking) β β (Google AI) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Streamlit UI ββββββ Chat Chain ββββββ FAISS Store β
β (Frontend) β β (LangChain) β β (Vector Search) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
ββββββββββββββββββββ
β Gemini Models β
β (Generation AI) β
ββββββββββββββββββββ
# Create .env file with your API key
echo "GOOGLE_API_KEY=your-api-key-here" > .env
# Start the service
docker-compose up -d
# View logs
docker-compose logs -f
# Build image
docker build -t document-qa-rag-system .
# Run container
docker run -p 8501:8501 -e GOOGLE_API_KEY=your_api_key document-qa-rag-system
document-rag-assistant/
β
βββ app.py # Main Streamlit application
β
βββ notebooks/
β βββ rag_demo.ipynb # Beginner-level RAG notebook demo
β
βββ data/ # Sample documents (PDF/TXT)
| βββ Stack vs Heap Memory.txt
| βββ FastAPI Modern Python Web Development.pdf
β
βββ Dockerfile # Container setup
βββ requirements.txt # Python dependencies
βββ .env.example # Example API key file
βββ .gitignore # Git ignore rules
βββ README.md # Project documentation
- Processing Speed: ~2-5 seconds for typical documents (10-50 pages)
- Memory Usage: Optimized vector storage with FAISS
- Accuracy: High precision with 4-chunk retrieval system
- Container Size: ~380MB (optimized Docker image)
- Response Time: Sub-second for most queries
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- 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
# Build development image
docker build -f Dockerfile.dev -t document-rag-dev .
# Run with live reload
docker run -p 8501:8501 -v $(pwd):/app document-rag-dev
- Support for more document formats (DOCX, HTML, Markdown)
- Multi-document conversation capabilities
- OCR support for scanned PDFs
- Advanced filtering and search options
- Integration with cloud storage services (Google Drive, Dropbox)
- API endpoint for programmatic access
- Batch processing for multiple documents
- Custom embedding model options
- Multi-language document support
- Document summarization features
- Large PDF files (>100MB) may cause memory issues
- Some complex PDF layouts may not parse correctly
- API rate limiting may affect performance during peak usage
- Embedded images in PDFs are not processed
"API key not found" error:
- Ensure your Google Gemini API key is correctly set
- Check that the key has proper permissions
Document processing fails:
- Verify the document format is supported (PDF/TXT)
- Ensure the file is not corrupted or password-protected
Slow processing:
- Try using a smaller document or different model
- Check your internet connection
Out of memory:
- Reduce document size or restart the application
- For Docker: increase memory limits
This project is licensed under the MIT License - see the LICENSE file for details.
- Streamlit for the amazing web framework
- LangChain for RAG implementation tools
- Google AI for Gemini API access
- FAISS for efficient vector similarity search
- PyPDFLoader for PDF processing
If you encounter any issues or have questions:
- Open an Issue
- Check existing issues for solutions
- Review the troubleshooting section above
- Contact: itxlevicodez@gmail.com
β Star this repository if you found it helpful!
Built with π€ using Streamlit and Google Gemini AI