use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[repr(C)]
pub struct HnswConfig {
pub m: u32,
pub m0: u32,
pub ef_construction: u32,
pub ef_search: u32,
pub dimensions: u32,
pub metric: u32,
pub _reserved: [u32; 2], }
impl HnswConfig {
pub const METRIC_L2_SQUARED: u32 = 0;
pub const METRIC_COSINE: u32 = 1;
pub const METRIC_DOT_PRODUCT: u32 = 2;
pub const METRIC_HAMMING: u32 = 3;
#[must_use]
pub fn new(dimensions: u32) -> Self {
Self {
m: 12,
m0: 24,
ef_construction: 100,
ef_search: 50,
dimensions,
metric: Self::METRIC_L2_SQUARED,
_reserved: [0; 2],
}
}
}
const _: () = assert!(core::mem::size_of::<HnswConfig>() == 32);
const _: () = assert!(core::mem::align_of::<HnswConfig>() == 4);