VectorRef

Trait VectorRef 

Source
pub trait VectorRef {
    // Required method
    fn as_slice(&self) -> &[f32];

    // Provided methods
    fn dimension(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A reference to vector data that may be borrowed or owned.

This trait abstracts over different ways to access vector data:

  • &[f32]: Direct slice reference (zero-copy from mmap)
  • Cow<[f32]>: Copy-on-write for flexibility
  • Vec<f32>: Owned data when needed

§Example

use velesdb_core::VectorRef;

fn compute_distance<V: VectorRef>(a: &V, b: &V) -> f32 {
    let a_slice = a.as_slice();
    let b_slice = b.as_slice();
    // SIMD distance calculation on slices
    crate::simd::cosine_similarity_fast(a_slice, b_slice)
}

Required Methods§

Source

fn as_slice(&self) -> &[f32]

Returns the vector data as a slice.

Provided Methods§

Source

fn dimension(&self) -> usize

Returns the dimension of the vector.

Source

fn is_empty(&self) -> bool

Returns true if the vector is empty.

Implementations on Foreign Types§

Source§

impl VectorRef for &[f32]

Source§

fn as_slice(&self) -> &[f32]

Source§

impl VectorRef for Cow<'_, [f32]>

Source§

fn as_slice(&self) -> &[f32]

Source§

impl VectorRef for Vec<f32>

Source§

fn as_slice(&self) -> &[f32]

Source§

impl VectorRef for [f32]

Source§

fn as_slice(&self) -> &[f32]

Implementors§