Skip to main content

AnnSpec

Struct AnnSpec 

Source
#[non_exhaustive]
pub struct AnnSpec { pub dim: u32, pub distance: u8, pub m: u16, pub ef: u16, }
Expand description

HNSW declaration (immutable once created).

use kevy_index::AnnSpec;
let a = AnnSpec::new(128).with_distance(1).with_m(32);
assert_eq!((a.dim, a.distance, a.m, a.ef), (128, 1, 32, 200));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§dim: u32

Vector dimensionality (field bytes must be dim×4 f32 LE).

let s = IndexSpec::builder("v", "doc:", IndexKind::Ann, ValType::Vector)
    .with_field("emb")
    .with_ann(AnnSpec::new(3))
    .build()?;
let dim = s.ann().expect("an ann index").dim;
// a stored vector is dim little-endian f32s
let v: Vec<u8> = [0.5f32, 1.0, 2.0].iter().flat_map(|x| x.to_le_bytes()).collect();
assert_eq!(v.len(), dim as usize * 4);
§distance: u8

0=cosine 1=l2 2=ip (kevy-vector’s Distance tags).

let s = IndexSpec::builder("v", "doc:", IndexKind::Ann, ValType::Vector)
    .with_field("emb")
    .with_ann(AnnSpec::new(3).with_distance(1))
    .build()?;
assert_eq!(s.ann().map(|a| a.distance), Some(1), "l2");
§m: u16

Max links per node per layer.

let s = IndexSpec::builder("v", "doc:", IndexKind::Ann, ValType::Vector)
    .with_field("emb")
    .build();
// the parameters are required on an ann index
assert!(s.is_err());
assert_eq!(kevy_index::AnnSpec::new(3).m, 16, "the IDX.CREATE default");
§ef: u16

Construction beam width.

let s = IndexSpec::builder("v", "doc:", IndexKind::Ann, ValType::Vector)
    .with_field("emb")
    .with_ann(AnnSpec::new(3).with_ef(64))
    .build()?;
assert_eq!(s.ann().map(|a| a.ef), Some(64));

Implementations§

Source§

impl AnnSpec

Source

pub fn new(dim: u32) -> AnnSpec

A dim-dimensional cosine graph with the HNSW defaults (M 16, EF 200), the values IDX.CREATE uses when the options are not given.

let a = kevy_index::AnnSpec::new(4);
assert_eq!((a.distance, a.m, a.ef), (0, 16, 200));
Source

pub fn with_distance(self, distance: u8) -> AnnSpec

This graph under distance tag distance (0 cosine, 1 l2, 2 ip).

assert_eq!(kevy_index::AnnSpec::new(4).with_distance(2).distance, 2);
Source

pub fn with_m(self, m: u16) -> AnnSpec

This graph with at most m links per node per layer.

assert_eq!(kevy_index::AnnSpec::new(4).with_m(8).m, 8);
Source

pub fn with_ef(self, ef: u16) -> AnnSpec

This graph built with beam width ef.

assert_eq!(kevy_index::AnnSpec::new(4).with_ef(64).ef, 64);

Trait Implementations§

Source§

impl Clone for AnnSpec

Source§

fn clone(&self) -> AnnSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for AnnSpec

Source§

impl Debug for AnnSpec

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for AnnSpec

Source§

impl Hash for AnnSpec

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AnnSpec

Source§

fn eq(&self, other: &AnnSpec) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AnnSpec

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.