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§
- Binary
Vector - Unstable: binary quantization format and struct layout are under active design.
- Int4
Params - Unstable: INT4 quantization internals; scale/bias scheme may change.
- Int4
Vector - Unstable: INT4 quantization format is under active design; struct layout may change.
- Prepared
Query With Meta - A prepared query annotated with a normalization hint for fast-path dispatch.
- Quantization
Params - Unstable: INT8 quantization parameters; scale/bias scheme may change.
- Quantized
Vector - Unstable: INT8 quantized vector; struct layout and invariants may change.
- Simd
Config - Unstable: SIMD dispatch internals; fields may be added as new ISAs are supported.
Enums§
- Normalization
Hint - Caller assertion that a vector is L2-unit-normalized (norm ≈ 1).
- Prepared
Query - Unstable: pre-quantized query for repeated distance computation.
- Quantization
Tier - Unstable: tier design is under active iteration; tier boundaries may change.
- Quantized
Data - 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_preparedbut writes into a caller-supplied buffer. - batch_
cosine_ similarity - Unstable: SIMD batch dispatch; use
lattice_embed::utils::batch_cosine_similarityfor stable wrapper. - batch_
dot_ product - Unstable: SIMD batch dispatch; use
lattice_embed::utils::batch_dot_productfor stable wrapper. - cosine_
similarity - Unstable: SIMD dispatch layer; use
lattice_embed::utils::cosine_similarityfor 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_productfor 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_distancefor the stable wrapper. - is_
unit_ norm - Returns
truewhen the squared norm ofvis within 1e-4 of 1.0. - normalize
- Unstable: SIMD dispatch layer; use
lattice_embed::utils::normalizefor 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§
- DotBatch4
Kernel - SIMD kernel type for batch-4 f32 dot product.
- DotKernel
- SIMD kernel function pointer type for f32 dot product.
- I8Dot
Kernel - INT8 dot-product kernel function pointer type.