Multi-query

更新时间:
复制 MD 格式

Runs multiple vector queries in a single request and merges the results into a unified ranked list. Supports searching across multiple namespaces, multiple indexes, and combinations of dense and sparse vectors.

Request

Method: POST

URL: /vector-service/multi-query

Format: JSON

Authentication

The request signature uses HTTP Basic Auth. Encode username:password as Base64 and pass the result in the authorization header.

Credentials

ParameterTypeDescription
accessUserNamestringThe username. View it in the API Endpoint section of the Instance Details page.
accessPassWordstringThe password. Modify it in the API Endpoint section of the Instance Details page.

Generate the authorization value

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);
    }
}

Set the header with the Basic prefix:

authorization: Basic cm9vdDp******mdhbA==

Request parameters

SearchRequest

ParameterTypeRequiredDefaultDescription
tableNamestringYesThe name of the table to query.
indexNamestringNoThe index to use for all queries. Specify here or in each individual Query object.
querieslist[Query]YesThe list of vector queries to run.
modestringNosumThe score aggregation method when multiple queries match the same primary key. Valid values: sum, max, min.
topKintNo100The number of results to return.
includeVectorboolNofalseSpecifies whether to include vector values in the response.
outputFieldslist[string]No[]The fields to include in each result. Returns all fields if empty.
orderstringNoASCThe sort order of results. Valid values: ASC (ascending), DESC (descending).
filterstringNo""A filter expression to apply to results.
sortstringNo""A sort expression to apply to results.

Query

ParameterTypeRequiredDefaultDescription
indexNamestringNoThe index to use for this query. Overrides the indexName in SearchRequest. Either this field or SearchRequest.indexName must be set.
vectorlist[float]NoThe dense vector to search. To include multiple vectors, tile them sequentially in this list and set vectorCount accordingly.
vectorCountintNo1The number of vectors in the vector field.
topKintNo100The number of results to return for this query.
namespacestringNo""The namespace of the vector data to search.
sparseDataSparseDataNoThe sparse vector to search. Used for hybrid dense-sparse queries.
weightfloatNo1.0The weight of this query when merging results.
searchParamsstringNo""Additional query parameters.
scoreThresholdfloatNoFilters results by score. For squared Euclidean distance, only documents with a distance smaller than this value are returned. For inner product, only documents with an inner product greater than this value are returned.

SparseData

ParameterTypeRequiredDefaultDescription
indiceslist[int]YesThe indexes of the non-zero elements, in ascending order.
valueslist[float]YesThe values of the non-zero elements, in the same order as indices.
countlist[int]NoNumber of indexes (single sparse vector)The number of elements in each sparse vector. Required when passing multiple sparse vectors.

Response parameters

Top-level response

ParameterTypeDescription
resultlist[Item]The matched documents.
totalCountintThe number of results returned.
totalTimefloatThe total query time, in milliseconds.
errorCodeintThe error code. Returned only when an error occurs.
errorMsgstringThe error message. Returned only when an error occurs.

Item

ParameterTypeDescription
idTypeThe primary key of the document.
scorefloatThe distance score for this result.
fieldsmap<string, FieldType>The field names and their values.
vectorlist[float]The vector value. Returned when includeVector is true.
namespacestringThe namespace of the vector. Returned when a namespace is configured.

Examples

Query across multiple namespaces

Search two namespaces simultaneously and return the top 3 results using the minimum score across matches.

Request 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
}

Hybrid query across multiple indexes

Search two indexes simultaneously using dense and sparse vectors with different weights. Each query targets a separate index and namespace.

Request 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
}