Vector Functions

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 int or float.
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:

FunctionDescription
COSINE_SIM(array, array)Computes the cosine similarity of two vectors. Cosine similarity represents the dot product of two vectors divided by their magnitude
DOT_PRODUCT(array, array)Computes the dot product of two vectors.
EUCLIDEAN_DIST(array, array)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.
VECTOR_ADD(array, addend)Adds a scalar of type int or float to a vector. Alternatively, adds two vectors.
VECTOR_DIVIDE(array, divisor)Divides a vector by a scalar of type int or 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'.
VECTOR_MULTIPLY(array, multiplier)Multiplies a vector by a scalar of type int or float or computes the element-wise multiplication of two vectors as the Hadamard product.
VECTOR_SUBTRACT(array, subtrahend)Subtracts a scalar of type int or float from a vector. Alternatively, subtracts a vector from another vector.
RANK_FUSION (score [DESC|ASC] [weight], score [DESC|ASC] [weight])[OPTION(k=60)]Combines the rankings from two different search modalities (e.g. vector search and text search), using the proven Reciprocal Rank Fusion (RRF) scoring method.
APPROX_DOT_PRODUCT(array, array)Approximate version of DOT_PRODUCT. If the query orders by the result of this function in descending order then an approximate inner_product similarity index will be used if available. Otherwise behavior is the same as DOT_PRODUCT.
APPROX_EUCLIDEAN_DIST(array, array)Approximate version of EUCLIDEAN_DIST. If the query orders by the result of this function in ascending order then an approximate l2 similarity index will be used if available. Otherwise behavior is the same as EUCLIDEAN_DIST.