Skip to content

inner_product()

Function Description

The INNER PRODUCT function is used to calculate the inner product/dot product between two vectors. It is the result of multiplication and then addition of the corresponding elements of the two vectors.

Function Syntax

> SELECT inner_product(vector1, vector2) AS result FROM table_name;

Example

drop table if exists vec_table;
create table vec_table(a int, b vecf32(3), c vecf64(3));
insert into vec_table values(1, "[1,2,3]", "[4,5,6]");
mysql> select * from vec_table;
+-------+--------------------------+
| a | b | c |
+-------+--------------------------+
| 1 | [1, 2, 3] | [4, 5, 6] |
+-------+--------------------------+
1 row in set (0.00 sec)

mysql> select inner_product(b,"[1,2,3]") from vec_table;
+--------------------------------+
| inner_product(b, [1,2,3]) |
+--------------------------------+
| 14 |
+--------------------------------+
1 row in set (0.00 sec)

limit

Two parameter vectors must have the same dimension.