You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
数据(Data)
fetchDataInIndex
复制全文
下载 pdf
fetchDataInIndex

概述

fetchData 用于 Index 数据查询。根据主键 ID,在指定的 Index 查询单条或多条数据,单次最多可查询 100 条数据。

说明

Collection 数据写入/删除后,Index 数据更新时间有同步延迟,一般在10s左右,不能立即在 Index 查询到。

方法定义
public DataApiResponse<FetchDataInIndexResult> fetchDataInIndex(FetchDataInIndexRequest request)
            throws ApiClientException, VectorApiException

请求参数

参数名

类型

必选

备注

resourceId

String

2选1

资源 ID

collectionName

String

Collection 名称

indexName

String

索引名称

ids

List[Object]

  • 点查数据的主键列表。最多 100 条

outputFields

List[String]

要返回的标量字段列表。

  1. 用户不传 outputFields 时,返回所有标量字段
  2. 用户传一个空列表不返回标量字段
  3. outputFields 格式错误或过滤字段不是 collection 里的字段时,接口返回错误

返回参数

名称

类型

说明

fetch

List[FetchInCollectionItem]

查询到的数据列表,FetchInCollectionItem 结构见下。

idsNotExist

List[Object]

不存在的主键列表

  • List[FetchInCollectionItem]

参数名

类型

备注

id

Object

主键值

fields

Map[String, Object]

key为字段名,value为字段值

denseVector

List[Float]

稠密向量

denseDim

Integer

稠密向量维度

示例

请求参数

package org.example.newsubproduct.data.data;

import com.volcengine.vikingdb.runtime.core.ClientConfig;
import com.volcengine.vikingdb.runtime.core.auth.AuthWithAkSk;
import com.volcengine.vikingdb.runtime.enums.Scheme;
import com.volcengine.vikingdb.runtime.exception.VectorApiException;
import com.volcengine.vikingdb.runtime.vector.model.request.*;
import com.volcengine.vikingdb.runtime.vector.model.response.*;
import com.volcengine.vikingdb.runtime.vector.service.VectorService;

import java.util.Arrays;

public class FetchDataInIndex {

    public static void main(String[] args) {
        VectorService vectorService = null;
        try {
            vectorService = new VectorService(
                    Scheme.HTTPS,
                    "api-vikingdb.vikingdb.cn-beijing.volces.com", // 填写向量库数据面v2的域名  https://www.volcengine.com/docs/84313/1792715
                    "cn-beijing",
                    new AuthWithAkSk(System.getenv("AK"), System.getenv("SK")),
                    ClientConfig.builder().build()
            );
        } catch (Exception e) {
            System.err.println("Client initialization failed: " + e.getMessage());
            e.printStackTrace();
            return;
        }

        FetchDataInIndexRequest request = FetchDataInIndexRequest.builder()
                .collectionName("your_collection_name") // 替换为您的集合名称
                .indexName("your_index_name") // 替换为您的索引名称
                .ids(Arrays.asList(1, 2, 3))
                .build();

        try {
            DataApiResponse<FetchDataInIndexResult> response = vectorService.fetchDataInIndex(request);
            System.out.println("request success:");
            System.out.println(response);
        } catch (VectorApiException vectorApiException) {
            System.err.println("request vectorApiException:");
            System.out.println("apiName: " + vectorApiException.getApiName());
            System.out.println("httpStatusCode: " + vectorApiException.getHttpStatusCode());
            System.out.println("code: " + vectorApiException.getCode());
            System.out.println("message: " + vectorApiException.getMessage());
            System.out.println("requestId: " + vectorApiException.getRequestId());
            System.out.println("responseContext: " + vectorApiException.getResponseContext().getBody());
        } catch (Exception e) {
            System.err.println("request exception, message : " + e.getMessage());
            e.printStackTrace();
        }
    }
}

最近更新时间:2026.04.14 15:03:25
这个页面对您有帮助吗?
有用
有用
无用
无用