# aunraza19/rag-pipline-chatbot architecture

> Architecture diagram of the GitHub repository aunraza19/rag-pipline-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aunraza19/rag-pipline-chatbot
- Repository: https://github.com/aunraza19/rag-pipline-chatbot

## Overview

##### Project Type and Purpose
- This is a specialized full-stack RAG (Retrieval-Augmented Generation) chatbot designed to answer university academic policy questions. It consists of two major workflows:
a. **Data Ingestion Pipeline** (batch job) to process and index the PDF manual.
b. **Query-Response Service** (interactive Streamlit UI) to serve students in real time.

##### High-Level Components
A. **Source Document**
- academic_manual.pdf (the raw policy PDF)
B. **Ingestion Pipeline**
- ingest.py:
- Uses PyPDFLoader to parse the PDF into text chunks
- Generates embeddings via BAAI/bge-small-en-v1.5 (HuggingFaceEmbeddings)
- Persists embeddings and metadatas in ChromaDB (./chroma_db)
C. **Configuration**
- config.py + .env: centralize API keys (GROQ_API_KEY, optional HUGGINGFACEHUB_API_TOKEN) and constants
D. **Utility Layer**
- utils.py: wraps calls to embedding model, vector store client, and LLM client (Groq API via LangChain)
E. **Frontend & Orchestration**
- app.py (Streamlit):
- Takes user query
- Uses utils to convert query → embedding → vector search → retrieve top-k chunks
- Feeds context + query to Groq LLM → obtains generated answer
- Renders chat interface with answer and source attributions
F. **External Services & Dependencies**
- Groq LLM API (llama-3.1-8b-instant) for answer generation
- HuggingFaceEmbeddings for vector encoding (if token required)
- LangChain library to orchestrate retrieval and generation
- Streamlit runtime for UI

##### Interactions & Data Flow
1. **One-Time Ingestion**
academic_manual.pdf → ingest.py → text chunks → embeddings (HuggingFace) → ChromaDB
2. **Query Flow (per user request)**
Streamlit UI (app.py)
↓ user question
utils.py embedding call → embedding vector
↓
ChromaDB vector search → top-N relevant chunks
↓
utils.py LLM call via LangChain → Groq API (context + prompt)
↓
LLM returns answer → Streamlit displays answer with source snippets

##### Architectural Patterns & Principles
- **Modular Separation**: clear divide between ingestion (offline batch) and serving (online interactive)
- **Single Responsibility**: each script has one focused role (ingest, config, utils, UI)
- **Externalized Configuration**: secrets/config in .env + config.py
- **Layered Design**:
- Data Layer (PDF, ChromaDB)
- Logic Layer (utils + LangChain orchestrator)
- Presentation Layer (Streamlit)

## Diagram (Mermaid)

```mermaid
flowchart TD
    title["University Academic Policy Chatbot – System Architecture"]:::title

    %% Batch Ingestion
    subgraph "Batch Ingestion (Offline)"
        direction TB
        PDF["PDF Source<br/>academic_manual.pdf"]:::local
        subgraph "Ingestion Pipeline"
            direction TB
            Loader["PDFLoader (PyPDFLoader)"]:::local
            Chunker["Chunker (text chunks)"]:::local
            EmbedGen["Embedding Generator<br/>HuggingFaceEmbeddings"]:::external
            Writer["ChromaDB Writer"]:::local
        end
        PDF -->|"raw PDF"| Loader
        Loader -->|"text chunks"| Chunker
        Chunker -->|"text chunks"| EmbedGen
        EmbedGen -->|"embeddings"| Writer
        Writer -->|"stores embeddings & metadata"| DB
    end

    %% Vector Store
    DB[(ChromaDB)]:::storage

    %% Online Serving
    subgraph "Online Serving (Real-Time)"
        direction TB
        UI["Streamlit UI<br/>app.py"]:::local
        Logic["Backend Logic<br/>utils.py + config.py"]:::local
        UI -->|"user query"| Logic
        Logic -->|"embed query"| HF
        HF["HuggingFace Embeddings Service"]:::external
        HF -->|"vector"| Logic
        Logic -->|"vector search"| DB
        DB -->|"top-k chunks"| Logic
        Logic -->|"prompt+context"| Groq
        Groq["Groq LLM API"]:::external
        Groq -->|"answer"| Logic
        Logic -->|"response & sources"| UI
    end

    %% Dependencies
    Req["requirements.txt"]:::local

    %% Click Events
    click PDF "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/academic_manual.pdf"
    click Loader "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/ingest.py"
    click EmbedGen "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/ingest.py"
    click Writer "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/ingest.py"
    click Logic "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/utils.py"
    click UI "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/app.py"
    click Config "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/config.py"
    click Env "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/.env"
    click Req "https://github.com/aunraza19/rag-pipline-chatbot/blob/master/requirements.txt"

    %% Styles
    classDef local fill:#cce5ff,stroke:#004085,color:#004085;
    classDef external fill:#d4edda,stroke:#155724,color:#155724;
    classDef storage fill:#fff3cd,stroke:#856404,color:#856404;
    classDef title fill:#e2e3e5,stroke:#6c757d,color:#6c757d,font-weight:bold;
```
