This page covers vector operations and distance functions available in Rockset. Rockset internally handles and manipulates vectors as homogeneous arrays.
Note: Arrays input to vector functions must have the same lengths and the elements must be of the types
Otherwise the functions will throw an error. Various error messages are outlined in the following sections. Operations between an array of
ints and an array of
floats will return an array of
floats. Learn more about type functions.
List of functions defined in this section:
|Computes the cosine similarity of two vectors. Cosine similarity represents the dot product of two vectors divided by their magnitude
|Computes the dot product of two vectors.
|Computes the Euclidean distance of two vectors (which is also referred to as the L2 norm). Euclidean distance represents the square root of the sum of squared differences between corresponding elements of two vectors.
|Adds a scalar of type
float to a vector. Alternatively, adds two vectors.
|Divides a vector by a scalar of type
float or computes the element-wise divison of two vectors. Throws an error when division by zero occurs.
VECTOR_ENFORCE(array, length, type)
|Returns the input vector if it fulfills the length and type requirements. Otherwise returns
null. Input the length argument as an
int and the type argument as the
string 'int' or 'float'.
|Multiplies a vector by a scalar of type
float or computes the element-wise multiplication of two vectors as the Hadamard product.
|Subtracts a scalar of type
float from a vector. Alternatively, subtracts a vector from another vector.