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

向量数据库VikingDB

复制全文
下载 pdf
数据(data)
FetchIndexData
复制全文
下载 pdf
FetchIndexData

概述

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

说明

Collection 数据写入/删除后,Index 数据更新时间最长滞后 20s,不能立即在 Index 查询到。

请求参数

字段名

类型

是否必传

说明

CollectionName/CollectionAlias

string

数据集名称或数据集别名,二选一

PrimaryKeys

Array<string | number>

主键值,类型对齐定义的主键字段

Partition

string | number

子索引,类型和子索引字段对齐

OutputFields

string[]

输出的字段

响应参数
declare class FetchIndexDataResponse<
  Data extends Record<string, any>,
  PrimaryKey extends GetPrimaryKeys<Data>
> {
  readonly Data: FetchDataInfo<Data, PrimaryKey>[];
  readonly OriginalRequest: string;
  readonly LogId: string;
  constructor(
    Data: FetchDataInfo<Data, PrimaryKey>[],
    OriginalRequest: string,
    LogId: string
  );
}
type GetPrimaryKeys<T extends Record<string, any>> = {
  [K in keyof T]: IsPrimaryKey<T, K> extends true ? K : never;
}[keyof T];

type FetchDataInfo<
  Data extends Record<string, any>,
  PrimaryKey extends GetPrimaryKeys<Data>
> = Data | { [Key in PrimaryKey]: ScalarFieldType2JsType[Data[PrimaryKey]] };
type IsNever<T> = [T] extends [never] ? true : false;

type IsUnion<T, B = T> = IsNever<T> extends true
  ? false
  : T extends B
  ? [B] extends [T]
    ? false
    : true
  : never;
  
enum FieldType {
  Int64 = "int64",
  Float32 = "float32",
  String = "string",
  Boolean = "bool",
  ListString = "list<string>",
  ListInt64 = "list<int64>",
  /** 稠密向量 */
  DenseVector = "vector",
  /** 稀疏向量 */
  SparseVector = "sparse_vector",
  Text = "text",
}  
  
interface ScalarFieldType2JsType {
  [FieldType.Int64]: number;
  [FieldType.Float32]: number;
  [FieldType.String]: string;
  [FieldType.Boolean]: boolean;
  [FieldType.ListString]: string[];
  [FieldType.ListInt64]: Array<number>;
}
  
type IsPrimaryKey<
  Data extends Record<string, any>,
  PrimaryKey extends keyof Data
> = IsUnion<PrimaryKey> extends true
  ? false
  : Data[PrimaryKey] extends ScalarFieldType2JsType[PrimaryKeyFieldType]
  ? true
  : false;

参考示例
import { vikingdb } from '@volcengine/openapi'

declare const service: vikingdb.VikingdbService // 替换为你初始化好的实例

interface Data {
  Id: number,
  Name: string
}

const response = await service.data.FetchIndexData<Data, 'Id'>({
  CollectionName: 'test_collection_1',
  IndexName: 'test_index_1',
  PrimaryKeys: [1, 2],
  Partition: 3, // optional
  OutputFields: ['Id', 'Name'], // optional
})

console.log(response.Data) // 查询的索引数据 Data
最近更新时间:2025.09.30 16:06:34
这个页面对您有帮助吗?
有用
有用
无用
无用