Skip to main content

SemanticVersioningTracker

Struct SemanticVersioningTracker 

Source
pub struct SemanticVersioningTracker { /* private fields */ }
Expand description

Tracks semantic drift of concept embeddings across model versions.

§Overview

The tracker maintains a registry of named model/embedding versions and a set of anchor concepts — representative items whose embeddings should be stable between compatible versions. For each concept that exists in two versions the tracker computes the cosine distance of their embeddings, which it calls the drift score.

§Example

use ipfrs_semantic::semantic_versioning_tracker::{
    SemanticVersioningTracker, SvtTrackerConfig,
};

let config = SvtTrackerConfig { drift_threshold: 0.1, ..Default::default() };
let mut tracker = SemanticVersioningTracker::new(config);

let v1 = tracker.register_version("bert-v1", 3).unwrap();
let v2 = tracker.register_version("bert-v2", 3).unwrap();

tracker.add_anchor("cat", v1, vec![1.0, 0.0, 0.0]).unwrap();
tracker.add_anchor("cat", v2, vec![0.98, 0.1, 0.05]).unwrap();

let report = tracker.compute_drift(v1, v2).unwrap();
assert!(report.overall_drift < 0.1);

Implementations§

Source§

impl SemanticVersioningTracker

Source

pub fn new(config: SvtTrackerConfig) -> Self

Creates a new tracker with the supplied configuration.

Source

pub fn with_defaults() -> Self

Creates a tracker with default configuration.

Source

pub fn register_version( &mut self, name: impl Into<String>, dim: usize, ) -> Result<SvtVersionId, SvtError>

Registers a new version and returns its assigned SvtVersionId.

§Errors

Returns SvtError::DimMismatch (with expected = 0) if dim == 0.

Source

pub fn deprecate_version(&mut self, id: SvtVersionId) -> Result<(), SvtError>

Marks a version as deprecated (inactive).

§Errors

Returns SvtError::VersionNotFound if the ID is unknown.

Source

pub fn activate_version(&mut self, id: SvtVersionId) -> Result<(), SvtError>

Re-activates a previously deprecated version.

§Errors

Returns SvtError::VersionNotFound if the ID is unknown.

Source

pub fn get_version(&self, id: SvtVersionId) -> Result<&SvtVersion, SvtError>

Returns an immutable reference to the version metadata.

§Errors

Returns SvtError::VersionNotFound if the ID is unknown.

Source

pub fn list_versions(&self) -> Vec<&SvtVersion>

Returns all registered versions sorted by ID (ascending).

Source

pub fn active_versions(&self) -> Vec<&SvtVersion>

Returns only active versions sorted by ID (ascending).

Source

pub fn add_anchor( &mut self, concept: &str, version_id: SvtVersionId, embedding: Vec<f64>, ) -> Result<(), SvtError>

Registers a concept embedding for a specific version.

If an anchor for this (concept, version_id) pair already exists it is replaced.

§Errors
Source

pub fn get_anchor( &self, concept: &str, version_id: SvtVersionId, ) -> Result<&[f64], SvtError>

Returns the embedding for a specific (concept, version) pair.

§Errors
Source

pub fn concepts_for_version(&self, version_id: SvtVersionId) -> Vec<&str>

Returns all concepts that have anchors registered in the given version.

Source

pub fn compute_drift( &mut self, ver_a: SvtVersionId, ver_b: SvtVersionId, ) -> Result<SvtDriftReport, SvtError>

Computes a full drift report between two versions.

For each concept present in both versions the method computes the cosine distance and records it in the drift log.

§Errors
Source

pub fn find_drifted_concepts( &self, ver_a: SvtVersionId, ver_b: SvtVersionId, threshold: f64, ) -> Result<Vec<(String, f64)>, SvtError>

Returns concepts whose drift between the two versions exceeds threshold, sorted by score descending.

§Errors

Returns SvtError::VersionNotFound if either ID is unknown.

Source

pub fn semantic_similarity_over_time( &self, concept: &str, ) -> Result<Vec<(SvtVersionId, SvtVersionId, f64)>, SvtError>

Computes pairwise cosine similarity (not distance) between consecutive version pairs that share an anchor for concept.

Pairs are ordered by (version_a_id, version_b_id) ascending. At most config.window_size pairs are returned.

§Errors
Source

pub fn stability_score(&self, concept: &str) -> Result<f64, SvtError>

Computes a stability score in [0, 1] for a concept across all its consecutive version pairs.

stability = 1 – mean_drift where mean_drift is the mean cosine distance over all consecutive pairs. Returns 1.0 if fewer than 2 versions have the anchor (no drift measured).

§Errors
Source

pub fn recommend_migration( &self, from: SvtVersionId, to: SvtVersionId, ) -> Result<Vec<String>, SvtError>

Returns a list of concept names that should be re-verified when migrating from from to to.

A concept is flagged for re-verification when its drift score between the two versions exceeds config.drift_threshold.

§Errors

Returns SvtError::VersionNotFound if either ID is unknown.

Source

pub fn tracker_stats(&self) -> SvtTrackerStats

Returns aggregate statistics for this tracker instance.

Source

pub fn drift_log(&self) -> &VecDeque<SvtDriftEvent>

Returns a read-only slice of the drift log (oldest first).

Source

pub fn clear_drift_log(&mut self)

Clears all recorded drift events.

Source

pub fn config(&self) -> &SvtTrackerConfig

Returns the current tracker configuration.

Source

pub fn config_mut(&mut self) -> &mut SvtTrackerConfig

Returns a mutable reference to the configuration.

Source

pub fn add_anchors_batch( &mut self, items: impl IntoIterator<Item = (String, SvtVersionId, Vec<f64>)>, ) -> Vec<SvtError>

Registers multiple anchors at once.

Returns a Vec of errors (one per failed anchor); successful insertions are committed even if some fail.

Source

pub fn compute_all_consecutive_drifts( &mut self, ) -> Vec<Result<SvtDriftReport, SvtError>>

Computes drift reports for all consecutive active-version pairs, returning (report_or_error) for each pair.

Pairs are ordered by ascending version IDs.

Source

pub fn global_stability(&self) -> f64

Returns the mean stability score across all registered concepts.

Concepts with fewer than two version anchors contribute 1.0.

Source

pub fn concepts_by_stability(&self) -> Vec<(String, f64)>

Returns all concepts sorted by stability score descending (most stable first).

§Errors

This function only returns Err variants from internal calls; in practice they are suppressed and the concept is scored as 1.0.

Source

pub fn top_drifted_concepts( &self, ver_a: SvtVersionId, ver_b: SvtVersionId, n: usize, ) -> Result<Vec<(String, f64)>, SvtError>

Returns the n most drifted concepts between two versions.

§Errors

Returns SvtError::VersionNotFound if either ID is unknown.

Source

pub fn are_compatible( &mut self, ver_a: SvtVersionId, ver_b: SvtVersionId, ) -> Result<bool, SvtError>

Returns true if the two versions are semantically compatible, i.e. their overall drift is strictly below drift_threshold.

§Errors

Returns SvtError::VersionNotFound if either ID is unknown, or SvtError::InsufficientAnchors if not enough shared concepts exist.

Source

pub fn remove_version_anchors( &mut self, version_id: SvtVersionId, ) -> Result<usize, SvtError>

Removes all anchors for a given version ID and decrements anchor_count.

§Errors

Returns SvtError::VersionNotFound if the version is unknown.

Source

pub fn concept_drift_matrix( &self, ver_a: SvtVersionId, ver_b: SvtVersionId, ) -> Result<HashMap<String, f64>, SvtError>

Computes per-concept drift scores between two versions for all shared concepts, without recording to the drift log.

§Errors

Returns SvtError::VersionNotFound if either ID is unknown.

Trait Implementations§

Source§

impl Debug for SemanticVersioningTracker

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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