erDiagram
    CATALOG {
        int id PK
        string name
        text description
        string type
        string type_version
        int min_chunk_size
        int max_chunk_size
        jsonb user_metadata
        jsonb system_metadata
        jsonb configuration
        datetime created_at
        int created_by FK
        datetime updated_at
        int updated_by FK
    }

    PROCESSOR {
        int id PK
        string name
        text description
        int catalog_id FK
        string type
        string sub_file_type
        boolean active
        boolean tuning
        jsonb user_metadata
        jsonb system_metadata
        jsonb configuration
        datetime created_at
        int created_by FK
        datetime updated_at
        int updated_by FK
    }

    RETRIEVER {
        int id PK
        string name
        text description
        int catalog_id FK
        string type
        string type_version
        boolean tuning
        jsonb user_metadata
        jsonb system_metadata
        jsonb configuration
        jsonb arguments
        datetime created_at
        int created_by FK
        datetime updated_at
        int updated_by FK
    }

    DOCUMENT {
        int id PK
        int catalog_id FK
        string name
        datetime valid_from
        datetime valid_to
        datetime created_at
        int created_by FK
        datetime updated_at
        int updated_by FK
    }

    DOCUMENT_VERSION {
        int id PK
        int doc_id FK
        string url
        string bucket_name
        string object_name
        string file_type
        string sub_file_type
        float file_size
        string language
        text user_context
        text system_context
        jsonb user_metadata
        jsonb system_metadata
        jsonb catalog_properties
        datetime created_at
        int created_by FK
        datetime updated_at
        int updated_by FK
        boolean processing
        datetime processing_started_at
        datetime processing_finished_at
        string processing_error
    }

    EMBEDDING {
        int id PK
        string type
        int doc_vers_id FK
        boolean active
        text chunk
    }

    EMBEDDING_MISTRAL {
        int id PK,FK
        vector_1024 embedding
    }

    EMBEDDING_SMALL_OPENAI {
        int id PK,FK
        vector_1536 embedding
    }

    EMBEDDING_LARGE_OPENAI {
        int id PK,FK
        vector_3072 embedding
    }

    USER {
        int id PK
        string user_name
        string email
    }

    %% Relationships
    CATALOG ||--o{ PROCESSOR : "has many"
    CATALOG ||--o{ RETRIEVER : "has many"
    CATALOG ||--o{ DOCUMENT : "has many"
    
    DOCUMENT ||--o{ DOCUMENT_VERSION : "has many"
    
    DOCUMENT_VERSION ||--o{ EMBEDDING : "has many"
    
    EMBEDDING ||--o| EMBEDDING_MISTRAL : "inheritance"
    EMBEDDING ||--o| EMBEDDING_SMALL_OPENAI : "inheritance"
    EMBEDDING ||--o| EMBEDDING_LARGE_OPENAI : "inheritance"
    
    USER ||--o{ CATALOG : "creates/updates"
    USER ||--o{ PROCESSOR : "creates/updates"
    USER ||--o{ RETRIEVER : "creates/updates"
    USER ||--o{ DOCUMENT : "creates/updates"
    USER ||--o{ DOCUMENT_VERSION : "creates/updates"