# notshrirang/loomrag architecture

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

- Interactive diagram: https://gitdiagram.com/notshrirang/loomrag
- Repository: https://github.com/notshrirang/loomrag

## Overview

##### Project Overview and Purpose
- LoomRAG is a multimodal retrieval-augmented generation system. It integrates various input modalities (text, images, audio, PDFs) for search and retrieval, powered by deep learning models – notably OpenAI’s CLIP for image and text embeddings and Whisper for audio processing. It also features an image annotation interface and supports model fine-tuning.
- The README clearly describes major functions such as data indexing, query processing, response generation, image annotation, and model fine-tuning. This confirms that it’s a full-fledged end-to-end system with both data processing and user interactivity.

##### Analyzing the File Structure
- Top-level files such as app.py, requirements.txt, LICENSE, and README.md indicate that this is a self-contained project.
- Directories like data_annotations, data_search, and data_upload suggest separate modules dedicated to different kinds of user interactions and use cases.
- The model_finetuning directory contains modules related to training and selection, indicating a well-modularized approach for adapting the CLIP model.
- The presence of configuration (config/constants.py), utility (utils.py, vectordb.py), and weights directories further emphasizes clear separation of concerns: configuration, business logic, data embedding, and pre-trained model artifacts.

a. User Interface & Frontend:
- The Streamlit interface launched via app.py acts as the front-end portal for users.
- It provides multiple pages: Data Upload, Data Search/Retrieval, Data Annotation, and Model Fine-Tuning.

b. Data Processing Modules:
- Data Upload: Handles image, audio, PDF, and URL inputs.
- Data Search: Implements the embedding-based search functionality using CLIP embeddings.
- Data Annotation: Provides a page for managing and annotating images.

c. Core AI/ML Components:
- Embedding Generation: Utilizes OpenAI’s CLIP and Whisper for converting inputs into vector embeddings.
- Model Fine-Tuning: Consists of a training pipeline (model_training_component.py, selection_component.py) for custom CLIP model adjustments.
- External dependencies include vector database support using FAISS for similarity search.

d. Backend Services/Utilities:
- Vector Database (via vectordb.py) that stores embeddings from processed inputs.
- Utility components (utils.py and adapter_utils.py) aiding in data transformation and integration.
- Configuration management via the config folder.

##### Relationships and Interactions
- Data Flow:
- User interactions occur through the Streamlit UI; input data (text, image, audio, PDFs) is sent to the respective processing modules.
- The system’s preprocessing converts these inputs into embeddings.
- These embeddings are stored in and retrieved from a vector database (likely using FAISS).
- On retrieval, the system searches nearest neighbors for similar embeddings and returns text, image, and audio results.
- Model Fine-Tuning Cycle:
- Annotated data from the Annotation module feed into the CLIP fine-tuning pipeline.
- Fine-tuned weights (stored in the weights folder) then integrate back into the search component for improved results.
- External Integration:
- Web scraping (through URL input) and audio recording integration are additional layers that connect external data sources into the indexing pipeline.

##### Architectural Patterns
- Modular Design: Different modules are clearly separated (upload, search, annotation, fine-tuning) indicating high cohesion and low coupling.
- MVC-like Separation: The UI (View) in Streamlit, business logic in separate Python modules, and persisted state in the vector database reflect a model separation pattern.
- Data Flow and Pipeline Architecture: The process from data ingestion to embedding generation and retrieval is best presented as a pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        UI["Frontend (Streamlit Interface)"]:::frontend
    end

    subgraph "Data Processing Modules"
        DU["Data Upload Page"]:::module
        DSUtil["Input Sources Utils"]:::module
        DS["Data Search Page"]:::module
        DSearchUtil["Adapter Utils"]:::module
        DA["Data Annotation Page"]:::module
        DFT["Model Fine-Tuning Page"]:::module
        DFTComp["Model Components"]:::module
    end

    subgraph "AI/ML Components"
        EG["Embedding Generation (CLIP & Whisper)"]:::core
        CFG["Configuration Management"]:::core
        UF["Utility Functions"]:::core
    end

    subgraph "Backend Services"
        VD["Vector Database (FAISS)"]:::database
    end

    UI -->|"triggers"| DU
    UI -->|"triggers"| DS
    UI -->|"triggers"| DA
    UI -->|"triggers"| DFT

    DU -->|"processes"| EG
    DS -->|"processes"| EG
    EG -->|"stores in"| VD
    VD -->|"retrieves for"| DS

    DA -->|"annotates"| DFT
    DFT -->|"updates"| EG

    DU -.->|"utilizes"| DSUtil
    DS -.->|"utilizes"| DSearchUtil
    DFT -.->|"contains"| DFTComp

    click UI "https://github.com/notshrirang/loomrag/blob/main/app.py"
    click DU "https://github.com/notshrirang/loomrag/blob/main/data_upload/data_upload_page.py"
    click DSUtil "https://github.com/notshrirang/loomrag/tree/main/data_upload/input_sources_utils/"
    click DS "https://github.com/notshrirang/loomrag/blob/main/data_search/data_search_page.py"
    click DSearchUtil "https://github.com/notshrirang/loomrag/blob/main/data_search/adapter_utils.py"
    click DA "https://github.com/notshrirang/loomrag/blob/main/data_annotations/data_annotation_page.py"
    click DFT "https://github.com/notshrirang/loomrag/blob/main/model_finetuning/model_finetuning_page.py"
    click DFTComp "https://github.com/notshrirang/loomrag/tree/main/model_finetuning/components/"
    click CFG "https://github.com/notshrirang/loomrag/blob/main/config/constants.py"
    click UF "https://github.com/notshrirang/loomrag/blob/main/utils.py"
    click VD "https://github.com/notshrirang/loomrag/blob/main/vectordb.py"

    classDef frontend fill:#f9d56e,stroke:#333,stroke-width:2px;
    classDef module fill:#a3d2ca,stroke:#333,stroke-width:2px;
    classDef core fill:#ffe6e6,stroke:#333,stroke-width:2px;
    classDef database fill:#cce5ff,stroke:#333,stroke-width:2px;
```
