cosineDistance
Computes the cosine distance between two vectors, defined as one minus their cosine similarity. Values range from0 (identical direction) to 2 (opposite direction), so smaller values mean more similar orientation regardless of magnitude.
Syntax
vector1— first vector, an array or tuple of numeric values.vector2— second vector, an array or tuple of the same length.
- The cosine distance as a
Float(Float32 or Float64 depending on the input types).
Cosine distance between two embeddings
L2Distance / L2Norm
L2Distance returns the Euclidean distance between two vectors, the square root of the sum of the squared differences of their elements. L2Norm returns the Euclidean length of a single vector, the square root of the sum of the squares of its elements.
Syntax
vector,vector1,vector2— arrays or tuples of numeric values. The two arguments toL2Distancemust have the same length.
L2Distance: the Euclidean distance between the two vectors as aFloat.L2Norm: the Euclidean length of the vector as aFloat.
Euclidean distance and L2 norm
L2SquaredDistance / L2SquaredNorm
L2SquaredDistance returns the sum of the squared differences between corresponding elements of two vectors (the squared Euclidean distance). L2SquaredNorm returns the sum of the squares of a single vector’s elements (the squared L2 norm). Skipping the square root makes these cheaper than their L2 counterparts and is sufficient when you only need to rank or compare distances.
Syntax
vector,vector1,vector2— arrays or tuples of numeric values. The two arguments toL2SquaredDistancemust have the same length.
L2SquaredDistance: the sum of squared element-wise differences.L2SquaredNorm: the sum of the squared element values.
Float value depending on the input types.
Example
Squared Euclidean distance and squared L2 norm
dotProduct
Computes the scalar (dot) product of two vectors: the sum of the products of their corresponding elements. Syntaxvector1— first vector, an array or tuple of numeric values.vector2— second vector, an array or tuple of the same length.
- The scalar product as a single numeric value whose type follows the input element types.
Dot product of two vectors
L1Distance / L1Norm
L1Distance returns the Manhattan (taxicab) distance between two vectors, the sum of the absolute differences of their elements. L1Norm returns the L1 length of a single vector, the sum of the absolute values of its elements.
Syntax
vector,vector1,vector2— arrays or tuples of numeric values. The two arguments toL1Distancemust have the same length.
L1Distance: the sum of absolute element-wise differences.L1Norm: the sum of the absolute element values.
Float value depending on the input types.
Example
Manhattan distance and L1 norm
LinfDistance / LinfNorm
LinfDistance returns the Chebyshev (L-infinity) distance between two vectors, the maximum absolute difference across their elements. LinfNorm returns the L-infinity length of a single vector, the maximum absolute value among its elements.
Syntax
vector,vector1,vector2— arrays or tuples of numeric values. The two arguments toLinfDistancemust have the same length.
LinfDistance: the largest absolute element-wise difference, as aFloat.LinfNorm: the largest absolute element value, as aFloat.
Chebyshev distance and L-infinity norm