Snowflake provides native mathematical vector functions designed to measure distance, divergence, and similarity across dense vector embeddings generated by machine learning models. The Manhattan distance—also known in linear algebra and coordinate geometry as the L1 distance, rectilinear distance, or taxicab metric—calculates the sum of the absolute differences between the corresponding Cartesian coordinates of two vectors of equal dimensionality.
In Snowflake SQL, this operation is executed using VECTOR_L1_DISTANCE(vector1, vector2). The function accepts two VECTOR arguments with matching dimension and floating-point data types, outputting a real value representing the total grid-aligned distance separating the points.
The remaining options calculate different geometric metrics: VECTOR_L2_DISTANCE computes the Euclidean distance (the straight-line distance derived from the square root of the sum of squared differences); VECTOR_COSINE_SIMILARITY measures the cosine of the angle between two non-zero vectors, quantifying directional alignment irrespective of absolute vector magnitude; and VECTOR_INNER_PRODUCT calculates the dot product, reflecting both directional alignment and coordinate scale.
References & Study Guide Topics:
Snowflake Gen AI Functions: Vector Similarity and Distance Functions
Mathematical Foundations: Vector Data Types and Metric Selection (L1, L2, Cosine)
===============
Submit