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

向量数据库VikingDB

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

概述

fetch_data 用于 Index 数据查询。根据主键 id,在指定的 Index 查询单条或多条数据,单次最多可查询100条数据。
异步调用使用async_fetch_data接口,参数不变。
Collection 数据写入/删除后,Index 数据更新时间最长滞后 20s,不能立即在 Index 查询到。

请求参数

参数

类型

是否必选

默认值

参数说明

id

string、int64、
list、
list

是

主键或主键构成的列表。

output_fields

list

否

过滤标量字段,指定要返回的标量字段列表。

  • output_fields 不传时,返回所有的标量字段。
  • output_fields 为空列表时,不返回 fields 字段。
  • output_fields 格式错误或者过滤字段不是 collection 里的字段时, 接口返回错误。

partition

string/int

否

"default"

子索引名称,类型与 partition_by 的 field_type 一致,字段值对应 partition_by 的 field_value。

  • field_type 为 int64,list 时,partition 输入类型为 int64。
  • field_type 为 string,list 时,partition 输入类型为 string,格式要求 "^[a-zA-Z0-9._]+$"。

完整示例

运行示例前,请完成以下准备:

  • 安装 VikingDB Python SDK,将完整代码保存为 example.py 后执行 python3 example.py。
  • 将 <YOUR_HOST>、<YOUR_REGION> 和 <YOUR_SCHEME> 替换为地域和访问域名中与实例一致的服务地址、地域和协议。
  • 将 <YOUR_AK>、<YOUR_SK> 替换为火山引擎控制台“密钥管理”中创建的 Access Key ID 和 Secret Access Key;请勿把真实凭证提交到代码仓库。
  • 将 Collection、Index、Task 等资源占位符替换为控制台中对应资源的名称或接口返回的 ID。若示例包含 TOS 路径,请从 TOS 控制台确认桶名和对象路径,并使用 tos://<YOUR_BUCKET_NAME>/<YOUR_OBJECT_KEY> 或文档要求的路径格式。

请求参数

# 获取指定数据集,程序初始化时调用即可,无需重复调用
from volcengine.viking_db.IndexClient import IndexClient

index_client = IndexClient("<YOUR_COLLECTION_NAME>", "<YOUR_INDEX_NAME>", "api-vikingdb.volces.com", "cn-beijing", "<YOUR_AK>", "<YOUR_SK>", "http")
res = index_client.fetch_data(["11", "33"], partition="1", output_fields=["doc_id", "like"])


# 异步调用
async def index_fetch_data():
    index_client = IndexClient("<YOUR_COLLECTION_NAME>", "<YOUR_INDEX_NAME>", "api-vikingdb.volces.com", "cn-beijing", "<YOUR_AK>", "<YOUR_SK>", "http")
    res = await index_client.async_fetch_data(["111", "222", "333", "444"])
asyncio.run(index_fetch_data())

返回结果

Python 调用执行上面的任务,返回 Data 实例或 Data 实例列表。Data 实例包含的属性如下表所示。

属性

说明

id

主键 id。

fields

请求返回中的 fields 字段,是具体的数据,字典类型。

最近更新时间:2026.09.08 15:30:02
这个页面对您有帮助吗?
有用
有用
无用
无用