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.
- Vector Distance Metrics
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_DISTANCE
VECTOR_DISTANCEis the main function that you can use to calculate the distance between two vectors. - L1_DISTANCE
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_DISTANCE
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_DISTANCE
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_PRODUCT
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_DISTANCE
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_DISTANCE
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.
Related Topics
Parent topic: Use SQL Functions for Vector Operations