Skip to main content

Module simd

Module simd 

Source
Expand description

SIMD-accelerated vector operations for embedding similarity.

Provides optimized implementations with automatic fallback:

  • x86_64 (float32): AVX-512F > AVX2 + FMA > scalar
  • x86_64 (int8): AVX-512 VNNI > AVX2 > scalar
  • aarch64: ARM NEON with multiple accumulators and loop unrolling
  • Other: Scalar fallback

§Optimizations

  • Multiple accumulators: 4 parallel accumulators to break dependency chains
  • Loop unrolling: Process 16/32/64 elements per iteration depending on ISA
  • AVX-512F: Wide float32 kernels for dot, cosine, normalize, and distance
  • AVX-512 VNNI: Integer VNNI instructions when available (quantized int8 path)

Structs§

BinaryVector
Unstable: binary quantization format and struct layout are under active design.
Int4Params
Unstable: INT4 quantization internals; scale/bias scheme may change.
Int4Vector
Unstable: INT4 quantization format is under active design; struct layout may change.
PreparedQueryWithMeta
A prepared query annotated with a normalization hint for fast-path dispatch.
QuantizationParams
Unstable: INT8 quantization parameters; scale/bias scheme may change.
QuantizedVector
Unstable: INT8 quantized vector; struct layout and invariants may change.
SimdConfig
Unstable: SIMD dispatch internals; fields may be added as new ISAs are supported.

Enums§

NormalizationHint
Caller assertion that a vector is L2-unit-normalized (norm ≈ 1).
PreparedQuery
Unstable: pre-quantized query for repeated distance computation.
QuantizationTier
Unstable: tier design is under active iteration; tier boundaries may change.
QuantizedData
Unstable: unified quantized data container; variants may change with tier redesign.

Functions§

approximate_cosine_distance
Unstable: tiered distance dispatch; tier mix and formula may change.
approximate_cosine_distance_prepared
Unstable: prepared cosine distance; query tier must match stored data tier.
approximate_cosine_distance_prepared_with_meta
Cosine distance with unit-norm fast path.
approximate_dot_product
Unstable: tiered dot product dispatch; tier mix and formula may change.
approximate_dot_product_prepared
Unstable: prepared dot product dispatch; query tier must match stored data tier.
batch_approximate_cosine_distance_prepared
Compute cosine distances from one prepared query to a slice of stored vectors.
batch_approximate_cosine_distance_prepared_into
Like batch_approximate_cosine_distance_prepared but writes into a caller-supplied buffer.
batch_cosine_similarity
Unstable: SIMD batch dispatch; use lattice_embed::utils::batch_cosine_similarity for stable wrapper.
batch_dot_product
Unstable: SIMD batch dispatch; use lattice_embed::utils::batch_dot_product for stable wrapper.
cosine_similarity
Unstable: SIMD dispatch layer; use lattice_embed::utils::cosine_similarity for the stable wrapper.
cosine_similarity_i8
Unstable: SIMD INT8 cosine similarity; norm storage approach may change.
dot_product
Unstable: SIMD dispatch layer; use lattice_embed::utils::dot_product for the stable wrapper.
dot_product_batch4
Compute dot product of one query against 4 candidates simultaneously.
dot_product_i8
Unstable: SIMD INT8 dot product; VNNI/AVX2/NEON dispatch may change.
dot_product_i8_raw
Unstable: raw SIMD INT8 hot path; signature and scaling semantics may change.
euclidean_distance
Unstable: SIMD dispatch layer; use lattice_embed::utils::euclidean_distance for the stable wrapper.
is_unit_norm
Returns true when the squared norm of v is within 1e-4 of 1.0.
normalize
Unstable: SIMD dispatch layer; use lattice_embed::utils::normalize for the stable wrapper.
prepare_query
Prepare a query vector for repeated distance computation against a homogeneous tier.
prepare_query_with_norm
Prepare a query annotated with the given normalization hint.
resolved_dot_product_batch4_kernel
Resolve the best available batch-4 f32 dot-product kernel once and return it.
resolved_dot_product_kernel
Resolve the best available f32 dot-product kernel once and return it.
resolved_i8_dot_kernel
Return the cached INT8 dot-product kernel.
simd_config
Unstable: SIMD dispatch internal; shape may change as new backends are added.
squared_euclidean_distance
Unstable: squared Euclidean distance — skips the final sqrt.
try_approximate_cosine_distance_prepared
Non-panicking variant of approximate_cosine_distance_prepared.
try_approximate_dot_product_prepared
Non-panicking variant of approximate_dot_product_prepared.

Type Aliases§

DotBatch4Kernel
SIMD kernel type for batch-4 f32 dot product.
DotKernel
SIMD kernel function pointer type for f32 dot product.
I8DotKernel
INT8 dot-product kernel function pointer type.