WeaviateEx.Types.Vector (WeaviateEx v0.7.4)
View SourceVector type with multi-dimensional support for ColBERT and other advanced models.
Supports both standard 1D vectors and multi-dimensional vectors (2D arrays) used by models like ColBERT for late interaction retrieval.
Standard Vectors
Most embeddings are 1D vectors:
vector = [0.1, 0.2, 0.3, 0.4]
Vector.validate(vector)
# => :ok
Vector.shape(vector)
# => {4}Multi-Dimensional Vectors
Some models like ColBERT produce multi-dimensional vectors:
multi_vector = [[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]]
Vector.validate(multi_vector)
# => :ok
Vector.shape(multi_vector)
# => {3, 2}
Summary
Functions
Computes the cosine similarity between two vectors.
Returns the dimensionality of a vector.
Computes the dot product of two vectors.
Checks if a vector is multi-dimensional.
Normalizes a vector to unit length (L2 normalization).
Checks if a vector is 1-dimensional.
Returns the shape of a vector.
Validates a vector or multi-dimensional vector.
Types
Functions
Computes the cosine similarity between two vectors.
Examples
Vector.cosine_similarity([1.0, 0.0], [0.0, 1.0])
# => 0.0
Vector.cosine_similarity([1.0, 0.0], [1.0, 0.0])
# => 1.0
@spec dimensionality(t()) :: non_neg_integer()
Returns the dimensionality of a vector.
For 1D vectors, returns the length. For multi-dimensional vectors, returns the inner dimension.
Examples
Vector.dimensionality([0.1, 0.2, 0.3])
# => 3
Vector.dimensionality([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
# => 2
Computes the dot product of two vectors.
Examples
Vector.dot_product([1.0, 2.0], [3.0, 4.0])
# => 11.0
Checks if a vector is multi-dimensional.
Examples
Vector.multi_dimensional?([[0.1, 0.2], [0.3, 0.4]])
# => true
Vector.multi_dimensional?([0.1, 0.2, 0.3])
# => false
Normalizes a vector to unit length (L2 normalization).
Examples
Vector.normalize([3.0, 4.0])
# => [0.6, 0.8]
Checks if a vector is 1-dimensional.
Examples
Vector.one_dimensional?([0.1, 0.2, 0.3])
# => true
Vector.one_dimensional?([[0.1, 0.2], [0.3, 0.4]])
# => false
@spec shape(t()) :: {non_neg_integer()} | {non_neg_integer(), non_neg_integer()}
Returns the shape of a vector.
Examples
Vector.shape([0.1, 0.2, 0.3, 0.4])
# => {4}
Vector.shape([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]])
# => {3, 2}
Validates a vector or multi-dimensional vector.
Examples
Vector.validate([0.1, 0.2, 0.3])
# => :ok
Vector.validate([[0.1, 0.2], [0.3, 0.4]])
# => :ok
Vector.validate([])
# => {:error, "Vector cannot be empty"}
Vector.validate([[0.1, 0.2], [0.3]])
# => {:error, "Multi-dimensional vectors must have consistent inner dimensions"}