pub trait EmbeddingSpace:
Clone
+ PartialEq
+ Eq
+ Debug
+ Send
+ Sync {
type EmbeddingData: Embedding;
type DistanceValue: Distance;
type Prepared: Clone;
// Required methods
fn space_id(&self) -> &'static str;
fn distance(
&self,
lhs: &Self::EmbeddingData,
rhs: &Self::EmbeddingData,
) -> Self::DistanceValue;
fn prepare(&self, embedding: &Self::EmbeddingData) -> Self::Prepared;
fn distance_prepared(
&self,
prepared: &Self::Prepared,
target: &Self::EmbeddingData,
) -> Self::DistanceValue;
fn length() -> usize;
fn infinite_mapping(native_distance: &Self::DistanceValue) -> f32;
fn slice_distance(a: &[f32], b: &[f32]) -> f32;
// Provided methods
fn create_embedding(
data: Vec<<Self::EmbeddingData as Embedding>::Scalar>,
) -> Self::EmbeddingData { ... }
fn create_distance(dist: f32) -> Self::DistanceValue { ... }
fn zero_vector() -> Self::EmbeddingData { ... }
fn zero_distance() -> Self::DistanceValue { ... }
}Expand description
An embedding space defines the embedding type, distance metric, and space properties.
Required Associated Types§
type EmbeddingData: Embedding
type DistanceValue: Distance
Required Methods§
fn space_id(&self) -> &'static str
Sourcefn distance(
&self,
lhs: &Self::EmbeddingData,
rhs: &Self::EmbeddingData,
) -> Self::DistanceValue
fn distance( &self, lhs: &Self::EmbeddingData, rhs: &Self::EmbeddingData, ) -> Self::DistanceValue
Compute distance between two embeddings.
Sourcefn prepare(&self, embedding: &Self::EmbeddingData) -> Self::Prepared
fn prepare(&self, embedding: &Self::EmbeddingData) -> Self::Prepared
Prepare a query embedding for efficient repeated distance computations.
Sourcefn distance_prepared(
&self,
prepared: &Self::Prepared,
target: &Self::EmbeddingData,
) -> Self::DistanceValue
fn distance_prepared( &self, prepared: &Self::Prepared, target: &Self::EmbeddingData, ) -> Self::DistanceValue
Compute distance using prepared query state.
fn length() -> usize
Sourcefn infinite_mapping(native_distance: &Self::DistanceValue) -> f32
fn infinite_mapping(native_distance: &Self::DistanceValue) -> f32
Maps a finite distance range to an infinite range (e.g., tan(pi * x / 4))
Sourcefn slice_distance(a: &[f32], b: &[f32]) -> f32
fn slice_distance(a: &[f32], b: &[f32]) -> f32
Compute the space’s distance metric on raw scalar slices of arbitrary length.
This is the same distance function as distance() but operates on raw f32 slices
rather than typed EmbeddingData. Used when the caller has subvectors or
centroid slices that don’t match the full embedding dimension.
Provided Methods§
fn create_embedding( data: Vec<<Self::EmbeddingData as Embedding>::Scalar>, ) -> Self::EmbeddingData
fn create_distance(dist: f32) -> Self::DistanceValue
fn zero_vector() -> Self::EmbeddingData
fn zero_distance() -> Self::DistanceValue
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.