Representation-independent dense vector operations.
The same API accepts ordinary numeric lists, row-major little-endian f32
binaries, %Vettore.Vector{} wrappers, and—when the host application has Nx
installed—Nx.Tensor values. Native kernels operate directly on f32
binaries, while Nx remains an optional interchange format rather than a
runtime requirement.
Little-endian f32 binaries are suitable for persistence and model matrices:
iex> {:ok, binary} = Vettore.Vector.to_f32_binary([3.0, 4.0])
iex> Vettore.Vector.dimensions(binary)
{:ok, 2}
iex> {:ok, normalized} = Vettore.Vector.normalize(binary, :l2, as: :list)
iex> Enum.map(normalized, &Float.round(&1, 1))
[0.6, 0.8]The wrapper struct is useful at application boundaries where representation and dimensions should travel together:
iex> {:ok, vector} = Vettore.Vector.new([1, 2, 3], as: :f32_binary)
iex> {vector.representation, vector.dimensions}
{:f32_binary, 3}
iex> Vettore.Vector.to_list(vector)
{:ok, [1.0, 2.0, 3.0]}
Summary
Functions
Chebyshev/L-infinity distance over any supported representation.
Chebyshev/L-infinity distance with per-call compute options.
Converts between list, f32-binary, and optional Nx representations.
Cosine similarity, with the same normalization options as Vettore.Distance.cosine/3.
Returns the flattened coordinate count.
Compatibility alias for inner_product/2.
Compatibility alias for inner_product/3.
Converts an Nx tensor into a validated Vettore representation.
Hamming distance using Vettore's non-zero coordinate semantics.
Hamming distance with per-call compute options.
Inner/dot product over any supported representation.
Inner/dot product with per-call compute options.
Jaccard distance using Vettore's non-zero coordinate semantics.
Jaccard distance with per-call compute options.
L2/Euclidean distance over any supported representation.
L2/Euclidean distance with per-call compute options.
Squared L2 distance over any supported representation.
Squared L2 distance with per-call compute options.
Manhattan/L1 distance over any supported representation.
Manhattan/L1 distance with per-call compute options.
Returns the row/column shape of a row-major little-endian f32 matrix.
Mean-pools a non-empty list of equally sized vectors.
Mean-pools selected rows from a row-major little-endian f32 matrix.
Computes one named metric over any pair of supported representations.
Negative inner product over any supported representation.
Negative inner product with per-call compute options.
Builds a dimensioned vector wrapper in the requested representation.
Normalizes a vector while allowing the result representation to be selected.
Returns the storage representation used by a supported vector value.
Returns a wrapper with new shape metadata, without changing coordinate order.
Returns the original tensor shape, or a one-dimensional shape for flat values.
Stacks equally sized vectors into a row-major matrix representation.
Selects rows from a row-major f32 matrix without mean pooling them.
Converts any supported vector to a validated little-endian f32 binary.
Converts any supported vector to a validated flat float list.
Converts a vector to an Nx tensor, preserving shape and accepting a host backend.
Checks the vector representation, finite f32 values, and wrapper metadata.
Returns whether a complete row-major f32 matrix is structurally valid and finite.
Validates a complete f32 matrix and returns its shape.
Types
@type metric() :: Vettore.Distance.metric()
@type normalization() :: :none | :l2 | :zscore | :minmax
@type representation() :: :list | :f32_binary | :nx
@type t() :: %Vettore.Vector{ data: raw_vector(), dimensions: non_neg_integer(), representation: representation(), shape: tuple() | nil }
@type target_representation() :: representation() | :same
@type vector() :: raw_vector() | t()
Functions
Chebyshev/L-infinity distance over any supported representation.
Chebyshev/L-infinity distance with per-call compute options.
@spec convert(vector(), target_representation()) :: {:ok, raw_vector()} | {:error, term()}
Converts between list, f32-binary, and optional Nx representations.
Cosine similarity, with the same normalization options as Vettore.Distance.cosine/3.
@spec dimensions(vector()) :: {:ok, non_neg_integer()} | {:error, term()}
Returns the flattened coordinate count.
Compatibility alias for inner_product/2.
Compatibility alias for inner_product/3.
@spec from_nx(term(), :list | :f32_binary) :: {:ok, raw_vector()} | {:error, term()}
Converts an Nx tensor into a validated Vettore representation.
Hamming distance using Vettore's non-zero coordinate semantics.
Hamming distance with per-call compute options.
Inner/dot product over any supported representation.
Inner/dot product with per-call compute options.
Jaccard distance using Vettore's non-zero coordinate semantics.
Jaccard distance with per-call compute options.
L2/Euclidean distance over any supported representation.
L2/Euclidean distance with per-call compute options.
Squared L2 distance over any supported representation.
Squared L2 distance with per-call compute options.
Manhattan/L1 distance over any supported representation.
Manhattan/L1 distance with per-call compute options.
@spec matrix_shape_f32(binary(), pos_integer()) :: {:ok, {non_neg_integer(), pos_integer()}} | {:error, term()}
Returns the row/column shape of a row-major little-endian f32 matrix.
@spec mean_pool( [vector()], keyword() ) :: {:ok, raw_vector()} | {:error, term()}
Mean-pools a non-empty list of equally sized vectors.
@spec mean_pool_f32(binary(), pos_integer(), [non_neg_integer()], keyword()) :: {:ok, raw_vector()} | {:error, term()}
Mean-pools selected rows from a row-major little-endian f32 matrix.
The result defaults to :f32_binary; pass as: :list or as: :nx when a
different interchange representation is needed. Repeated indices are
counted repeatedly, matching token-sequence pooling semantics.
Computes one named metric over any pair of supported representations.
Negative inner product over any supported representation.
Negative inner product with per-call compute options.
Builds a dimensioned vector wrapper in the requested representation.
@spec normalize(vector(), normalization(), keyword()) :: {:ok, raw_vector()} | {:error, term()}
Normalizes a vector while allowing the result representation to be selected.
@spec representation(term()) :: representation() | :unknown
Returns the storage representation used by a supported vector value.
Returns a wrapper with new shape metadata, without changing coordinate order.
Returns the original tensor shape, or a one-dimensional shape for flat values.
Stacks equally sized vectors into a row-major matrix representation.
@spec take_rows_f32(binary(), pos_integer(), [non_neg_integer()], keyword()) :: {:ok, term()} | {:error, term()}
Selects rows from a row-major f32 matrix without mean pooling them.
Converts any supported vector to a validated little-endian f32 binary.
Converts any supported vector to a validated flat float list.
Converts a vector to an Nx tensor, preserving shape and accepting a host backend.
Checks the vector representation, finite f32 values, and wrapper metadata.
Returns whether a complete row-major f32 matrix is structurally valid and finite.
@spec validate_matrix_f32(binary(), pos_integer()) :: {:ok, {non_neg_integer(), pos_integer()}} | {:error, term()}
Validates a complete f32 matrix and returns its shape.