Skip to content

riyaz-raz/rag_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RAG Document Q&A System with Gemini AI

Python 3.8+ License: MIT

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.

Features

  • 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

Architecture

The system follows a standard RAG pipeline:

  1. User submits a question
  2. Question is converted to a vector embedding
  3. Similar documents are retrieved from ChromaDB
  4. Retrieved context is combined with the question
  5. Gemini AI generates a response based on the context

Project Structure

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

Quick Start

Prerequisites

Installation

  1. Clone the repository
git clone https://github.com/yourusername/rag-gemini-document-qa.git
cd rag-gemini-document-qa
  1. Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up environment variables
echo "GEMINI_API_KEY=your_gemini_api_key_here" > .env
  1. Add your documents
# Place PDF or TXT files in the docs/ folder
cp /path/to/your/document.pdf docs/

Running the Application

python src/app.py

Or from the project root:

python -m src.app

Example Usage

πŸš€ 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!

Technologies Used

  • 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

Dependencies

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

Configuration

Environment Variables

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

Troubleshooting

Common Issues

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.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgments

  • Google for the Gemini API
  • LangChain team for the amazing framework
  • ChromaDB team for the vector database

Support

If you find this project helpful, please give it a star on GitHub!


Built with Python and Gemini AI

About

πŸ“š RAG (Retrieval-Augmented Generation) system with Google Gemini. Load documents, create vector embeddings, and ask questions with context-aware responses.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages