INNER_PRODUCT_DISTANCE

更新时间:
复制 MD 格式

The INNER_PRODUCT_DISTANCE function calculates the inner product distance between two vectors.

Note

The inner product, also known as the dot product or scalar product, is the result of multiplying two vectors. The result indicates the degree of alignment between the two vectors. Similar vectors have a larger inner product than dissimilar vectors.

Syntax

FLOAT INNER_PRODUCT_DISTANCE(<vector>, <vector>)

Parameters

vector: Required. A vector of the VECTOR data type.

Return value

Returns a FLOAT value representing the inner product distance between the two input vectors.

Optimizations in vector functions may reduce floating-point precision. The result of this function can have an error of up to 1e-4.

Examples

-- Enable the VECTOR data type.
set odps.sql.type.vector.enable=true;
set odps.sql.type.system.odps2=true;

-- Prepare the data.
CREATE TABLE vectors (a VECTOR(FLOAT, 3), b VECTOR(FLOAT, 3));
INSERT INTO vectors SELECT CAST(ARRAY(1.1,2.2,3.0) AS VECTOR(FLOAT,3)), CAST(ARRAY(1.0,1.0,1.0) AS VECTOR(FLOAT,3));
INSERT INTO vectors SELECT CAST(ARRAY(1.0,2.2,3.0) AS VECTOR(FLOAT,3)), CAST(ARRAY(4.0,6.0,8.0) AS VECTOR(FLOAT,3));

-- Calculate the inner product distance between a and b.
SELECT INNER_PRODUCT_DISTANCE(a, b) FROM vectors;

-- Result
+------------+
| _c0        |
+------------+
| -40.20000076293945 |
| -5.300000190734863 |
+------------+