Class ModelMetadata
- java.lang.Object
-
- com.codedstream.otterstream.inference.model.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
ModelLoaderimplementations 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelMetadata.BuilderBuilder for constructingModelMetadatainstances.
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ModelMetadata.Builderbuilder()Creates a new Builder instance for constructing ModelMetadata.booleanequals(Object o)Compares this metadata to another object for equality.ModelFormatgetFormat()Gets the format of the model.Map<String,Object>getInputSchema()Gets the input schema describing model inputs.longgetLoadTimestamp()Gets the timestamp when the model was loaded.StringgetModelName()Gets the name of the model.longgetModelSize()Gets the size of the model in bytes.StringgetModelVersion()Gets the version of the model.Map<String,Object>getOutputSchema()Gets the output schema describing model outputs.inthashCode()Returns a hash code based on all metadata fields.StringtoString()Returns a string representation of the model metadata.
-
-
-
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 bytesloadTimestamp- 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.
-
equals
public boolean equals(Object o)
Compares this metadata to another object for equality.
-
-