Class ModelMetadata


  • public class ModelMetadata
    extends Object
    Immutable metadata container for machine learning models.

    This class captures essential information about a loaded ML model including its identity, format, structure, and loading characteristics. Metadata is typically extracted by ModelLoader implementations after successful model loading.

    Key Attributes:

    • Model Identity: Name and version for model identification
    • Format: The model format (ONNX, TensorFlow, PyTorch, etc.)
    • Schema: Input and output structure definitions
    • Size: Memory footprint of the loaded model
    • Timing: When the model was loaded into memory

    Builder Pattern:

    
     ModelMetadata metadata = ModelMetadata.builder()
         .modelName("bert-classifier")
         .modelVersion("v2.1.0")
         .format(ModelFormat.ONNX)
         .inputSchema(Map.of("input_ids", "int32[1,512]"))
         .outputSchema(Map.of("logits", "float32[1,2]"))
         .modelSize(450_000_000L) // 450MB
         .build();
     

    Thread Safety:

    Instances of this class are immutable and therefore thread-safe. All getters return either primitive values or defensive copies of collections.

    Usage with ModelLoader:

    
     ModelLoader<OrtSession> loader = new OnnxModelLoader();
     OrtSession model = loader.loadModel(config);
     ModelMetadata metadata = loader.getModelMetadata(model);
    
     // Access metadata
     String name = metadata.getModelName();
     Map<String, Object> inputs = metadata.getInputSchema();
     
    Since:
    1.0.0
    Author:
    Nestor Martourez, Sr Software and Data Streaming Engineer @ CodedStreams
    See Also:
    ModelLoader, ModelFormat, ModelConfig
    • Constructor Detail

      • ModelMetadata

        public ModelMetadata​(String modelName,
                             String modelVersion,
                             ModelFormat format,
                             Map<String,​Object> inputSchema,
                             Map<String,​Object> outputSchema,
                             long modelSize,
                             long loadTimestamp)
        Constructs a new ModelMetadata instance with the specified attributes.
        Parameters:
        modelName - the name of the model (required)
        modelVersion - the version of the model (required)
        format - the format of the model (required)
        inputSchema - map describing model inputs (nullable, defaults to empty)
        outputSchema - map describing model outputs (nullable, defaults to empty)
        modelSize - size of the model in bytes
        loadTimestamp - when the model was loaded (epoch milliseconds)
        Throws:
        NullPointerException - if modelName, modelVersion, or format is null
    • Method Detail

      • getModelName

        public String getModelName()
        Gets the name of the model.
        Returns:
        model name, never null
      • getModelVersion

        public String getModelVersion()
        Gets the version of the model.
        Returns:
        model version, never null
      • getFormat

        public ModelFormat getFormat()
        Gets the format of the model.
        Returns:
        model format, never null
      • getInputSchema

        public Map<String,​Object> getInputSchema()
        Gets the input schema describing model inputs.

        Returns a defensive copy of the internal map.

        Returns:
        immutable map of input names to their schema definitions
      • getOutputSchema

        public Map<String,​Object> getOutputSchema()
        Gets the output schema describing model outputs.

        Returns a defensive copy of the internal map.

        Returns:
        immutable map of output names to their schema definitions
      • getModelSize

        public long getModelSize()
        Gets the size of the model in bytes.
        Returns:
        model size in bytes
      • getLoadTimestamp

        public long getLoadTimestamp()
        Gets the timestamp when the model was loaded.
        Returns:
        load timestamp in epoch milliseconds
      • builder

        public static ModelMetadata.Builder builder()
        Creates a new Builder instance for constructing ModelMetadata.
        Returns:
        a new Builder instance
      • toString

        public String toString()
        Returns a string representation of the model metadata.
        Overrides:
        toString in class Object
        Returns:
        string representation including all metadata fields
      • equals

        public boolean equals​(Object o)
        Compares this metadata to another object for equality.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to compare
        Returns:
        true if all fields are equal
      • hashCode

        public int hashCode()
        Returns a hash code based on all metadata fields.
        Overrides:
        hashCode in class Object
        Returns:
        hash code value