📄 RAG Chatbot using LangChain, ChromaDB & Google Gemini
A production-oriented Retrieval-Augmented Generation (RAG) application built using LangChain , ChromaDB , Hugging Face Embeddings , and Google Gemini . The project is designed with a modular architecture that separates every stage of the RAG pipeline, making it scalable, reusable, and easy to maintain.
Table of Contents
Project Overview
Key Features
Complete Architecture
RAG Processing Chain
Project Structure
Module Responsibilities
Technologies Used
Workflow
Software Engineering Practices
Unique Features
Current Limitations
Future Roadmap
Production Architecture
Installation
Running the Project
Project Overview
This project allows users to upload PDF documents, automatically extract and split their contents into semantic chunks, convert those chunks into vector embeddings, store them in ChromaDB, retrieve the most relevant chunks for a user query, and finally generate grounded answers using Google Gemini.
Unlike many beginner RAG implementations, this project is intentionally modular. Every stage of the pipeline has its own dedicated module, allowing each component to be independently developed, tested, and replaced.
Key Features
PDF Upload Interface
Automatic PDF Parsing
Recursive Text Chunking
Metadata Cleaning
Hugging Face Local Embeddings (BAAI/bge-small-en-v1.5)
Persistent ChromaDB Storage
Semantic Similarity Search
Prompt Engineering
Google Gemini Answer Generation
Streamlit Interface
Command Line Interface
Configurable Chunk Size & Overlap
Modular Design
Complete Architecture
1 USER
2 │
3 ┌────────────┴───────────────┐
4 │ │
5 ▼ ▼
6 Upload PDF Ask Question
7 │ │
8 ▼ ▼
9 Streamlit UI Streamlit UI
10 │ │
11 ├────────────────────────────┤
12 │
13 ▼
14 document_loader.py
15 │
16 ▼
17 spliter.py
18 │
19 ▼
20 Metadata Cleaning
21 │
22 ▼
23 embedding.py
24 │
25 ▼
26 HuggingFace Embeddings
27 │
28 ▼
29 Persistent ChromaDB
30 │
31 ▼
32 retrieval.py
33 │
34 ▼
35 Retrieve Top-K Chunks
36 │
37 ▼
38 rag_chain.py
39 │
40 ▼
41 Prompt Construction
42 │
43 ▼
44 Google Gemini
45 │
46 ▼
47 Context-Aware Answer
Complete RAG Processing Chain
1 PDF
2 │
3 ▼
4 Load Document
5 │
6 ▼
7 Split into Semantic Chunks
8 │
9 ▼
10 Clean Metadata
11 │
12 ▼
13 Generate Embeddings
14 │
15 ▼
16 Store in ChromaDB
17 │
18 ▼
19 User Question
20 │
21 ▼
22 Embed Query
23 │
24 ▼
25 Similarity Search
26 │
27 ▼
28 Retrieve Top-K Relevant Chunks
29 │
30 ▼
31 Build Prompt
32 │
33 ▼
34 Gemini LLM
35 │
36 ▼
37 Grounded Response
Project Structure
1 RAG/
2 │
3 ├── upload/
4 ├── chroma_db/
5 ├── app.py
6 ├── streamlit.py
7 ├── document_loader.py
8 ├── spliter.py
9 ├── embedding.py
10 ├── retrieval.py
11 ├── rag_chain.py
12 ├── requirements.txt
13 ├── README.md
14 └── .env
Module Responsibilities
document_loader.py
Loads PDF files
Converts pages into LangChain Documents
Handles file validation
spliter.py
Splits documents into overlapping chunks
Cleans metadata
Assigns chunk IDs
embedding.py
Generates embeddings
Stores vectors in ChromaDB
Creates persistent vector database
retrieval.py
Loads ChromaDB
Embeds user query
Retrieves Top-K similar chunks
rag_chain.py
Formats retrieved context
Creates prompt
Invokes Gemini
Returns grounded answer
streamlit.py
User interface
Upload documents
Build vector database
Chat interface
app.py
CLI entry point
Useful for testing without UI
Technologies Used
Language
Frameworks
Embeddings
HuggingFace
BAAI/bge-small-en-v1.5
Vector Database
LLM
PDF Loader
Software Engineering Best Practices
Modular Architecture
Separation of Concerns
Single Responsibility Principle
High Cohesion
Loose Coupling
Persistent Vector Storage
Reusable Components
Environment-based Configuration
Metadata Preservation
Semantic Retrieval
Prompt Engineering
Configurable Chunk Size
Configurable Chunk Overlap
Independent Module Testing
Production-Oriented Folder Structure
Unique Features
Modular Pipeline
Every stage is isolated into a dedicated module, allowing independent maintenance and testing.
Persistent Vector Database
Embeddings are generated once and stored permanently, avoiding repeated computation.
Local Embeddings + Cloud LLM
Uses local Hugging Face embeddings for indexing while leveraging Gemini only for reasoning, reducing API usage and cost.
Metadata Tracking
Each chunk stores source, page number, and chunk ID, enabling future support for citations and explainability.
Configurable Architecture
Chunk size and overlap can be modified through environment variables without changing source code.
Ready for Production
The architecture is designed to transition easily to FastAPI, React, and cloud deployment.
Current Limitations
Single-user workflow
One vector database directory
No authentication
No chat history
No hybrid retrieval
No reranking
No OCR support
Future Roadmap
Multi-User Support
1 chroma_db/
2 user_001/
3 user_002/
Per-Document Vector Stores
1 chroma_db/
2 user_001/
3 document_001/
4 document_002/
Benefits:
Complete data isolation
Better scalability
Faster retrieval
Independent deletion
Additional planned features:
JWT / OAuth Authentication
PostgreSQL Metadata Storage
FastAPI Backend
React / Next.js Frontend
Flutter Mobile App
Chat History
Multi-document Retrieval
Hybrid Search (Dense + BM25)
Cross-Encoder Reranking
OCR for Scanned PDFs
Multi-modal RAG
Knowledge Graph Integration
Agentic RAG
Docker
Kubernetes
AWS / Azure / GCP Deployment
Monitoring & Logging
Role-Based Access Control
Production Architecture
1 User
2 │
3 ▼
4 Authentication
5 │
6 ▼
7 Upload PDF
8 │
9 ▼
10 Generate User ID
11 │
12 ▼
13 Generate Document ID
14 │
15 ▼
16 Store:
17 ./chroma_db/<user_id>/<document_id>/
18 │
19 ▼
20 Metadata Database (PostgreSQL)
21 │
22 ▼
23 Retriever
24 │
25 ▼
26 Gemini
27 │
28 ▼
29 Grounded Answer
Installation
pip install -r requirements.txt
Create .env
1 GEMINI_API_KEY=YOUR_API_KEY
2 CHUNK_SIZE=1000
3 CHUNK_OVERLAP=100
Run
streamlit run streamlit.py
or
License
This project is intended for educational purposes and serves as a foundation for building scalable, production-ready Retrieval-Augmented Generation systems.