Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Agentic PDF RAG Chatbot

An advanced Retrieval-Augmented Generation (RAG) application that enables users to interact with PDF documents using natural language. The system leverages semantic search, vector embeddings, and Large Language Models (LLMs) to provide accurate, context-aware answers directly from uploaded PDF content.

Built with LangChain, Pinecone, Hugging Face Embeddings, Google Gemini, and Streamlit.


πŸ“– Overview

Traditional chatbots often generate responses based solely on their pre-trained knowledge, which may result in outdated or inaccurate answers. This project implements a Retrieval-Augmented Generation (RAG) architecture, allowing the chatbot to retrieve relevant information from PDF documents before generating responses.

The application:

  • Extracts content from PDF files
  • Splits documents into manageable chunks
  • Converts text into vector embeddings
  • Stores embeddings in Pinecone Vector Database
  • Retrieves relevant chunks using semantic search
  • Uses Gemini LLM to generate accurate responses
  • Displays source references for transparency

✨ Features

Document Processing

  • PDF ingestion pipeline
  • Automatic text extraction
  • Intelligent text chunking
  • Metadata preservation

Retrieval System

  • Semantic search using embeddings
  • Pinecone vector database integration
  • Similarity-based document retrieval
  • Context-aware information extraction

AI-Powered Question Answering

  • Google Gemini 2.5 Flash integration
  • Context-grounded response generation
  • Follow-up conversation support
  • Source-aware answering

User Experience

  • Interactive Streamlit interface
  • Chat history tracking
  • Source page references
  • Real-time response generation

πŸ—οΈ System Architecture

PDF Documents
      β”‚
      β–Ό
Document Loader
(PyPDFLoader)
      β”‚
      β–Ό
Text Chunking
(RecursiveCharacterTextSplitter)
      β”‚
      β–Ό
Embedding Generation
(HuggingFace MiniLM)
      β”‚
      β–Ό
Pinecone Vector Database
      β”‚
      β–Ό
Semantic Retrieval
      β”‚
      β–Ό
Gemini LLM
      β”‚
      β–Ό
Final Response
      β”‚
      β–Ό
Streamlit UI

πŸ› οΈ Technology Stack

Category Technology
Programming Language Python
Framework LangChain
Vector Database Pinecone
Embeddings HuggingFace MiniLM
Large Language Model Gemini 2.5 Flash
User Interface Streamlit
PDF Processing PyPDF
Environment Management python-dotenv

πŸ“‚ Project Structure

agentic-pdf-rag-chatbot/
β”‚
β”œβ”€β”€ pdfs/
β”‚   └── dsa.pdf
β”‚
β”œβ”€β”€ ingest.py
β”œβ”€β”€ chatbot.py
β”œβ”€β”€ app.py
β”œβ”€β”€ .env
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Installation Guide

1. Clone the Repository

git clone https://github.com/mithxcode/agentic-pdf-rag-chatbot.git

cd agentic-pdf-rag-chatbot

2. Create Virtual Environment

Windows

python -m venv venv

Activate:

venv\Scripts\activate

Linux / macOS

python3 -m venv venv

source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

πŸ”‘ Environment Variables

Create a .env file in the project root directory:

GOOGLE_API_KEY=YOUR_GEMINI_API_KEY

PINECONE_API_KEY=YOUR_PINECONE_API_KEY

πŸ“„ Adding PDF Documents

Create a folder named:

pdfs

Place all PDF files inside the folder:

pdfs/
β”œβ”€β”€ dsa.pdf
β”œβ”€β”€ dbms.pdf
β”œβ”€β”€ os.pdf
└── cn.pdf

πŸ“₯ Indexing Documents

Before using the chatbot, upload document embeddings to Pinecone.

Run:

python ingest.py

Expected Output:

Loading dsa.pdf

Total Pages: 120

Chunks: 231

Upload Complete

This process:

  1. Loads PDFs
  2. Extracts text
  3. Creates chunks
  4. Generates embeddings
  5. Stores vectors in Pinecone

πŸ€– Running the Terminal Chatbot

Launch the command-line version:

python chatbot.py

Example:

Ask Question:

What is Quick Sort?

Output:

Clear Answer

Important Points

Simple Explanation

Sources:
Page 30
Page 34
Page 35

🌐 Running the Streamlit Web Application

Start the web interface:

streamlit run app.py

Open:

http://localhost:8501

πŸ’¬ Example Questions

What is Quick Sort?

Explain Binary Search Tree.

What are the advantages of AVL Trees?

Difference between Stack and Queue.

Explain Heap Sort with example.

What is Dynamic Programming?

πŸ” Retrieval-Augmented Generation Workflow

User Query
     β”‚
     β–Ό
Generate Query Embedding
     β”‚
     β–Ό
Pinecone Similarity Search
     β”‚
     β–Ό
Retrieve Relevant Chunks
     β”‚
     β–Ό
Build Context
     β”‚
     β–Ό
Gemini LLM
     β”‚
     β–Ό
Generate Answer
     β”‚
     β–Ό
Display Sources

πŸ“š Source Attribution

The chatbot provides document transparency by displaying:

  • Source PDF file
  • Referenced page numbers
  • Retrieved document chunks

Example:

Files:
β€’ dsa.pdf

Pages:
β€’ Page 30
β€’ Page 34
β€’ Page 35

πŸš€ Future Enhancements

Advanced Retrieval

  • Query Rewriting
  • MMR Retrieval
  • Context Compression
  • Hybrid Search (BM25 + Vector Search)
  • Cross Encoder Reranking

Agentic AI Features

  • Tool Calling
  • Query Planning
  • Multi-Step Reasoning
  • Reflection Agents
  • Autonomous Retrieval

User Experience

  • ChatGPT-style Chat Interface
  • Streaming Responses
  • PDF Upload Feature
  • Dark Mode Support
  • Multi-PDF Selection

Production Features

  • User Authentication
  • Persistent Chat History
  • Analytics Dashboard
  • Docker Deployment
  • Cloud Hosting

πŸ“Š Current Capabilities

Feature Status
PDF Processing βœ…
Semantic Search βœ…
Pinecone Integration βœ…
Gemini Integration βœ…
Source Citations βœ…
Streamlit UI βœ…
Chat Memory βœ…
Multi-PDF Support βœ…
Query Rewriting 🚧
Agentic Workflow 🚧
Reranking 🚧

🎯 Learning Outcomes

This project demonstrates practical experience with:

  • Retrieval-Augmented Generation (RAG)
  • Vector Databases
  • Semantic Search
  • Embedding Models
  • Large Language Models
  • LangChain Framework
  • Streamlit Applications
  • AI-Powered Knowledge Systems

πŸ‘¨β€πŸ’» Author

Mithilesh Kumar

AI Enthusiast | Full Stack Developer | Generative AI Learner

GitHub:
https://github.com/mithxcode

LinkedIn:
https://www.linkedin.com/in/mithileshkumar001


🌟 Support

If you found this project useful, consider giving it a star ⭐ on GitHub.

Contributions, feature suggestions, and feedback are always welcome.


About

An Advanced PDF RAG Chatbot built using Pinecone, Gemini, HuggingFace Embeddings, LangChain and Streamlit for intelligent document question answering.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages