pub struct HnswConfigBuilder {
pub config: HnswConfig,
}Expand description
Builder pattern for HnswConfig construction
Provides a fluent interface for creating HnswConfig instances with validation and sensible defaults.
§Examples
use sqlitegraph::hnsw::{HnswConfig, DistanceMetric};
// Single-layer configuration (default, backward compatible)
let config = HnswConfigBuilder::new()
.dimension(512)
.m_connections(24)
.ef_construction(300)
.ef_search(80)
.max_layers(20)
.distance_metric(DistanceMetric::Euclidean)
.build()
.unwrap();
// Multi-layer configuration for large datasets
let multilayer_config = HnswConfigBuilder::new()
.dimension(768)
.m_connections(16)
.ef_construction(200)
.ef_search(50)
.max_layers(16)
.distance_metric(DistanceMetric::Cosine)
.enable_multilayer(true)
.multilayer_level_distribution_base(Some(16))
.multilayer_deterministic_seed(Some(42))
.build()
.unwrap();Fields§
§config: HnswConfigImplementations§
Source§impl HnswConfigBuilder
impl HnswConfigBuilder
Sourcepub fn m_connections(self, m: usize) -> Self
pub fn m_connections(self, m: usize) -> Self
Sourcepub fn ef_construction(self, ef: usize) -> Self
pub fn ef_construction(self, ef: usize) -> Self
Sourcepub fn max_layers(self, ml: u8) -> Self
pub fn max_layers(self, ml: u8) -> Self
Sourcepub fn distance_metric(self, metric: DistanceMetric) -> Self
pub fn distance_metric(self, metric: DistanceMetric) -> Self
Sourcepub fn enable_multilayer(self, enable: bool) -> Self
pub fn enable_multilayer(self, enable: bool) -> Self
Enable multi-layer HNSW functionality
When enabled, uses proper multi-layer HNSW with exponential distribution. When disabled, uses single-layer mode for backward compatibility.
§Arguments
enable- Whether to enable multi-layer functionality
Sourcepub fn multilayer_level_distribution_base(self, base: Option<usize>) -> Self
pub fn multilayer_level_distribution_base(self, base: Option<usize>) -> Self
Set base value for exponential level distribution in multi-layer mode
Higher values create flatter layer distributions (more vectors in higher layers). When None, uses the m parameter value as default.
§Arguments
base- Base value for level distribution, or None to use m
Sourcepub fn multilayer_deterministic_seed(self, seed: Option<u64>) -> Self
pub fn multilayer_deterministic_seed(self, seed: Option<u64>) -> Self
Set deterministic seed for multi-layer operations
When provided, ensures reproducible level assignments across runs. When None, uses non-deterministic behavior (default for production).
§Arguments
seed- Seed value, or None for non-deterministic behavior
Sourcepub fn build(self) -> Result<HnswConfig, HnswConfigError>
pub fn build(self) -> Result<HnswConfig, HnswConfigError>
Build the HnswConfig with validation
§Returns
Returns Ok(HnswConfig) if all parameters are valid,
or Err(HnswConfigError) if validation fails.
§Errors
InvalidDimensionif dimension is 0InvalidMParameterif m is 0InvalidEfConstructionif ef_construction < mInvalidEfSearchif ef_search is 0InvalidMaxLayersif ml is 0
§Examples
use sqlitegraph::hnsw::{HnswConfigBuilder, DistanceMetric};
let config = HnswConfigBuilder::new()
.dimension(256)
.distance_metric(DistanceMetric::Cosine)
.build()
.unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for HnswConfigBuilder
impl RefUnwindSafe for HnswConfigBuilder
impl Send for HnswConfigBuilder
impl Sync for HnswConfigBuilder
impl Unpin for HnswConfigBuilder
impl UnsafeUnpin for HnswConfigBuilder
impl UnwindSafe for HnswConfigBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more