# marqo-ai/marqo architecture

> Architecture diagram of the GitHub repository marqo-ai/marqo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marqo-ai/marqo
- Repository: https://github.com/marqo-ai/marqo

## Overview

##### Main Components

a) Client Layer:
- Python Client Interface (src/marqo)
- API Routes and Models (src/marqo/api)
- Client Configuration Handling

b) Core Processing Layer:
- Document Processing
- Inference Engine
- Tensor Search
- Index Management
- Embedding Generation

c) Storage Layer:
- Vespa Backend
- Index Storage
- Document Store
- Vector Storage (HNSW)

d) Infrastructure Components:
- Docker Container
- Kubernetes Support (optional)
- Cache System
- Distributed Lock Management

##### Key Relationships to Highlight

a) Data Flow:
- Client → API Layer → Core Processing → Storage
- Search Query → Vector Generation → Vector Search → Results
- Document Indexing → Preprocessing → Vector Generation → Storage

b) Integration Points:
- Model Integration (PyTorch, Huggingface, OpenAI)
- External Storage Systems
- Kubernetes Deployment

##### Specific Implementation Details

**[Client Layer]**

- v
**[API Gateway]**

- v
**[Core Processing]**
- Document Processor
- Inference Engine
- Model Management
- Vector Generation
- Cache System
- Search Engine
- Vector Search
- Lexical Search
- Hybrid Search

- v
**[Storage Layer]**
- Vespa Backend
- Vector Indexes (HNSW)
- Document Store

##### Important Features to Highlight

- Multi-modal support (text and images)
- Distributed architecture
- Scalability components
- Model management system
- Caching mechanisms
- Search methods (vector, lexical, hybrid)

##### Technical Details

- Docker container boundaries
- API endpoints
- Vector processing pipeline
- Model integration points
- Storage architecture
- Scaling components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        CI["Client Interface"]:::client
        AR["API Routes"]:::client
        AM["API Models"]:::client
    end

    subgraph Core["Core Processing Layer"]
        subgraph DP["Document Processing"]
            DV["Document Validation"]:::core
            FE["Field Extraction"]:::core
            MP["Multimodal Processing"]:::core
            TFP["Tensor Field Processing"]:::core
        end

        subgraph IE["Inference Engine"]
            MM["Model Management"]:::core
            DM["Device Management"]:::core
            MR["Model Registry"]:::core
            Cache["Caching Layer"]:::core
        end

        subgraph Search["Search Components"]
            HS["Hybrid Search"]:::core
            LS["Lexical Search"]:::core
            VS["Vector Search"]:::core
            QP["Query Processing"]:::core
            REC["Recommender"]:::core
        end

        subgraph IM["Index Management"]
            IMP["Index Manager"]:::core
            VA["Vespa Application"]:::core
        end
    end

    subgraph Storage["Storage Layer"]
        VB["Vespa Backend"]:::storage
        IS["Index Storage"]:::storage
        DS["Document Store"]:::storage
        VStore["Vector Storage (HNSW)"]:::storage
    end

    subgraph Infra["Infrastructure Components"]
        Docker["Docker Container"]:::infra
        K8s["Kubernetes"]:::infra
        Redis["Redis Throttling"]:::infra
        ZK["ZooKeeper Lock"]:::infra
    end

    subgraph MM_Support["Multimodal Support"]
        LB["Language Bind"]:::mm
        IP["Image Processing"]:::mm
        TP["Text Processing"]:::mm
    end

    %% Relationships
    CI --> AR
    AR --> AM
    AM --> DP
    DP --> IE
    IE --> MM_Support
    IE --> Search
    Search --> Storage
    IM --> Storage
    Redis --> Core
    ZK --> Core

    %% Click Events
    click CI "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/__init__.py"
    click AR "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/api/route.py"
    click AM "https://github.com/marqo-ai/marqo/tree/mainline/src/marqo/api/models/"
    click DV "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/unstructured_vespa_index/unstructured_validation.py"
    click MM "https://github.com/marqo-ai/marqo/tree/mainline/src/marqo/core/inference/embedding_models/"
    click DM "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/inference/device_manager.py"
    click MR "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/s2_inference/model_registry.py"
    click HS "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/search/hybrid_search.py"
    click QP "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/tensor_search/tensor_search.py"
    click REC "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/search/recommender.py"
    click IMP "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/index_management/index_management.py"
    click VA "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/index_management/vespa_application_package.py"
    click VB "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/vespa/vespa_client.py"
    click IS "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/vespa_index/vespa_index.py"
    click ZK "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/core/distributed_lock/zookeeper_distributed_lock.py"
    click Redis "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/tensor_search/throttling/redis_throttle.py"
    click LB "https://github.com/marqo-ai/marqo/tree/mainline/src/marqo/s2_inference/languagebind/"
    click IP "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/s2_inference/processing/image.py"
    click TP "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/s2_inference/processing/text.py"
    click Cache "https://github.com/marqo-ai/marqo/blob/mainline/src/marqo/inference/inference_cache/marqo_inference_cache.py"

    %% Styling
    classDef client fill:#2374ab
    classDef core fill:#57a773
    classDef storage fill:#ff8c42
    classDef infra fill:#848484
    classDef mm fill:#7209b7

    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["Core Processing"]:::core
        L3["Storage Components"]:::storage
        L4["Infrastructure"]:::infra
        L5["Multimodal Support"]:::mm
    end
```
