#[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: u32Vector 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: u80=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: u16Max 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: u16Construction 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
impl AnnSpec
Sourcepub fn new(dim: u32) -> AnnSpec
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));Sourcepub fn with_distance(self, distance: u8) -> AnnSpec
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);Trait Implementations§
impl Copy for AnnSpec
impl Eq for AnnSpec
impl StructuralPartialEq for AnnSpec
Auto Trait Implementations§
impl Freeze for AnnSpec
impl RefUnwindSafe for AnnSpec
impl Send for AnnSpec
impl Sync for AnnSpec
impl Unpin for AnnSpec
impl UnsafeUnpin for AnnSpec
impl UnwindSafe for AnnSpec
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