# gurpreetkaurjethra/rag-based-llm-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/gurpreetkaurjethra/rag-based-llm-chatbot
- Repository: https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot

## Overview

##### Project type and purpose
- This is a single-page, full-stack RAG (Retrieval-Augmented Generation) chatbot application built on Streamlit.
- Purpose: allow users to upload PDF files, generate embeddings for semantic search, and chat with a local LLM (Llama 3.2 via Ollama) using a LangChain orchestration layer and Qdrant vector database.

##### File structure
Top-level files and folders:
- new.py        – Streamlit entrypoint (frontend + high-level orchestration)
- chatbot.py    – LangChain chains and prompt logic (chat interface)
- vectors.py    – Embedding creation and vector-store interaction
- aliases/      – JSON templates or prompt aliases (aliases/data.json)
- raft_state.json – state file for streamlit session or Qdrant Docker state
- requirements.txt, Docker config implied for Qdrant
Key patterns:
– MVC-like separation: new.py (view + controller), chatbot.py & vectors.py (model/services)
– External services: Qdrant (Docker container), Ollama (local LLM server), HuggingFace BGE embeddings, Unstructured for PDF parsing

##### README insights
- Tech stack: Streamlit (UI), LangChain (orchestration), Unstructured (PDF → text), BGE (embeddings), Qdrant (vector DB), LLaMA via Ollama (chat LLM).
- Workflow description: Upload → Preprocess → Embed → Store/Retrieve → Respond.

a. Main components
1. Streamlit Frontend (new.py)
2. Document Processor (Unstructured module invoked in vectors.py)
3. Embedding Generator (HuggingFace BGE via vectors.py)
4. Vector Database (Qdrant in Docker)
5. Orchestrator (LangChain chains in chatbot.py)
6. LLM Service (LLaMA 3.2 hosted by Ollama)
7. Prompt Templates (aliases/data.json)
b. Relationships & interactions
- User ↔ Streamlit UI: upload PDF, view chat window
- UI → Document Processor: raw PDF → text chunks
- Processor → Embedding Generator: text chunks → vector embeddings
- Embeddings ↔ Qdrant: store & retrieve top-k similar vectors
- Chat Orchestrator → LLM Service: provide context + user query → LLM response
- Orchestrator → UI: display chat responses
c. Architectural patterns
– Layered architecture (UI, service layer, storage, external services)
– Orchestration pattern via LangChain (chain of responsibility)
– RAG pattern (retrieval + generation)
d. Key technologies
– Streamlit (Python UI framework)
– Unstructured (PDF → text)
– BGE Embeddings (HuggingFace)
– Qdrant (vector DB in Docker)
– LangChain (workflow)
– Ollama (LLaMA 3.2 inference)

##### Essential details to capture
- Clearly separate the two RAG phases (ingestion vs chat)
- LangChain orchestration flow
- Where embeddings live and how they’re retrieved
- Local vs external (all components run locally, but Docker is isolation boundary)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend" 
        UI["Streamlit UI (new.py)"]:::ui
    end

    %% Service Layer
    subgraph "Service Layer"
        Processor["Document Processor\n(vectors.py)"]:::services
        Embed["Embedding Generator\n(vectors.py)"]:::services
        Orchestrator["LangChain Orchestrator\n(chatbot.py)"]:::services
        Templates["Prompt Templates\n(aliases/data.json)"]:::services
    end

    %% Data Store Layer
    subgraph "Data Store"
        Qdrant["Qdrant Vector DB"]:::datastore
        State["raft_state.json"]:::datastore
    end

    %% External Services Layer
    subgraph "External Services"
        LLM["LLaMA 3.2 (Ollama)"]:::external
    end

    %% User Interaction
    User["User"]:::user

    %% Ingestion Flow
    User -->|"upload PDF file"| UI
    UI -->|"PDF file"| Processor
    Processor -->|"text chunks"| Embed
    Embed -->|"store vectors"| Qdrant

    %% Chat Flow
    User -->|"enter query"| UI
    UI -->|"user query"| Orchestrator
    Orchestrator -->|"retrieve vectors"| Qdrant
    Qdrant -->|"top-k vectors"| Orchestrator
    Orchestrator -->|"load templates"| Templates
    Orchestrator -->|"query + context"| LLM
    LLM -->|"LLM response"| Orchestrator
    Orchestrator -->|"chat response"| UI

    %% Click Events
    click UI "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/new.py"
    click Processor "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/vectors.py"
    click Embed "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/vectors.py"
    click Orchestrator "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/chatbot.py"
    click Templates "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/aliases/data.json"
    click State "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/raft_state.json"
    click Qdrant "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/raft_state.json"
    click User "https://github.com/gurpreetkaurjethra/rag-based-llm-chatbot/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,stroke-width:2px
    classDef services fill:#DFFFD0,stroke:#2E8B57,stroke-width:2px
    classDef datastore fill:#FFE4B5,stroke:#FF8C00,stroke-width:2px
    classDef external fill:#E8D0FF,stroke:#800080,stroke-width:2px
    classDef user fill:#F0F0F0,stroke:#999,stroke-width:1px,stroke-dasharray: 5 5
```
