Skip to main content

Configuration and Data Model

We have adopted elements of a lightweight version of the Domain-Driven Design (DDD) in the implementation of the project.

Hydra-based configuration

We have separated the configuration of the application from the application itself. We have used Hydra as the configuration engine - typically used in machine learning projects that run on different environments (e.g., edge server, development laptop, etc.). In addition we have connected Hydra and the experiment monitoring component that allow us to view the lineage of the produced models.

Pydantic-based data model

We have defined the entities of the application using Pydantic classes. The data model is used to validate the configuration data. Choosing Pydantic allows us also to future proof the solution around Large Language and Vision Model agents by using the same data model in the API layer.
from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

class ProductImage(BaseModel):
    """Domain entity representing a product seam image."""
    image_id: str
    machine_setting: str
    timestamp: datetime
    image_data: bytes
    anomaly_label: Optional[str] = None

class Dataset(BaseModel):
    """Domain entity representing a dataset of product images."""
    name: str
    version: str
    images: List[ProductImage]
    created_at: datetime

class InferenceResult(BaseModel):
    """Domain entity representing an anomaly detection inference result."""
    image_id: str
    anomaly_score: float
    is_anomalous: bool
    confidence: float
    inference_time_ms: float

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.