Skip to main content

VsaConfig

Struct VsaConfig 

Source
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% density

Fields§

§dimension: usize

Number of dimensions in vectors

§density: f64

Target density of non-zero elements (0.0 to 1.0) Default is 0.01 (1% density)

§min_nonzero: usize

Minimum non-zero elements per vector

§max_nonzero: usize

Maximum non-zero elements per vector

§auto_thin_threshold: usize

Auto-thinning threshold: automatically thin bundles when nnz exceeds this Set to 0 to disable auto-thinning

§scaling_mode: SparsityScaling

Dynamic sparsity scaling mode

§target_accuracy: f64

Target reconstruction accuracy (0.0-1.0) Used by for_accuracy() to select appropriate dimensions

Implementations§

Source§

impl VsaConfig

Source

pub fn new(dimension: usize) -> Self

Create a new VSA configuration with the specified dimension

Source

pub fn with_density(self, density: f64) -> Self

Set the target density for non-zero elements

Source

pub fn with_min_nonzero(self, min: usize) -> Self

Set minimum number of non-zero elements

Source

pub fn with_max_nonzero(self, max: usize) -> Self

Set maximum number of non-zero elements

Source

pub fn with_auto_thin(self, threshold: usize) -> Self

Set auto-thinning threshold (0 to disable)

Source

pub fn with_scaling(self, mode: SparsityScaling) -> Self

Set sparsity scaling mode

Source

pub fn with_target_accuracy(self, accuracy: f64) -> Self

Set target reconstruction accuracy

Source

pub fn sparsity(&self) -> usize

Calculate the sparsity (number of non-zero elements per polarity) based on dimension, density, and scaling mode

Source

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.

AccuracyDimensionDensityTypical Use Case
0.905,0002%Fast prototyping
0.9510,0001%Default balance
0.9850,0000.5%High fidelity
0.99100,0000.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);
Source

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);
Source

pub fn small() -> Self

Configuration for small vectors (1,000 dimensions)

Source

pub fn medium() -> Self

Configuration for medium vectors (10,000 dimensions - default)

Source

pub fn large() -> Self

Configuration for large vectors (100,000 dimensions)

Source

pub fn huge() -> Self

Configuration for huge vectors (1,000,000 dimensions) Use sparingly - memory intensive

Source

pub fn effective_auto_thin(&self) -> usize

Get the effective auto-thin threshold, accounting for dimension

Source

pub fn should_thin(&self, nnz: usize) -> bool

Check if a vector exceeds the auto-thin threshold

Trait Implementations§

Source§

impl Clone for VsaConfig

Source§

fn clone(&self) -> VsaConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for VsaConfig

Source§

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

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

impl Default for VsaConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for VsaConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for VsaConfig

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for VsaConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for VsaConfig

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,