当前位置: 首页 > news >正文

如何通过HTTP API插入或更新Doc

本文介绍如何通过HTTP API向Collection中插入或更新Doc。


说明

  1. 若调用本接口时Doc Id已存在,则等同于更新Doc;Doc Id不存在,则等同于插入Doc。

  2. 若调用本接口时不指定Doc Id,则等同于插入Doc,DashVector会自动生成Doc Id,并在返回结果中携带id信息。

前提条件

  • 已创建Cluster:创建Cluster。

  • 已获得API-KEY:API-KEY管理。

Method与URL

HTTP

POST https://{Endpoint}/v1/collections/{CollectionName}/docs/upsert

使用示例

说明

  1. 需要使用您的api-key替换示例中的YOUR_API_KEY、您的Cluster Endpoint替换示例中的YOUR_CLUSTER_ENDPOINT,代码才能正常运行。

  2. 本示例需要参考新建Collection-使用示例提前创建好名称为quickstart的Collection

插入或更新Doc

Shell

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"docs": [{"id": "1", "vector": [0.1, 0.2, 0.3, 0.4]}]}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs/upsert# example output:
# {"request_id":"1b8b4ada-1148-49ce-82e3-f7f521bb6f3b","code":0,"message":"Success","output":[{"doc_op":"insert","id":"1","code":0,"message":""}]}

插入或更新不带有Id的Doc

Shell

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"docs": [{"vector": [0.1, 0.2, 0.3, 0.4]}]}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs/upsert# example output:
# {"request_id":"9c3f2441-c47b-43a0-bb84-127ff6a88711","code":0,"message":"Success","output":[{"doc_op":"insert","id":"6176745980928","code":0,"message":""}]}

插入或更新带有Fields的Doc

Shell

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"docs": [{"id": "2", "vector": [0.2, 0.3, 0.4, 0.5], "fields": {"age": 70, "name": "zhangshan","anykey1": "str-value","anykey2": 1,"anykey3": true,"anykey4": 3.1415926}}]}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs/upsert# example output:
# {"request_id":"e1467d91-f4fd-4944-9ec0-1634de426db1","code":0,"message":"Success","output":[{"doc_op":"insert","id":"2","code":0,"message":""}]}

批量插入或更新Doc

Shell

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{ "docs": [ {"id": "3", "vector": [0.3, 0.4, 0.5, 0.6]},{"id": "4", "vector": [0.4, 0.5, 0.6, 0.7], "fields": {"age": 20, "name": "zhangsan"}},{"id": "5", "vector": [0.5, 0.6, 0.7, 0.8], "fields": {"anykey": "anyvalue"}}]}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs/upsert# example output:
# {"request_id":"113d221b-ec79-4fde-b546-58db5154e49d","code":0,"message":"Success","output":[{"doc_op":"insert","id":"3","code":0,"message":""},{"doc_op":"insert","id":"4","code":0,"message":""},{"doc_op":"insert","id":"5","code":0,"message":""}]}

插入或更新带有Sparse Vector的Doc

Shell

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"docs": [{"id": "6", "vector": [0.1, 0.2, 0.3, 0.4], "sparse_vector":{"1":0.4, "10000":0.6, "222222":0.8}}]}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs/upsert# example output:
# {"request_id":"c401e51d-430e-4c49-9d07-c944ec94de7b","code":0,"message":"Success","output":[{"doc_op":"insert","id":"6","code":0,"message":""}]}

入参描述

参数

Location

类型

必填

说明

{Endpoint}

path

str

Cluster的Endpoint,可在控制台Cluster详情中查看

{CollectionName}

path

str

Collection名称

dashvector-auth-token

header

str

api-key

docs

body

array

待更新或插入的Doc列表

partition

body

str

Partition名称

出参描述

字段

类型

描述

示例

code

int

返回值,参考返回状态码说明

0

message

str

返回消息

success

request_id

str

请求唯一id

19215409-ea66-4db9-8764-26ce2eb5bb99

output

array

返回插入或更新Doc的结果,DocOpResult列表

usage

map

对Serverless实例(按量付费)集合的Doc插入或更新请求,成功后返回实际消耗的写请求单元数

{Usage: {write_units: 4}
}
http://www.lryc.cn/news/510519.html

相关文章:

  • C++ STM32 F4xx USART LL库 DMA + IDLE ISR 驱动裸机 +FreeRTOS 任务通知
  • RK3588在Android13/14如何查看GPU,NPU,DDR,RGA数据
  • sentinel学习笔记6-限流降级(上)
  • 【Rust自学】6.4. 简单的控制流-if let
  • 【HarmonyOS】鸿蒙将资源文件夹Resource-RawFile下的文件存放到沙箱目录下
  • Vue项目中env文件的作用和配置
  • 在 Vue3 项目中实现计时器组件的使用(Vite+Vue3+Node+npm+Element-plus,附测试代码)
  • 机器人C++开源库The Robotics Library (RL)使用手册(三)
  • Photoshop启动错误:找不到MSVCP140.dll的多步骤解决指南
  • mac中idea菜单工具栏没有git图标了
  • 学习threejs,PerspectiveCamera透视相机和OrthographicCamera正交相机对比
  • C#数学相关开发性能优化方法
  • 【前沿 热点 顶会】AAAI 2025中与目标检测有关的论文
  • APP投放的归因框架设计
  • 职业生涯记录-1
  • 江苏捷科云:可视化平台助力制造企业智能化管理
  • 【ES6复习笔记】Promise对象详解(12)
  • 01 Oracle 基本操作
  • C语言基础:指针(数组指针与指针数组)
  • 本地部署 LLaMA-Factory
  • Web前端基础知识(三)
  • 数据库设计问题记录
  • mac_录屏
  • 【Java-tesseract】OCR图片文本识别
  • redis cluster集群
  • 解锁高效密码:适当休息,让学习状态满格
  • 代码随想录算法训练营第十一天-150.逆波兰表达式求值
  • C++ 泛编程 —— 嵌套使用模板类
  • 【WebGIS】Cesium:GLTF数据加载
  • 【面经】25届 双非本科 字节跳动 北京 四年的总结