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

向量数据库VikingDB

复制全文
下载 pdf
数据(Data)
数据删除-DeleteData
复制全文
下载 pdf
数据删除-DeleteData

概述

接口用于在指定 Collection 中删除数据。删除数据后需要时间更新到 Index,即在一段时间内 Index 中仍可检索到数据。

接口升级说明
  • 对应的 V1 接口为:https://www.volcengine.com/docs/84313/1254539
  • 使用区别:

V2接口

V1接口

指定主键的参数名

ids

primary_keys

请求接口

请求向量数据库 VikingDB 的 OpenAPI 接口时,可以使用 API Key(推荐) 或者 AK、SK 构造签名进行鉴权。请参见数据面 API 调用流程,复制调用示例并填入必要信息。

URI

/api/vikingdb/data/delete

统一资源标识符

方法

POST

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

请求头

Content-Type: application/json

请求消息类型

Authorization: ***

鉴权

请求体参数

参数名

类型

必选

备注

resource_id

string

2选1

资源 ID

collection_name

string

Collection 名称

ids

list<int64>list<string>

2选1

删除数据的主键列表(主键为 int64 或 string)。最多 100 条。
注意:

  • 若请求参数非法(4xx 类型),则会全部失败。

del_all

bool

为 true 时,删除所有数据;默认为 false。
此接口删除所有数据后,并不能立刻同步到索引,因此在一段时间内(约 5 分钟),索引内仍可检索到数据。

响应体参数

参考数据面API调用流程

请求响应示例
  • 请求参数
req_path = "/api/vikingdb/data/delete"
req_body = {
    "collection_name": "test_coll",
    "ids": [
        "uid_001",
        "uid_002",
        "uid_005"
    ]
}
  • 响应参数
{
    "code": "Success",
    "message": "The API call was executed successfully.",
    "request_id": "02175438839168500000000000000000000ffff0a003ee4fc3499",
    "result": null
}

请求模板
"""
pip3 install volcengine
"""

from volcengine.base.Request import Request
import requests, json


class ClientForDataApi:
    def __init__(self, api_key=None, host=None):
        """
        初始化ClientForDataApi类
        :param api_key: VikingDB的API Key
        :param host: VikingDB的API Host
        """
        if not api_key or not host:
            raise ValueError("api_key and host are required")
        self.api_key = api_key
        self.host = host

    def prepare_request(self, method, path, params=None, data=None):
        r = Request()
        r.set_shema("https")
        r.set_method(method)
        r.set_connection_timeout(10)
        r.set_socket_timeout(10)
        mheaders = {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Host": self.host,
            "Authorization": f"Bearer {self.api_key}",
        }
        r.set_headers(mheaders)
        if params:
            r.set_query(params)
        r.set_host(self.host)
        r.set_path(path)
        if data is not None:
            r.set_body(json.dumps(data))
        return r

    def do_req(self, req_method, req_path, req_params, req_body):
        req = self.prepare_request(
            method=req_method, path=req_path, params=req_params, data=req_body
        )
        return requests.request(
            method=req.method,
            url="https://{}{}".format(self.host, req.path),
            headers=req.headers,
            data=req.body,
            timeout=10000,
        )


if __name__ == "__main__":
    import os
    client = ClientForDataApi(
        api_key=os.environ.get("VIKINGDB_API_KEY", "***"), # 从环境变量中获取API Key,若未设置则使用默认值
        host="api-vikingdb.vikingdb.cn-beijing.volces.com",  # 替换为您所在的域名
    )
    req_method = "POST"
    req_params = None
    req_path = "/api/vikingdb/data/delete"
    req_body = {
        "collection_name": "test_coll",
        "ids": [
            "uid_001",
            "uid_002",
            "uid_005",
        ],
    }
    result = client.do_req(
        req_method=req_method, req_path=req_path, req_params=req_params, req_body=req_body
    )
    print("req http status code: ", result.status_code)
    print("req result: \n", result.text)
最近更新时间:2026.04.14 17:18:19
这个页面对您有帮助吗?
有用
有用
无用
无用