URL
/vector-service/multi-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文法
SearchRequest:
參數名稱
描述
預設值
類型
是否必須
tableName
查詢的表名
無
string
是
indexName
查詢的索引名必須在SearchRequest中指定或者在每個Query中指定
無
string
否
queries
多向量列表
無
list[Query]
是
mode
配置多路結果中相同pk doc如何計算分數,mode可以配置:sum, max, min。
sum
string
否
topK
最終返回的結果個數
100
int
否
includeVector
是否返迴文檔中的向量資訊
false
bool
否
outputFields
需要傳回值的欄位列表
[]
list[string]
否
order
排序次序, ASC:升序 DESC: 降序
ASC
string
否
filter
過濾運算式
""
string
否
sort
排序運算式
""
string
否
Query:
參數
描述
預設值
類型
是否必須
indexName
查詢的索引名必須在SearchRequest中指定或者在每個Query中指定
無
string
否
vector
查詢的向量資料,多個向量可以平鋪開
無
list[float]
否
vectorCount
vector欄位中向量的個數
1
int
否
topK
返回個數
100
int
否
namespace
查詢向量的空間
""
string
否
sparseData
查詢的稀疏向量
預設無sparse部分
SparseData
否
weight
Query的權重
1.0
float
否
searchParams
向量查詢參數
""
string
否
scoreThreshold
分數過濾, 使用歐式距離時,只返回小於scoreThreshold的結果。使用內積時,只返回大於scoreThreshold的結果
無
float
否
SparseData:
參數名稱
描述
預設值
類型
是否必須
count
每個稀疏向量中包含的元素個數
只有一個稀疏向量時預設為indices長度
list[int]
否
indices
元素下標(需要從小到大排序)
無
list[int]
是
values
元素值(與下標一一對應)
無
list[float]
是
返回參數
返回結果:
欄位名稱
描述
類型
result
結果清單
list[Item]
totalCount
result中的個數
int
totalTime
引擎處理耗時,單位ms
float
errorCode
錯誤碼,僅當發生錯誤時返回
int
errorMsg
錯誤資訊,僅當發生錯誤時返回
string
item定義:
欄位名稱
描述
類型
score
距離分
float
fields
欄位名稱和對應的值
map<string, FieldType>
vector
向量值
list[float]
id
主索引值,類型為所定義的欄位類型
FieldType
namespace
向量所屬的空間,如果設定了空間會返回該欄位
string
樣本
多命名空間
Body:
{
"tableName": "gist",
"indexName": "vec_index",
"queries": [
{
"vector": [
0.1,
0.2,
0.3
],
"namespace": "space_a"
},
{
"vector": [
0.4,
0.5,
0.6
],
"namespace": "space_b"
}
],
"mode": "min",
"topK": 3,
"includeVector": true
}Response:
{
"result": [
{
"id": 1,
"score": 1.0508723258972169,
"vector": [
0.1,
0.2,
0.3
],
"namespace": "space_a"
},
{
"id": 2,
"score": 1.0329746007919312,
"vector": [
0.2,
0.2,
0.3
],
"namespace": "space_b"
},
{
"id": 3,
"score": 0.980593204498291,
"vector": [
0.3,
0.2,
0.3
],
"namespace": "space_a"
}
],
"totalCount": 3,
"totalTime": 2.943
}多索引混合查詢
Body:
{
"tableName": "gist",
"queries": [
{
"indexName": "content_vec",
"vector": [
0.1,
0.2,
0.3
],
"sparseData": {
"count": [
3
],
"indices": [
102,
405,
503
],
"values": [
0.32,
0.94,
0.25
]
},
"weight": 0.7,
"namespace": "space_a"
},
{
"indexName": "title_vec",
"vector": [
0.4,
0.5,
0.6
],
"sparseData": {
"count": [
2
],
"indices": [
203,
709
],
"values": [
0.98,
0.08
]
},
"weight": 0.3,
"namespace": "space_b"
}
],
"topK": 3,
"includeVector": true
}