pub struct VsaConfig {
pub dimension: usize,
pub density: f64,
pub min_nonzero: usize,
pub max_nonzero: usize,
pub auto_thin_threshold: usize,
pub scaling_mode: SparsityScaling,
pub target_accuracy: f64,
}Expand description
Configuration for VSA vector operations
Controls the dimensionality and sparsity of vectors. This allows
dynamic configuration of vector dimensions at runtime rather than
being locked to the compile-time DIM constant.
§Example
use embeddenator_vsa::VsaConfig;
// Default 10,000 dimensions
let default_config = VsaConfig::default();
assert_eq!(default_config.dimension, 10_000);
// Custom configuration for smaller vectors
let small_config = VsaConfig::new(1000).with_density(0.02); // 2% density
// Configuration for larger vectors
let large_config = VsaConfig::new(100_000).with_density(0.005); // 0.5% densityFields§
§dimension: usizeNumber of dimensions in vectors
density: f64Target density of non-zero elements (0.0 to 1.0) Default is 0.01 (1% density)
min_nonzero: usizeMinimum non-zero elements per vector
max_nonzero: usizeMaximum non-zero elements per vector
auto_thin_threshold: usizeAuto-thinning threshold: automatically thin bundles when nnz exceeds this Set to 0 to disable auto-thinning
scaling_mode: SparsityScalingDynamic sparsity scaling mode
target_accuracy: f64Target reconstruction accuracy (0.0-1.0)
Used by for_accuracy() to select appropriate dimensions
Implementations§
Source§impl VsaConfig
impl VsaConfig
Sourcepub fn new(dimension: usize) -> Self
pub fn new(dimension: usize) -> Self
Create a new VSA configuration with the specified dimension
Sourcepub fn with_density(self, density: f64) -> Self
pub fn with_density(self, density: f64) -> Self
Set the target density for non-zero elements
Sourcepub fn with_min_nonzero(self, min: usize) -> Self
pub fn with_min_nonzero(self, min: usize) -> Self
Set minimum number of non-zero elements
Sourcepub fn with_max_nonzero(self, max: usize) -> Self
pub fn with_max_nonzero(self, max: usize) -> Self
Set maximum number of non-zero elements
Sourcepub fn with_auto_thin(self, threshold: usize) -> Self
pub fn with_auto_thin(self, threshold: usize) -> Self
Set auto-thinning threshold (0 to disable)
Sourcepub fn with_scaling(self, mode: SparsityScaling) -> Self
pub fn with_scaling(self, mode: SparsityScaling) -> Self
Set sparsity scaling mode
Sourcepub fn with_target_accuracy(self, accuracy: f64) -> Self
pub fn with_target_accuracy(self, accuracy: f64) -> Self
Set target reconstruction accuracy
Sourcepub fn sparsity(&self) -> usize
pub fn sparsity(&self) -> usize
Calculate the sparsity (number of non-zero elements per polarity) based on dimension, density, and scaling mode
Sourcepub fn for_accuracy(target: f64) -> Self
pub fn for_accuracy(target: f64) -> Self
Create configuration optimized for a target reconstruction accuracy
This automatically selects dimension and density based on empirical relationships between VSA parameters and encoding fidelity.
| Accuracy | Dimension | Density | Typical Use Case |
|---|---|---|---|
| 0.90 | 5,000 | 2% | Fast prototyping |
| 0.95 | 10,000 | 1% | Default balance |
| 0.98 | 50,000 | 0.5% | High fidelity |
| 0.99 | 100,000 | 0.3% | Production |
§Example
use embeddenator_vsa::VsaConfig;
// Create config targeting 95% reconstruction accuracy
let config = VsaConfig::for_accuracy(0.95);
// Accuracy maps to 25K dimensions (between 0.95 and 0.98)
assert!(config.dimension >= 10_000 && config.dimension <= 50_000);Sourcepub fn from_schema(schema: VsaConfigSchema) -> Self
pub fn from_schema(schema: VsaConfigSchema) -> Self
Create configuration from a custom schema/specification
Allows users to provide their own parameter mapping for specialized use cases.
§Example
use embeddenator_vsa::{VsaConfig, VsaConfigSchema, SparsityScaling};
// Custom schema for memory-constrained embedded systems
let schema = VsaConfigSchema {
dimension: 4096,
density: 0.025,
scaling: Some(SparsityScaling::Logarithmic),
auto_thin: Some(512),
min_nnz: Some(8),
max_nnz: Some(256),
target_accuracy: None,
};
let config = VsaConfig::from_schema(schema);
assert_eq!(config.dimension, 4096);Sourcepub fn huge() -> Self
pub fn huge() -> Self
Configuration for huge vectors (1,000,000 dimensions) Use sparingly - memory intensive
Sourcepub fn effective_auto_thin(&self) -> usize
pub fn effective_auto_thin(&self) -> usize
Get the effective auto-thin threshold, accounting for dimension
Sourcepub fn should_thin(&self, nnz: usize) -> bool
pub fn should_thin(&self, nnz: usize) -> bool
Check if a vector exceeds the auto-thin threshold