inner_product()¶
INNER PRODUCT 函数返回两个向量点积的相反数(-dot product),作为向量距离使用;值越小表示向量越相似。
函数说明¶
INNER PRODUCT 函数返回两个向量点积的相反数(-dot product),作为向量距离使用;值越小表示向量越相似。若需要数学意义上的点积,请使用 -inner_product(vector1, vector2)。

函数语法¶
> SELECT inner_product(vector1, vector2) AS result FROM table_name;
示例¶
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)
距离语义¶
INNER_PRODUCT 返回 -dot product,以便在向量索引中使用统一的距离排序约定。使用 ORDER BY inner_product(...) ASC 时,值越小表示向量越相似;如果使用 DESC,排序方向与相似度相反。
限制¶
两个参数向量必须具有相同的维度。