# bigmb/mb_rag architecture

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

- Interactive diagram: https://gitdiagram.com/bigmb/mb_rag
- Repository: https://github.com/bigmb/mb_rag

## Overview

##### Main Components
- RAG and Embedding Module (mb_rag/rag/embeddings.py): Responsible for generating text embeddings, interfacing with vector stores (like Chroma), and producing retrievers for context-aware queries.
- Chatbot Module (mb_rag/chatbot): Contains basic chat implementations and chain integrations (using LangChain) for conversation management.
- Agents Module (mb_rag/agents): Implements specialized agents such as a web browser agent that supports additional features (possibly using langgraph).
- Utility Functions (mb_rag/utils): Includes helpers for document extraction, PDF processing, and particularly image processing utilities (e.g., bounding_box.py for image annotation).
- Example Scripts and Jupyter Notebooks (examples/): Provide usage examples showing various use cases (chatbot interactions, embedding generation, image processing, etc.).
- Configuration and Environment Setup: Files like .env.example, Dockerfile, and pyproject.toml indicate deployment and configuration aspects.

##### Interactions and Relationships
– From the Chatbot Module, show interactions with the RAG Module where embeddings are generated and retrieval is performed from a vector store.
– For image-related capabilities, display how client images are processed via the Utilities (bounding_box.py) that interact with external image processing APIs (e.g., Google Generative AI) and return processed images.
– Highlight external dependencies such as LLM providers (OpenAI, Anthropic, Google, Ollama, Groq) and vector stores (Chroma) to illustrate integration points.

##### Architecture Patterns and Design Principles
– Modularity: The project is broken into clear sub-packages (rag, chatbot, agents, utils) which follow separation of concerns.
– Extensibility: The use of multiple model providers with a unified interface (ModelFactory) suggests a pluggable, abstracted design enabling easy swapping of underlying technologies.
– Layered Structure: A common pattern of having core logic (model factories, chaining logic) that interfaces with utility modules and external services.
– Use of standardized configuration and environment management (e.g., .env files) to support deployment.

##### Relevant Technologies
– Python, along with dependencies from langchain (core, community, openai, anthropic, google-genai, ollama).
– Image processing libraries like Pillow and OpenCV (as indicated in the optional dependencies).
– External vector store, for example, ChromaDB.
– Containerization support (Dockerfile) to indicate potential deployment in Docker.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Client["Client/User"]:::external
    LLM["LLM Providers"]:::external
    Chroma["Vector Store: ChromaDB"]:::external
    ImageAPI["External Image API"]:::external

    %% Internal Modules
    Chatbot["Chatbot Module"]:::internal
    RAG["RAG & Embeddings Module"]:::internal
    Agents["Agents Module"]:::internal
    Utils["Utility Functions"]:::internal
    Examples["Example Scripts & Notebooks"]:::internal
    Config["Configuration & Environment Setup"]:::internal

    %% Data flow arrows
    Client -->|"sends_query"| Chatbot
    Chatbot -->|"calls_embeddings"| RAG
    RAG -->|"retrieves_context"| Chroma
    Chatbot -- "invokes_agent" --> Agents
    Chatbot <-->|"chat_with_llm"| LLM
    Agents <-->|"agent_llm_interaction"| LLM

    Client -->|"sends_image"| Utils
    Utils -->|"processes_image"| ImageAPI
    ImageAPI -->|"returns_image"| Utils

    %% Supplementary links for documentation and configuration
    Examples ---|"demonstrates_usage"| Chatbot

    Config ---|"configures"| Chatbot
    Config ---|"configures"| RAG
    Config ---|"configures"| Agents
    Config ---|"configures"| Utils

    %% Click Events
    click RAG "https://github.com/bigmb/mb_rag/blob/main/mb_rag/rag/embeddings.py"
    click Chatbot "https://github.com/bigmb/mb_rag/tree/main/mb_rag/chatbot"
    click Agents "https://github.com/bigmb/mb_rag/tree/main/mb_rag/agents"
    click Utils "https://github.com/bigmb/mb_rag/tree/main/mb_rag/utils"
    click Examples "https://github.com/bigmb/mb_rag/tree/main/examples/"
    click Config "https://github.com/bigmb/mb_rag/tree/main/Dockerfile"

    %% Styles
    classDef internal fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef external fill:#ffd700,stroke:#000,stroke-width:2px;
```
