Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📄 Document RAG Chatbot

A production-style Retrieval-Augmented Generation (RAG) application built with FastAPI, LangChain, Groq, HuggingFace Embeddings, and ChromaDB.

The application allows users to upload PDF documents, generate vector embeddings, store them in a persistent Chroma Vector Database, and chat with the uploaded documents using semantic search.


🚀 Features

  • 📄 Upload PDF documents
  • 📖 Extract text from PDFs
  • ✂️ Intelligent document chunking
  • 🤗 HuggingFace Embeddings
  • 🗄️ Persistent Chroma Vector Database
  • 🔍 Semantic Similarity Search
  • ⚡ Groq LLM Integration
  • 💬 Context-Aware Chat
  • 🧠 Conversation Memory
  • 📚 Swagger API Documentation
  • 📝 Structured Logging
  • ⚙️ Environment-based Configuration
  • 🚀 FastAPI Backend
  • 📦 uv Package Management

🏗️ Project Architecture

                Upload PDF
                     │
                     ▼
              PDF Upload API
                     │
                     ▼
                Save PDF File
                     │
                     ▼
               PDF Loader
                     │
                     ▼
          Recursive Text Splitter
                     │
                     ▼
       HuggingFace Embeddings
                     │
                     ▼
         Chroma Vector Database
                     │
                     ▼
              Similarity Search
                     │
                     ▼
              Retrieved Chunks
                     │
                     ▼
             Prompt Template
                     │
                     ▼
                 Groq LLM
                     │
                     ▼
              Generated Answer
                     │
                     ▼
          Conversation Memory

📂 Project Structure

DOCU-RAG/

│

├── app/

│   ├── config/
│   │     settings.py
│   │
│   ├── memory/
│   │     chat_memory.py
│   │
│   ├── models/
│   │     request_models.py
│   │     response_models.py
│   │
│   ├── prompts/
│   │     prompt.py
│   │
│   ├── routers/
│   │     chat.py
│   │     health.py
│   │     upload.py
│   │
│   ├── services/
│   │     embedding_service.py
│   │     groq_service.py
│   │     pdf_loader.py
│   │     pdf_service.py
│   │     rag_chain.py
│   │     retriever.py
│   │     text_splitter.py
│   │     vector_store.py
│   │
│   ├── utils/
│   │     logger.py
│   │
│   └── main.py
│
├── chroma_db/
├── uploads/
├── logs/
│
├── tests/
│
├── .env
├── .gitignore
├── pyproject.toml
├── uv.lock
└── README.md

⚙️ Tech Stack

Category Technology
Backend FastAPI
LLM Groq
Framework LangChain
Embedding Model HuggingFace Embeddings
Vector Database ChromaDB
Document Loader PyPDFLoader
Text Splitter RecursiveCharacterTextSplitter
Package Manager uv
API Documentation Swagger UI
Configuration Pydantic Settings
Logging Python Logging

🔄 Workflow

Upload PDF
      │
      ▼
Save PDF
      │
      ▼
Read PDF
      │
      ▼
Split into Chunks
      │
      ▼
Generate Embeddings
      │
      ▼
Store in ChromaDB
      │
      ▼
User Question
      │
      ▼
Generate Query Embedding
      │
      ▼
Similarity Search
      │
      ▼
Retrieve Relevant Chunks
      │
      ▼
Prompt + Context
      │
      ▼
Groq LLM
      │
      ▼
Response

📦 Installation

Clone the repository

git clone <repository-url>

cd DOCU-RAG

Create virtual environment

uv venv

Activate virtual environment

Windows

.venv\Scripts\activate

Linux / macOS

source .venv/bin/activate

Install dependencies

uv sync

🔑 Environment Variables

Create a .env file in the project root.

GROQ_API_KEY=your_groq_api_key

EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2

CHROMA_DB_PATH=./chroma_db

UPLOAD_FOLDER=./uploads

CHUNK_SIZE=1000

CHUNK_OVERLAP=200

TOP_K_RESULTS=5

LLM_MODEL=llama-3.1-8b-instant

▶️ Run the Application

uv run uvicorn app.main:app --reload

Server

http://127.0.0.1:8000

Swagger UI

http://127.0.0.1:8000/docs

📌 API Endpoints

Health Check

GET /health

Upload PDF

POST /upload

Uploads a PDF document for processing.


Chat

POST /chat

Example Request

{
  "question": "What is Artificial Intelligence?"
}

Example Response

{
  "answer": "Artificial Intelligence is..."
}

🧠 RAG Pipeline

PDF
 │
 ▼
Upload
 │
 ▼
PyPDFLoader
 │
 ▼
RecursiveCharacterTextSplitter
 │
 ▼
HuggingFace Embeddings
 │
 ▼
ChromaDB
 │
 ▼
Retriever
 │
 ▼
Prompt Template
 │
 ▼
Groq LLM
 │
 ▼
Generated Answer

📚 Libraries Used

  • FastAPI
  • LangChain
  • LangChain Community
  • LangChain Groq
  • LangChain HuggingFace
  • LangChain Chroma
  • ChromaDB
  • Sentence Transformers
  • PyPDF
  • Pydantic Settings
  • Python Dotenv
  • Uvicorn

🚀 Future Improvements

  • Multiple PDF Support
  • Source Citation with Page Numbers
  • Streaming Responses
  • Hybrid Search (BM25 + Vector Search)
  • User Authentication
  • Conversation Persistence
  • Document Deletion API
  • Docker Support
  • AWS Deployment
  • Frontend Integration (React/Next.js)

👨‍💻 Author

Kallappa Kabbur


⭐ If you found this project useful, consider giving it a star!

About

A production-style Retrieval-Augmented Generation (RAG) application built with FastAPI, LangChain, Groq, HuggingFace Embeddings, and ChromaDB.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages