A lightweight Retrieval-Augmented Generation (RAG) system that lets you chat with your documents using Google Gemini AI. Load PDFs and text files, create searchable embeddings, and get intelligent answers with context-aware responses - all using free tier APIs.
- Semantic Search: Find relevant information using vector embeddings
- Gemini AI: Powered by Google's Gemini API (free tier friendly)
- Multiple Formats: Supports PDF and TXT documents
- Context-Aware: Responses grounded in your actual documents
- Free Tier: Works with Gemini's free API tier
- Simple CLI: Easy-to-use interactive command-line interface
- Modular: Clean, extensible code structure
The system follows a standard RAG pipeline:
- User submits a question
- Question is converted to a vector embedding
- Similar documents are retrieved from ChromaDB
- Retrieved context is combined with the question
- Gemini AI generates a response based on the context
rag-system/ βββ src/ β βββ __init__.py β βββ app.py # Main application entry point β βββ kb_loader.py # Document loading & chunking β βββ vector_store.py # ChromaDB vector database setup β βββ rag_chain.py # RAG pipeline orchestration βββ docs/ # Place your documents here β βββ document1.pdf β βββ document2.txt β βββ ... βββ chroma_db/ # Vector database storage (auto-created) βββ .env # Environment variables βββ requirements.txt # Python dependencies βββ README.md # This file
- Python 3.8 or higher
- Google Gemini API Key (Get it here: https://makersuite.google.com/app/apikey)
- Clone the repository
git clone https://github.com/yourusername/rag-gemini-document-qa.git cd rag-gemini-document-qa
- Create a virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Set up environment variables
echo "GEMINI_API_KEY=your_gemini_api_key_here" > .env
- Add your documents
# Place PDF or TXT files in the docs/ folder cp /path/to/your/document.pdf docs/
python src/app.py
Or from the project root:
python -m src.app
π Starting RAG System with Gemini (FREE) β API Key loaded: AIzaSy1234... π Step 1: Loading documents... β Loaded 3 documents, created 247 chunks π’ Step 2: Creating vector database... β Vector database created with 247 embeddings π Step 3: Creating RAG chain... β RAG chain ready! ============================================================ β System ready! Ask questions about your documents. Type 'exit', 'quit', or 'q' to stop ============================================================ β Your question: What are the key features? π€ Thinking... π‘ Answer: Based on the documentation, the key features include... ------------------------------------------------------------ β Your question: exit π Goodbye!
- LangChain - Framework for building LLM applications
- Google Gemini AI - Large language model
- ChromaDB - Vector database for embeddings
- Sentence Transformers - For generating text embeddings
- PyPDF2 - PDF parsing
- python-dotenv - Environment variable management
langchain-google-genai>=1.0.0 langchain-community>=0.2.0 chromadb>=0.4.0 sentence-transformers>=2.2.0 PyPDF2>=3.0.0 python-dotenv>=1.0.0
| Variable | Description | Required |
|---|---|---|
| GEMINI_API_KEY | Your Google Gemini API key | Yes |
| GEMINI_MODEL | Model to use (default: "gemini-pro") | No |
| CHROMA_PERSIST_DIR | ChromaDB storage path (default: "./chroma_db") | No |
| DOCS_DIR | Documents directory (default: "./docs") | No |
Issue: ModuleNotFoundError: No module named 'src'
- Solution: Run from project root or use python -m src.app
Issue: GEMINI_API_KEY not found
- Solution: Ensure .env file is in the project root and contains the API key
Issue: No documents loaded
- Solution: Add PDF/TXT files to the docs/ directory
Issue: Rate limit exceeded
- Solution: Gemini free tier has limits. Wait a few minutes and try again.
Distributed under the MIT License. See LICENSE for more information.
- Google for the Gemini API
- LangChain team for the amazing framework
- ChromaDB team for the vector database
If you find this project helpful, please give it a star on GitHub!
Built with Python and Gemini AI