# alagrine/rag_chatabot_with_langchain architecture

> Architecture diagram of the GitHub repository alagrine/rag_chatabot_with_langchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alagrine/rag_chatabot_with_langchain
- Repository: https://github.com/alagrine/rag_chatabot_with_langchain

## Overview

##### Project type and purpose
- This is a Retrieval-Augmented Generation (RAG) chatbot: a specialized full-stack application that combines document retrieval (from user-uploaded files) with Large Language Models (OpenAI/Google GenAI/Hugging Face) to answer questions grounded in the uploaded data.
- Its main use case: let end users upload documents (PDF, TXT, CSV, DOCX), build or load a Chroma vector store of embeddings, then chat with the data via a Streamlit frontend.

##### File structure
- Root files:
- RAG_app.py – Streamlit application entrypoint
- RAG_notebook.ipynb – exploratory notebook
- requirements.txt – dependency list
- data/
- docs/ – sample PDFs and screenshots
- vector_stores/ – persisted Chroma vector stores

##### Key insights from the README
- RAG pipeline components: document loader, text splitter, embeddings (OpenAI/Hugging Face), Chroma vector store, retriever, conversational chain.
- Supports three LLM providers via LangChain connectors.
- Streamlit UI for parameter selection (model, API keys) and chatting.

a. Main components
1. Streamlit UI (RAG_app.py)
2. RAG Orchestrator (LangChain layers):
– Document Loader & Text Splitter
– Embedding Generator
– Vector Store Manager (ChromaDB)
– Retriever
– Conversational Chain / LLM Invoker
3. External LLM Providers:
– OpenAI API
– Google Generative AI API
– Hugging Face Inference API
4. Data Storage:
– Local file system for raw docs (data/docs/)
– Persistent vector store on disk (data/vector_stores/)
b. Relationships and data flow
1. End user → Streamlit UI: selects provider, uploads docs or loads vector store, enters queries
2. UI → Document Loader/Text Splitter (on upload) → Embedding Generator → Vector Store (ingest)
3. UI Query → Retriever (queries Chroma) → top-k chunks
4. Retriever + Query → Conversational Chain → chosen LLM Provider → API response
5. LLM Response → UI → rendered chat
c. Architectural patterns / design principles
- Modular pipeline (each LangChain component is a reusable block)
- Separation of concerns: ingestion vs. retrieval vs. generation
- Pluggable provider interfaces for embeddings & LLMs
- Persistence layer (Chroma) decoupled from compute
d. Key technologies & libraries
- Python 3
- LangChain (chains, retrievers, connectors)
- chromadb (vector store)
- streamlit (UI)
- OpenAI / Google GenAI / Hugging Face APIs

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["Streamlit UI"]:::ui
    end

    %% Data Ingestion Path
    subgraph "Ingestion Pipeline"
        DL["Document Loader & Text Splitter"]:::pipeline
        EG["Embedding Generator"]:::pipeline
        VSM["Chroma Vector Store Manager"]:::storage
    end

    %% Storage
    subgraph "Storage Layer"
        RawDocs[(Raw Document Storage)]:::storage
        SamplePDF["2024-01-24-VirtualTryAll.pdf"]:::storage
        Screenshots["screenshots/"]:::storage
        VectorStores[(Vector Stores)]:::storage
        SpecificStore["Vit_All_HF_Embeddings/"]:::storage
    end

    %% Retrieval & Generation Path
    subgraph "Retrieval & Generation"
        RET["Retriever (Chroma)"]:::pipeline
        CC["Conversational Chain & LLM Invoker"]:::pipeline
    end

    %% External LLM Providers
    subgraph "External LLM Providers"
        OpenAI["OpenAI API"]:::external
        Google["Google Generative AI API"]:::external
        HF["Hugging Face Inference API"]:::external
    end

    %% Auxiliary Files
    subgraph "Auxiliary"
        Notebook["RAG_notebook.ipynb"]:::aux
        Req["requirements.txt"]:::aux
    end

    %% Connections
    UI -->|uploads docs| DL
    DL --> EG
    EG --> VSM
    VSM -->|persists embeddings| VectorStores
    VectorStores --> SpecificStore

    UI -->|queries chat| RET
    RET --> CC
    CC -->|calls API| OpenAI
    CC -->|calls API| Google
    CC -->|calls API| HF
    CC -->|returns response| UI

    RawDocs -->|provides files| DL
    RawDocs --> SamplePDF
    RawDocs --> Screenshots
    VectorStores --> RET

    %% Click Events
    click UI "https://github.com/alagrine/rag_chatabot_with_langchain/blob/main/RAG_app.py"
    click Notebook "https://github.com/alagrine/rag_chatabot_with_langchain/blob/main/RAG_notebook.ipynb"
    click Req "https://github.com/alagrine/rag_chatabot_with_langchain/blob/main/requirements.txt"
    click RawDocs "https://github.com/alagrine/rag_chatabot_with_langchain/tree/main/data/docs/"
    click SamplePDF "https://github.com/alagrine/rag_chatabot_with_langchain/blob/main/data/docs/2024-01-24-VirtualTryAll.pdf"
    click Screenshots "https://github.com/alagrine/rag_chatabot_with_langchain/tree/main/data/docs/screenshots/"
    click VectorStores "https://github.com/alagrine/rag_chatabot_with_langchain/tree/main/data/vector_stores/"
    click SpecificStore "https://github.com/alagrine/rag_chatabot_with_langchain/tree/main/data/vector_stores/Vit_All_HF_Embeddings/"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#00796B,color:#004D40;
    classDef pipeline fill:#E8F5E9,stroke:#388E3C,color:#1B5E20;
    classDef storage fill:#FFFDE7,stroke:#F9A825,color:#F57F17;
    classDef external fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
    classDef aux fill:#ECEFF1,stroke:#607D8B,color:#37474F;
```
