pub struct EmbeddingSpace { /* private fields */ }Expand description
Metadata about an embedding space.
An embedding space defines the properties of embeddings stored within it:
- The dimension of vectors in the space
- The distance metric used for similarity search
§Example
use manifoldb_vector::types::{EmbeddingName, EmbeddingSpace};
use manifoldb_vector::distance::DistanceMetric;
let name = EmbeddingName::new("text_embedding").unwrap();
let space = EmbeddingSpace::new(name, 384, DistanceMetric::Cosine);
assert_eq!(space.dimension(), 384);
assert_eq!(space.distance_metric(), DistanceMetric::Cosine);Implementations§
Source§impl EmbeddingSpace
impl EmbeddingSpace
Sourcepub const fn new(
name: EmbeddingName,
dimension: usize,
distance_metric: DistanceMetric,
) -> Self
pub const fn new( name: EmbeddingName, dimension: usize, distance_metric: DistanceMetric, ) -> Self
Create a new embedding space.
Sourcepub fn name(&self) -> &EmbeddingName
pub fn name(&self) -> &EmbeddingName
Get the name of the embedding space.
Sourcepub fn distance_metric(&self) -> DistanceMetric
pub fn distance_metric(&self) -> DistanceMetric
Get the distance metric used for similarity search.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, VectorError>
pub fn to_bytes(&self) -> Result<Vec<u8>, VectorError>
Encode the embedding space to bytes.
Format:
- 1 byte: version
- 2 bytes: name length (big-endian u16)
- N bytes: name (UTF-8)
- 4 bytes: dimension (big-endian u32)
- 1 byte: distance metric
§Errors
Returns an error if the name length exceeds u16::MAX or the dimension exceeds u32::MAX.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, VectorError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, VectorError>
Decode an embedding space from bytes.
§Errors
Returns an error if the bytes are invalid or truncated.
Trait Implementations§
Source§impl Clone for EmbeddingSpace
impl Clone for EmbeddingSpace
Source§fn clone(&self) -> EmbeddingSpace
fn clone(&self) -> EmbeddingSpace
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for EmbeddingSpace
impl Debug for EmbeddingSpace
Source§impl PartialEq for EmbeddingSpace
impl PartialEq for EmbeddingSpace
impl Eq for EmbeddingSpace
impl StructuralPartialEq for EmbeddingSpace
Auto Trait Implementations§
impl Freeze for EmbeddingSpace
impl RefUnwindSafe for EmbeddingSpace
impl Send for EmbeddingSpace
impl Sync for EmbeddingSpace
impl Unpin for EmbeddingSpace
impl UnwindSafe for EmbeddingSpace
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
Mutably borrows from an owned value. Read more