Skip to content

Repository files navigation

RAG-based Document QA Assistant

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.


Features

  • 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-001 model 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-flash model with retrieved source citations.
  • Cross-Platform & Windows Safe: Configured with UTF-8 console output to prevent terminal encoding crashes.

Project Structure

├── 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

Prerequisites


Setup & Installation

  1. Clone the repository:

    git clone https://github.com/hems705/RAG-based-QA-document.git
    cd RAG-based-QA-document
  2. Create and activate a virtual environment:

    python -m venv .venv
    # Windows (PowerShell):
    .\.venv\Scripts\activate
    # Linux / macOS:
    source .venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up your environment variables: Create a .env file in the root directory:

    GEMINI_API_KEY=your_gemini_api_key_here
  5. Verify API connectivity:

    python test.py

Usage

1. Ingest a PDF into ChromaDB

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.py

2. Ask Questions

Ask 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

3. Inspection Tools (Optional)

  • 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]

License

MIT License

About

A RAG-based AI Document Q&A Assistant built with Python, ChromaDB, and the Google Gemini API. Designed for semantic document search, context-aware retrieval, and accurate response citation. Features universal PDF support to seamlessly process and query local files.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages