# brainscorp/-rag_llm_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/brainscorp/-rag_llm_chatbot
- Repository: https://github.com/brainscorp/-rag_llm_chatbot

## Overview

##### Project type and purpose
- This is a full-stack, single-service Python application built with Streamlit that implements a Retrieval-Augmented Generation (RAG) pipeline using OpenAI’s GPT-4 model, LangChain abstractions, ChromaDB and FAISS for vector search.
- Its core use case is answering domain-specific questions by retrieving relevant documents from a custom knowledge base, then generating contextually grounded answers via an LLM.

##### File structure
- Top level:
- app.py – Streamlit entry point (UI + orchestrator)
- data/ – raw documents for ingestion
- model/llm.py – wrapper around the LLM (OpenAI GPT-4)
- utils/ – modular logic (data2vec, retriever, reasoning_query)
- vector_db/ – persistent vector store artifacts (Chroma SQLite, FAISS index, Pickle)
- requirements.txt, README.md, .gitignore
- Patterns & configuration:
- “utils” implements the retrieval and preprocessing pipeline (vector embedding, metadata filtering)
- “vector_db” holds on-disk storage for the vector store
- No microservices – everything runs in one Python process, orchestrated by Streamlit in app.py

##### README for additional insights
- Confirms RAG architecture: Retriever + Generator + Orchestrator
- Dependencies: LangChain, ChromaDB, FAISS, Streamlit, OpenAI SDK
- Mentions data ingestion script (data2vec.py) and custom retriever extension points (utils/retriever.py)

##### Diagramming recommendations
- Data ingestion: Data folder → Embedding Generator → Vector Store
- Query path: User → UI → Orchestrator → Retriever → Vector Store → Generator → UI
- UI layer (e.g., blue)
- Orchestration & services (e.g., green)
- Data stores (e.g., orange)
- External API (e.g., red)
- Clouds for external services (OpenAI)
- Rectangles for modules/services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI["Streamlit UI & Orchestrator"]:::ui
    end
    click UI "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/app.py"

    %% Data Ingestion Pipeline
    subgraph "Ingestion Pipeline"
        Data["Raw Documents"]:::data
        Embed["Embedding Generator"]:::service
        Store["Vector Store\n(ChromaDB & FAISS)"]:::store
        Data -->|ingest| Embed
        Embed -->|store embeddings| Store
    end
    click Data "https://github.com/brainscorp/-rag_llm_chatbot/tree/main/data/"
    click Embed "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/utils/data2vec.py"
    click Store "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/vector_db/chroma.sqlite3"

    %% Query Pipeline
    subgraph "Query Pipeline"
        User["User"]:::external
        User -->|query| UI

        UI -->|submit query| Orch["Orchestration Logic"]:::service

        subgraph "Retrieval Engine"
            Basic["Basic Retriever"]:::service
            Reason["Reasoning Retriever"]:::service
        end
        click Basic "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/utils/retriever.py"
        click Reason "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/utils/reasoning_query.py"

        Orch -->|"retrieve"| Basic
        Orch -->|"filter/reason"| Reason
        Basic -->|search| Store
        Reason -->|search| Store
        Store -->|top-k docs| Basic
        Store -->|top-k docs| Reason
        Basic -->|docs| Orch
        Reason -->|docs| Orch

        Orch -->|generate prompt| GenWrapper["LLM Wrapper"]:::service
        click GenWrapper "https://github.com/brainscorp/-rag_llm_chatbot/blob/main/model/llm.py"

        GenWrapper -->|API call| Cloud["OpenAI GPT-4 API"]:::external
        Cloud -->|response| GenWrapper

        GenWrapper -->|answer| UI
    end

    %% Styles
    classDef ui fill:#D6E9F8,stroke:#3182bd,color:#0b3d91;
    classDef service fill:#E2F0D9,stroke:#3c763d,color:#27632a;
    classDef store fill:#FDEBD0,stroke:#e67e22,color:#a84300;
    classDef data fill:#FCF3CF,stroke:#f1c40f,color:#83692c;
    classDef external fill:#F8D7DA,stroke:#c41e3a,color:#a1242b;
```
