Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty registry.

Source

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).

Source

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.

Source

pub fn get_version( &self, measurement: &str, model_name: &str, version: u64, ) -> Option<ModelVersion>

Get a specific version.

Source

pub fn get_champion( &self, measurement: &str, model_name: &str, ) -> Option<ModelVersion>

Get the champion version for a measurement+name.

Source

pub fn list_versions( &self, measurement: &str, model_name: &str, ) -> Vec<ModelVersion>

List all versions for a measurement+name.

Source

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.

Source

pub fn update_metrics( &self, measurement: &str, model_name: &str, version: u64, metrics: AccuracyMetrics, ) -> bool

Update accuracy metrics for a specific version.

Source

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.

Source

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.

Source

pub fn total_versions(&self) -> usize

Total number of registered model versions across all keys.

Trait Implementations§

Source§

impl Debug for ModelRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more