Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG·Chat — Document Q&A Chatbot

A Retrieval-Augmented Generation (RAG) chatbot that lets you upload any PDF and ask questions about it. Answers are grounded in the document's content — not the model's general knowledge.

Built with Python, LangChain, FAISS, Flask, and the Gemini API.


How It Works

  1. Upload — A PDF is split into overlapping text chunks using RecursiveCharacterTextSplitter
  2. Embed — Each chunk is converted into a vector embedding via Gemini's embedding model
  3. Index — Embeddings are stored in a FAISS similarity index for fast retrieval
  4. Retrieve — On a question, the top-k most relevant chunks are fetched from the index
  5. Generate — Retrieved chunks are injected into a grounded prompt sent to Gemini, which returns an answer based strictly on the document

Architecture

The backend follows an object-oriented design with three domain classes, each with a single responsibility:

DocumentLoader       →  loads a PDF and splits it into chunks
VectorStoreService   →  embeds chunks and builds/queries the FAISS index
RAGChatbot           →  orchestrates retrieval + LLM generation

Flask exposes two REST endpoints:

  • POST /upload — accepts a PDF, indexes it
  • POST /ask — accepts a question, returns a grounded answer

Project Structure

rag-chatbot/
├── application.py          # Flask app + domain classes
├── requirements.txt
├── .env.example
├── static/
│   └── css/
│       └── style.css
├── templates/
│   └── home.html
└── tests/
    ├── conftest.py         # fixtures + mock pipeline
    └── test_application.py # 8-case pytest suite

Tests

The test suite has 8 cases across 4 classes, with all external dependencies (Gemini API, FAISS, PDF parsing) replaced by monkeypatched fakes. This means tests run instantly, offline, and without any API key — only Flask routing and orchestration logic is under test.

pytest tests/ -v

Test classes:

  • TestRoutes — verifies HTTP status codes and error shapes for all endpoints
  • TestUploadFlow — checks that upload triggers indexing and loads the retriever
  • TestAskFlow — covers ask before/after upload, JSON and form-encoded input
  • TestDocumentLoaderUnit — unit test for the loader's chunking output

Setup

1. Clone and install dependencies

git clone https://github.com/MeghaMuskan/rag-chatbot.git
cd rag-chatbot
pip install -r requirements.txt

2. Add your Gemini API key

cp .env.example .env
# Edit .env and add your key:
# GOOGLE_API_KEY=your_key_here

3. Run the app

python application.py

Visit http://localhost:5000, upload a PDF, and start asking questions.


Tech Stack

Layer Technology
Language Python 3
Web framework Flask
LLM Gemini 2.5 Flash (via LangChain)
Embeddings Gemini Embedding 001
Vector store FAISS
PDF parsing PyPDF + LangChain
Testing pytest + monkeypatch

Resume Context

"Designed and deployed a RAG document Q&A chatbot (LangChain · FAISS · Gemini API) with a 3-class OOP architecture separating document loading, vector indexing, and LLM orchestration; validated Flask routing logic via an 8-case pytest suite using monkeypatched fakes to eliminate external API dependencies."


Megha Muskan

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages