Vector Distance Functions and Operators
A vector distance function takes in two vector operands and a distance metric to compute a mathematical distance between those two vectors, based on the distance metric provided. You can optionally use shorthand distance functions and operators instead of their corresponding distance functions.
Distances determine similarity or dissimilarity between vectors.
-
Measuring distances in a vector space is at the heart of identifying the most relevant results for a given query vector. That process is very different from the well-known keyword filtering in the relational database world.
-
VECTOR_DISTANCEis the main function that you can use to calculate the distance between two vectors. -
L1_DISTANCEis a shorthand version of theVECTOR_DISTANCEfunction that calculates the Manhattan distance between two vectors. It takes two vectors as input and returns the distance between them as aBINARY_DOUBLE. -
L2_DISTANCEis a shorthand version of theVECTOR_DISTANCEfunction that calculates the Euclidean distance between two vectors. It takes two vectors as input and returns the distance between them as aBINARY_DOUBLE. -
COSINE_DISTANCEis a shorthand version of theVECTOR_DISTANCEfunction that calculates the cosine distance between two vectors. It takes two vectors as input and returns the distance between them as aBINARY_DOUBLE. -
INNER_PRODUCTcalculates the inner product of two vectors. It takes two vectors as input and returns the inner product as aBINARY_DOUBLE.INNER_PRODUCT(<expr1>, <expr2>)is equivalent to-1 * VECTOR_DISTANCE(<expr1>, <expr2>, DOT). -
HAMMING_DISTANCEis a shorthand version of theVECTOR_DISTANCEfunction that calculates the hamming distance between two vectors. It takes two vectors as input and returns the distance between them as aBINARY_DOUBLE. -
JACCARD_DISTANCEis a shorthand version of theVECTOR_DISTANCEfunction that calculates the jaccard distance between two vectors. It takes twoBINARYvectors as input and returns the distance between them as aBINARY_DOUBLE.