Vector Distance Operand to the VECTOR_DISTANCE Function

VECTOR_DISTANCE() is the main function that allows you to calculate distances between two vectors.

The VECTOR_DISTANCE() function takes two vectors as parameters. You can optionally specify a distance metric to calculate the distance desirably. If you do not specify a distance metric, then the default distance metric is the COSINE metric.

You can optionally use the following shorthand functions too : L1_DISTANCE, L2_DISTANCE, COSINE_DISTANCE and INNER_PRODUCT. These functions take two vectors as input and return the distance between them.

All of these functions return the vectors' distance as a BINARY_DOUBLE.

When using the VECTOR_DISTANCE() function to perform a similarity search, note the following caveats:

  • If a similarity search query does not specify a distance metric in the VECTOR_DISTANCE() function, then the default COSINE metric will be used for both exact and approximate (index-based) searches.
  • If a similarity search query does specify a distance metric in the VECTOR_DISTANCE() function, then an exact search with that distance metric is used if it conflicts with the distance metric specified in a vector index. If the two distance metrics are the same, then that will be used for both exact and approximate (index-based) searches.

Syntax

For detailed information on the vector functions, see Vector Functions in Oracle SQL Language Reference.