An end-to-end Retrieval-Augmented Generation (RAG) system built with Python, Google Gemini, and ChromaDB that allows you to ingest any PDF document and ask questions with precise, context-aware answers.
- Universal Document Support: Works with resumes, research papers, textbooks, technical reports, and multi-page PDFs.
- Smart Sliding-Window Chunking: Splits text into coherent, overlapping chunks with paragraph and sentence preservation.
- Fast Batch Vector Embeddings: Uses Google's
gemini-embedding-001model with batching for high speed and rate-limit protection. - Local Persistent Vector Storage: Stores and retrieves document embeddings locally with ChromaDB.
- Context-Aware QA: Answers questions using Google's
gemini-3.6-flashmodel with retrieved source citations. - Cross-Platform & Windows Safe: Configured with UTF-8 console output to prevent terminal encoding crashes.
├── pdf_utils.py # PDF text extraction, normalization, and universal chunking
├── read_pdf.py # Utility to inspect extracted text from a PDF
├── chunk_pdf.py # Utility to inspect generated text chunks
├── embed_test.py # Test script for generating vector embeddings
├── store_chunks.py # Main ingestion script: embeds & stores chunks in ChromaDB
├── ask_question.py # Q&A CLI: queries vector database and answers via Gemini
├── test.py # Basic Gemini API connectivity test
├── requirements.txt # Project dependencies
├── .env.example # Environment variable template
└── .gitignore # Git ignore rules
- Python 3.9+
- A Google Gemini API Key (get one free at Google AI Studio)
-
Clone the repository:
git clone https://github.com/hems705/RAG-based-QA-document.git cd RAG-based-QA-document -
Create and activate a virtual environment:
python -m venv .venv # Windows (PowerShell): .\.venv\Scripts\activate # Linux / macOS: source .venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up your environment variables: Create a
.envfile in the root directory:GEMINI_API_KEY=your_gemini_api_key_here
-
Verify API connectivity:
python test.py
Place your PDF in the project folder or specify its path:
# Ingest by specifying a path:
python store_chunks.py path/to/document.pdf
# Or simply place your PDF in the project folder and run:
python store_chunks.pyAsk specific questions or query the document:
# Ask a specific question:
python ask_question.py What are the key findings discussed in this document?
# Or run without arguments for an automatic summary & key takeaways:
python ask_question.py- Inspect raw extracted text:
python read_pdf.py [document.pdf]
- Inspect text chunking:
python chunk_pdf.py [document.pdf]
- Test embedding generation:
python embed_test.py [document.pdf]
MIT License