Struct AnchorSpaceIndex

Source
pub struct AnchorSpaceIndex {
    config: AnchorSetConfig,
    k: usize,
    projected_vectors: Vec<Vec<f32>>,
    source_model: Vec<u32>,
    entity_ids: Vec<u64>,
    timestamps: Vec<i64>,
    entity_index: BTreeMap<u64, Vec<(i64, u32)>>,
}
Expand description

An index operating in anchor-projected space (ℝᴷ).

Stores pre-projected vectors from potentially multiple embedding models. All comparable because they use the same anchor set.

Fields§

§config: AnchorSetConfig

Anchor set configuration.

§k: usize

Number of anchors (= dimensionality of projected space).

§projected_vectors: Vec<Vec<f32>>

Projected vectors: node_id → Vec of length K.

§source_model: Vec<u32>

Source model identifier per node.

§entity_ids: Vec<u64>

Entity ID per node.

§timestamps: Vec<i64>

Timestamp per node.

§entity_index: BTreeMap<u64, Vec<(i64, u32)>>

Entity index: entity_id → sorted vec of (timestamp, node_id).

Implementations§

Source§

impl AnchorSpaceIndex

Source

pub fn new(config: AnchorSetConfig, k: usize) -> Self

Create a new empty anchor space index.

Source

pub fn insert( &mut self, entity_id: u64, timestamp: i64, vector: &[f32], model_anchors: &[&[f32]], model_id: u32, ) -> u32

Insert a raw vector, projecting it to anchor space.

model_anchors are the anchor vectors embedded in the SAME model as the input vector. These may differ from anchors of other models.

Source

pub fn insert_projected( &mut self, entity_id: u64, timestamp: i64, projected: Vec<f32>, model_id: u32, ) -> u32

Insert a pre-projected vector (already in ℝᴷ).

Source

pub fn search( &self, query_projected: &[f32], k: usize, filter: TemporalFilter, ) -> Vec<(u32, f32)>

Search in anchor space: flat scan kNN by L2 distance in ℝᴷ.

Cross-model: results may come from ANY source model.

Source

pub fn trajectory( &self, entity_id: u64, filter: TemporalFilter, ) -> Vec<(i64, Vec<f32>)>

Retrieve trajectory in anchor space for an entity.

Source

pub fn cross_model_trajectory( &self, entity_id: u64, filter: TemporalFilter, ) -> BTreeMap<u32, Vec<(i64, Vec<f32>)>>

Cross-model trajectory: separate trajectories per source model.

Source

pub fn anchor_drift( &self, entity_id: u64, t1: i64, t2: i64, ) -> Option<AnchorDriftReport>

Compute drift in anchor space between two timestamps.

Source

pub fn len(&self) -> usize

Number of indexed points.

Source

pub fn is_empty(&self) -> bool

Whether the index is empty.

Source

pub fn n_entities(&self) -> usize

Number of unique entities.

Source

pub fn entity_id(&self, node_id: u32) -> u64

Get entity ID for a node.

Source

pub fn timestamp(&self, node_id: u32) -> i64

Get timestamp for a node.

Source

pub fn source_model(&self, node_id: u32) -> u32

Get source model for a node.

Source

pub fn projected_vector(&self, node_id: u32) -> &[f32]

Get projected vector for a node.

Source

pub fn config(&self) -> &AnchorSetConfig

Anchor set config.

Source

pub fn k(&self) -> usize

Dimensionality of the projected space (= number of anchors).

Source

pub fn save(&self, path: &Path) -> Result<()>

Save to file via postcard.

Source

pub fn load(path: &Path) -> Result<Self>

Load from file.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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