URL
/vector-service/batch-query
以上 URL 省略了请求Header参数及编码等因素。
以上 URL 中省略了访问应用的 host 地址。
以上URL 中拼接的所有查询参数,请查看下方“查询参数”的参数定义、使用方式及样例。
请求协议
HTTP
请求方式
POST
支持格式
JSON
签名机制
可用以下方法计算签名(authorization)
参数 | 类型 | 描述 |
accessUserName | string | 用户名,可在实例详情页>网络信息查看 |
accessPassWord | string | 密码,可在实例详情页>网络信息修改 |
import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;
public class GenerateAuthorization {
public static void main(String[] args) throws Exception {
String accessUserName = "username";
String accessPassWord = "password";
String realmStr = "" + accessUserName + ":" + accessPassWord + "";
String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
System.out.println(authorization);
}
}
authorization正确返回格式:
cm9vdDp******mdhbA==
使用HTTP请求设置authorization参数需加上Basic前缀
示例:(在header中加入)
authorization: Basic cm9vdDp******mdhbA==
请求body
参数名称 | 描述 | 默认值 | 类型 | 是否必须 |
queries | 批量查询列表 | [] | List<Query> | 是 |
timeout | 超时时间 | -1: 不超时 | Integer | 否 |
Query:
参数名称 | 描述 | 默认值 | 类型 | 是否必须 |
tableName | 查询的表名。 | 无 | string | 是 |
vector | 查询的向量数据。 | 无 | list[float] | 是 |
vectorCount | vector字段中包含的向量个数。 | 1 | int | 否 |
namespace | 查询向量的空间。 | "" | string | 否 |
topK | 返回个数。 | 100 | int | 否 |
indexName | 查询的索引名。 | "" | string | 否 |
sparseData | 查询的稀疏向量。 | 默认无sparse部分 | SparseData | 否 |
includeVector | 是否返回文档中的向量信息。 | false | bool | 否 |
outputFields | 需要返回值的字段列表。 | [] | list[string] | 否 |
order | 排序顺序。
| ASC | string | 否 |
searchParams | 查询参数。 | "" | string | 否 |
filter | 过滤表达式。 | "" | string | 否 |
scoreThreshold | 分数过滤, 使用欧式距离时,只返回小于scoreThreshold的结果。使用内积距离时,只返回大于scoreThreshold的结果。 | 默认不过滤 | float | 否 |
sort | 排序表达式。 | "" | string | 否 |
返回参数
字段 | 说明 | 类型 |
result | 结果列表,每个query的结果顺序与查询中的一致 | List[QueryResult] |
totalTime | 查询耗时,单位ms | Integer |
errorCode | 错误码,有错误时才有该字段 | Integer |
errorMsg | 错误信息,有错误时才有该字段 | String |
QueryResult:
字段
说明
类型
queryId
标明结果属于query列表中的哪个query
Integer
totalCount
结果个数
Integer
data
结果doc列表
List[Item]
Item:
字段名称
描述
类型
id
主键值,类型为所定义的字段类型
FieldType
score
距离分
Float
fields
字段名称和对应的值
Map<String, FieldType>
vector
向量值
List[Float]
namespace
向量的名称空间,如果设置了namespace会返回该字段
String
示例
请求示例:
{
"queries":
[
{
"indexName": "vector",
"outputFields":
[
"id",
"name"
],
"tableName": "test",
"vector":
[
0.363397,
0.843076,
0.47759,
0.48623
]
},
{
"indexName": "vector",
"outputFields":
[
"id",
"title"
],
"tableName": "test1",
"vector":
[
0.822608,
0.972663,
0.014438,
0.410083
]
}
]
}
返回示例:
{
"result":
[
{
"queryId": 0,
"totalCount": 1,
"data":
[
{
"id": 1,
"score": 0.521898,
"__source__": 0,
"fields":
{
"name": "测试1"
}
}
]
},
{
"queryId": 1,
"totalCount": 1,
"data":
[
{
"id": 1,
"score": 1.200817,
"__source__": 1,
"fields":
{
"title": "标题1"
}
}
]
}
],
"totalTime": 4.419
}