文档

多query查询

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]

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

1

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"
        }
    ],
    "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
}

  • 本页导读 (0)
文档反馈