向量函数
清单
功能类型 |
说明 |
返回值类型 |
|---|---|---|
txt2vec( host,test) |
从文本中提取向量,以 1024 维测量向量 |
Float |
Img2vec(host,img_url,local_path) |
从图像中提取向量,测量向量为 512 维 |
Float |
distance(vector_column, txt2vec( host,test)) |
计算两个向量之间的距离,距离类型是向量表中指定向量列的距离类型。 |
Float |
ipDistance(vector_column, array[1,2,3…]) |
内积距离函数是一种计算向量间相似度的方法。距离越大,表示向量之间的相似度越低,距离越小,表示向量之间的相似度越高。 |
Float |
l2distance(vector_column, array[1,2,3…]) |
欧氏距离函数,用于测量直线上两点之间的距离,更常用于连续值向量。距离越短,相似度越高。 |
Float |
cosineDistance(vector_column, array[1,2,3…]) |
余弦距离函数是衡量向量相似度的常用指标,其值越接近 1,向量的相似度越高,而其值越接近 0,向量的相似度越低。 |
Float |
规格
1. txt2vec(host,text)
从文本中提取向量,测试向量的维数为 1024。
语法
txt2vec('host','text')
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
host |
字符串 |
模型服务的具体 IP:端口需要包含'' |
Y |
text |
字符串 |
表示需要提取向量的文本,其中需要包含 '' |
Y |
返回类型
Float
实例
0: jdbc:dingo::///> select id,age, gender,hobby, color_index$distance from vector(VECTOR_TABLE_L2, color, txt2vec('ip:port','red'), 10) where age>1;
2. img2vec(host,img_url,local_path)
从图像中提取向量,测试向量的维数为 512。
语法
img2vec('host','img_url','local_path')
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
host |
字符串 |
模型服务的具体 IP:端口需要包含'' |
Y |
img_url |
字符串 |
代表图像的网络地址或本地地址(服务器)需要包含'' |
Y |
local_path |
布尔型 |
表示是否获取本地图像资源,包括'';默认值:false |
N |
返回类型
Float
实例
0: jdbc:dingo::///> select id,age, gender,hobby, color_index$distance from vector(VECTOR_TABLE_IMG_L2, color, img2vec('ip:port','img_url', false), 10) where age>1;
3. distance(vector_column,txt2vec(host,text))
使用为向量表中的向量列指定的距离度量,计算两个向量之间的距离。两个向量的尺寸必须相同。
语法
distance('vector_column',txt2vec(host,text))
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
vector_column |
字符串 |
用于计算距离的向量列的列名,不含引号。 |
Y |
txt2vec(host,text) |
用于计算距离的向量函数。 |
Y |
返回类型
Float
实例
0: jdbc:dingo::///> select age from VECTOR_TABLE_L2 where distance(color,txt2vec('ip:port','red')) < 0.1;
4. ipDistance(vector_colume, array[1,2,3…])
内积距离计算函数,是一种计算向量间相似度的方法。距离越大,表示向量之间的相似度越低,距离越小,表示向量之间的相似度越高。
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
vector_column |
字符串 |
表示计算距离的列名,不含引号。 |
Y |
array[1,2…] |
Float |
表示要计算的距离值 |
Y |
语法 1
<*>
实例 1
select feature <*> array[1.1,1.2,1.3] from table;
语法 2
ipdistance(vector_colume, array[])
实例 2
select ipDistance(feature,array[1,2......]) from table;
5. l2Distance(vector_colume, array[1,2,3…])
测量两点之间的 L2 距离。也就是说,矢量所代表的点之间的直线长度;距离越短,说明源对象在概念上越相似。
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
vector_column |
字符串 |
表示计算距离的列名,不含引号。 |
Y |
array[1,2…] |
Float |
表示要计算的距离值 |
Y |
语法 1
<=>
实例 1
select feature <=> array[1.1,1.2,1.3] from table;
语法 2
l2distance(vector_colume, array[])
实例 2
select l2Distance(feature,array[1,2......]) from table;
6. cosDistance(vector_colume, array[1,2,3…])
测量两个向量间夹角的余弦值,即点积除以长度。
参数
参数 |
类型 |
说明 |
必需 |
|---|---|---|---|
vector_column |
字符串 |
用于计算距离的向量列的列名,不含引号。 |
Y |
txt2vec(host,text) |
用于计算距离的向量函数。 |
Y |
语法 1
<->
实例 1
select feature <-> array[1.1,1.2,1.3] from table;
语法 2
cosdistance(vector_colume,array[])
实例 2
select cosDistance(feature,array[1,2......]) from table;