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.
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
- PDF ingestion pipeline
- Automatic text extraction
- Intelligent text chunking
- Metadata preservation
- Semantic search using embeddings
- Pinecone vector database integration
- Similarity-based document retrieval
- Context-aware information extraction
- Google Gemini 2.5 Flash integration
- Context-grounded response generation
- Follow-up conversation support
- Source-aware answering
- Interactive Streamlit interface
- Chat history tracking
- Source page references
- Real-time response generation
PDF Documents
β
βΌ
Document Loader
(PyPDFLoader)
β
βΌ
Text Chunking
(RecursiveCharacterTextSplitter)
β
βΌ
Embedding Generation
(HuggingFace MiniLM)
β
βΌ
Pinecone Vector Database
β
βΌ
Semantic Retrieval
β
βΌ
Gemini LLM
β
βΌ
Final Response
β
βΌ
Streamlit UI
| 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 |
agentic-pdf-rag-chatbot/
β
βββ pdfs/
β βββ dsa.pdf
β
βββ ingest.py
βββ chatbot.py
βββ app.py
βββ .env
βββ requirements.txt
βββ README.md
git clone https://github.com/mithxcode/agentic-pdf-rag-chatbot.git
cd agentic-pdf-rag-chatbotpython -m venv venvActivate:
venv\Scripts\activatepython3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root directory:
GOOGLE_API_KEY=YOUR_GEMINI_API_KEY
PINECONE_API_KEY=YOUR_PINECONE_API_KEYCreate a folder named:
pdfs
Place all PDF files inside the folder:
pdfs/
βββ dsa.pdf
βββ dbms.pdf
βββ os.pdf
βββ cn.pdf
Before using the chatbot, upload document embeddings to Pinecone.
Run:
python ingest.pyExpected Output:
Loading dsa.pdf
Total Pages: 120
Chunks: 231
Upload Complete
This process:
- Loads PDFs
- Extracts text
- Creates chunks
- Generates embeddings
- Stores vectors in Pinecone
Launch the command-line version:
python chatbot.pyExample:
Ask Question:
What is Quick Sort?
Output:
Clear Answer
Important Points
Simple Explanation
Sources:
Page 30
Page 34
Page 35
Start the web interface:
streamlit run app.pyOpen:
http://localhost:8501
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?
User Query
β
βΌ
Generate Query Embedding
β
βΌ
Pinecone Similarity Search
β
βΌ
Retrieve Relevant Chunks
β
βΌ
Build Context
β
βΌ
Gemini LLM
β
βΌ
Generate Answer
β
βΌ
Display Sources
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
- Query Rewriting
- MMR Retrieval
- Context Compression
- Hybrid Search (BM25 + Vector Search)
- Cross Encoder Reranking
- Tool Calling
- Query Planning
- Multi-Step Reasoning
- Reflection Agents
- Autonomous Retrieval
- ChatGPT-style Chat Interface
- Streaming Responses
- PDF Upload Feature
- Dark Mode Support
- Multi-PDF Selection
- User Authentication
- Persistent Chat History
- Analytics Dashboard
- Docker Deployment
- Cloud Hosting
| Feature | Status |
|---|---|
| PDF Processing | β |
| Semantic Search | β |
| Pinecone Integration | β |
| Gemini Integration | β |
| Source Citations | β |
| Streamlit UI | β |
| Chat Memory | β |
| Multi-PDF Support | β |
| Query Rewriting | π§ |
| Agentic Workflow | π§ |
| Reranking | π§ |
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
AI Enthusiast | Full Stack Developer | Generative AI Learner
GitHub:
https://github.com/mithxcode
LinkedIn:
https://www.linkedin.com/in/mithileshkumar001
If you found this project useful, consider giving it a star β on GitHub.
Contributions, feature suggestions, and feedback are always welcome.