You need to enable JavaScript to run this app.
导航

fetch_data(index)

最近更新时间2024.04.16 13:11:48

首次发布时间2023.11.03 15:00:09

功能介绍

/index/fetch_data 接口用于根据主键在指定的 Index 查询单条或多条数据,单次最多可查询100条数据。

说明

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

请求接口

说明

请求向量数据库 VikingDB 的 OpenAPI 接口时,需要构造签名进行鉴权,详细的 OpenAPI 签名调用方法请参见 API签名调用指南

URI

/api/index/fetch_data

统一资源标识符

请求方法

GET

客户端对向量数据库服务器请求的操作类型

请求头

Content-Type: application/json

请求消息类型

Authorization: HMAC-SHA256 ***

鉴权

请求参数

参数

类型

是否必选

参数说明

collection_name/collection_alias

string

指定查询数据的 Collection 名称/别名。

  • 只能使用英文字母、数字、下划线_,并以英文字母开头,不能为空。
  • 长度要求:[1, 128]。
  • Collection 名称/别名不能重复。

index_name

string

指定查询数据的 Index 名称。

  • 只能使用英文字母、数字、下划线_,并以英文字母开头,不能为空。
  • 长度要求:[1, 128]。
  • 索引名称不能重复。

primary_keys

int64、
array<int64>、
string、
array<string>

指定主键字段值,单次最多查询100条数据。primary_keys设置为不同类型时,数据查询逻辑如下:

  • int64类型、string类型:单条数据查询。
  • array<int64>、array<string>:多条数据查询,数据条数为 array 长度,最大100条。

partition

int64 / string

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

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

不设置默认为"default"。

output_fields

list<string>

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

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

响应消息

参数

参数说明

code

状态码

message

返回信息

request_id

标识每个请求的唯一标识符

data

返回查询的数据。

  • 如果查询单条数据,则类型是 map;如果批量查询多条数据,则类型是 array<map>;如果某条数据查不到,则只返回主键值和提示信息。
  • 每条数据作为一个 map,key 为字段名,value 为字段值。

状态码说明

状态码

http状态码

返回信息

状态码说明

0

200

success

在指定的 Index 查询数据成功。

1000008

400

index not exist

Index 不存在。

1000003

400

invalid request:%s

非法参数:

  • 缺失必选参数。

1000001

401

unauthorized

请求头中缺乏鉴权信息。

1000002

403

no permission

权限不足。

完整示例

请求消息

curl -i -X GET \
  -H 'Content-Type: application/json' \
  -H 'Authorization: HMAC-SHA256 ***' \
  http://***/api/index/fetch_data \
  -d '{
    "collection_name": "test_name",
    "primary_keys": [123,456],    
    "output_fields": ["time", "author", "vector_field"]
}'

响应消息

执行成功返回:

HTTP/1.1 200 OK
Content-Length: 43
Content-Type: application/json
 
{
    "code":0,
    "msg":"fetch data success",
    "request_id":"021695029537650fd001de666660000000000000000000230da93",
    "data": [
        {
            "id": "123",
            "vector": [0.10, 0.13.........0.52],
            "dimension": 768,
            "fields": [
                "time": 1690529701,
                "author": "zhangsan",
                "vector_field": [0.10, 0.13.........0.52]
            ]
        },
        {
            "id": "456",
            // 查不到,则没有vector, 并返回提示信息
            "message": "no data found"
        }  
    ]
}

执行失败返回:

HTTP/1.1 400 OK
Content-Length: 43
Content-Type: application/json
 
{"code": 1000008, "msg": "index not exist", "request_id":"021695029537650fd001de666660000000000000000000230da93"}