pub struct ModelRegistry { /* private fields */ }Expand description
Thread-safe in-memory model registry with versioning and tagging.
Per measurement+name key, maintains an ordered list of versions.
At most one version can be tagged Champion per key.
All methods take &self and acquire internal locks as needed,
so the registry can be shared across threads via Arc<ModelRegistry>.
§Iteration Order
The inner BTreeMap guarantees deterministic (sorted) iteration
order, which is important for snapshot reproducibility and
consistent API responses.
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn register(
&self,
measurement: &str,
model_name: &str,
algorithm: &str,
hyperparameters: HashMap<String, String>,
training_range: (i64, i64),
model_bytes: Vec<u8>,
) -> ModelVersion
pub fn register( &self, measurement: &str, model_name: &str, algorithm: &str, hyperparameters: HashMap<String, String>, training_range: (i64, i64), model_bytes: Vec<u8>, ) -> ModelVersion
Register a new model version, auto-incrementing the version number.
Returns the registered ModelVersion (cloned, since the registry
holds an internal lock).
Sourcepub fn get_latest(
&self,
measurement: &str,
model_name: &str,
) -> Option<ModelVersion>
pub fn get_latest( &self, measurement: &str, model_name: &str, ) -> Option<ModelVersion>
Get the latest version for a measurement+name.
Verifies model integrity on retrieval via SHA-256 hash.
Uses borrowed key lookup to avoid String allocation.
Sourcepub fn get_version(
&self,
measurement: &str,
model_name: &str,
version: u64,
) -> Option<ModelVersion>
pub fn get_version( &self, measurement: &str, model_name: &str, version: u64, ) -> Option<ModelVersion>
Get a specific version.
Sourcepub fn get_champion(
&self,
measurement: &str,
model_name: &str,
) -> Option<ModelVersion>
pub fn get_champion( &self, measurement: &str, model_name: &str, ) -> Option<ModelVersion>
Get the champion version for a measurement+name.
Sourcepub fn list_versions(
&self,
measurement: &str,
model_name: &str,
) -> Vec<ModelVersion>
pub fn list_versions( &self, measurement: &str, model_name: &str, ) -> Vec<ModelVersion>
List all versions for a measurement+name.
Sourcepub fn set_tag(
&self,
measurement: &str,
model_name: &str,
version: u64,
tag: ModelTag,
) -> bool
pub fn set_tag( &self, measurement: &str, model_name: &str, version: u64, tag: ModelTag, ) -> bool
Tag a specific version. Ensures only one champion per key.
Returns false if the key or version doesn’t exist, without
modifying any existing tags.
Sourcepub fn update_metrics(
&self,
measurement: &str,
model_name: &str,
version: u64,
metrics: AccuracyMetrics,
) -> bool
pub fn update_metrics( &self, measurement: &str, model_name: &str, version: u64, metrics: AccuracyMetrics, ) -> bool
Update accuracy metrics for a specific version.
Sourcepub fn rollback_champion(
&self,
measurement: &str,
model_name: &str,
version: u64,
) -> bool
pub fn rollback_champion( &self, measurement: &str, model_name: &str, version: u64, ) -> bool
Rollback: promote a previous version to champion, retiring the current one.
Convenience method for the common rollback workflow. Equivalent
to set_tag(measurement, model_name, version, ModelTag::Champion) but
logs the rollback event for auditability.
Returns false if the key or version doesn’t exist.
Sourcepub fn delete_version(
&self,
measurement: &str,
model_name: &str,
version: u64,
) -> bool
pub fn delete_version( &self, measurement: &str, model_name: &str, version: u64, ) -> bool
Delete a specific model version.
Allows removing bad versions from the registry. Refuses to
delete the current champion — call set_tag or rollback_champion
first to promote a different version.
Returns true if the version was found and deleted.
Sourcepub fn total_versions(&self) -> usize
pub fn total_versions(&self) -> usize
Total number of registered model versions across all keys.
Trait Implementations§
Source§impl Debug for ModelRegistry
impl Debug for ModelRegistry
Auto Trait Implementations§
impl !Freeze for ModelRegistry
impl !RefUnwindSafe for ModelRegistry
impl Send for ModelRegistry
impl Sync for ModelRegistry
impl Unpin for ModelRegistry
impl UnsafeUnpin for ModelRegistry
impl UnwindSafe for ModelRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more