Skip to main content

Module simd

Module simd 

Source
Expand description

SIMD vector operations for embedding similarity and compressed-vector search.

Dispatch uses the best supported target kernel with scalar fallbacks; WASM SIMD128 is selected at compile time. The public SIMD surface is unstable.

See docs/simd.md for the kernel family, dispatch, and quantization design.

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 with caller-provided normalization metadata.
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 same-tier 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: quantizes an f32 query and computes tiered cosine distance.
approximate_cosine_distance_prepared
Unstable: computes prepared cosine distance in [0, 2] for matching tiers.
approximate_cosine_distance_prepared_with_meta
Computes prepared cosine distance; hints are accepted but do not select a separate code path.
approximate_dot_product
Unstable: approximate tiered dot-product dispatch.
approximate_dot_product_prepared
Unstable: computes a prepared dot product for matching non-binary tiers.
approximate_int4_batch_prepared
Computes distances from one prepared INT4 query without re-quantizing it.
approximate_int4_batch_prepared_into
Writes prepared INT4 distances into a reusable buffer, clearing it on error.
approximate_int8_batch_prepared
Computes distances from one prepared INT8 query without re-quantizing it.
approximate_int8_batch_prepared_into
Writes prepared INT8 distances into a reusable buffer, clearing it on error.
batch_approximate_cosine_distance_prepared
Computes distances from one prepared query to all stored vectors.
batch_approximate_cosine_distance_prepared_into
Writes prepared-query distances into a reusable buffer, clearing it on error.
batch_cosine_one_vs_many
Unstable: one-query/many-candidate cosine similarity.
batch_cosine_similarity
Unstable: batched cosine dispatch; callers supply normalization knowledge.
batch_dot_product
Unstable: batched dot-product dispatch with a same-query fast path.
cosine_similarity
Computes cosine similarity, returning 0.0 for a mismatch, empty input, or zero norm.
cosine_similarity_fused
Unstable: fused single-pass cosine similarity.
cosine_similarity_i8
Unstable: SIMD INT8 cosine similarity; norm storage approach may change.
cosine_similarity_pre_normalized
Cosine similarity against a query whose norm the caller already knows.
dot_product
Computes the float dot product, returning 0.0 for a dimensional mismatch.
dot_product_batch4
Compute dot product of one query against 4 candidates simultaneously.
dot_product_i8
Unstable: computes an approximate float dot product, returning 0.0 for a mismatch.
dot_product_i8_raw
Unstable: computes an unscaled raw INT8 dot product, returning 0.0 for a mismatch.
euclidean_distance
Computes Euclidean (L2) distance, returning f32::MAX for a dimensional mismatch.
is_unit_norm
Returns true when the squared norm of v is within 1e-4 of 1.0.
manhattan_distance
Computes Manhattan (L1) distance, the sum of absolute per-element differences.
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.
query_norm
The query-side norm for cosine_similarity_pre_normalized.
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 for tight loops.
simd_config
Unstable: SIMD dispatch internal; shape may change as new backends are added.
squared_euclidean_distance
Computes squared Euclidean distance without a square root.
try_approximate_cosine_distance_prepared
Alias for approximate_cosine_distance_prepared retained for compatibility.
try_approximate_dot_product_prepared
Alias for approximate_dot_product_prepared retained for compatibility.

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.