如何通过HTTP API更新Doc

本文介绍如何通过HTTP API更新Collection中已存在的Doc。


说明

  1. 若更新Doc时指定id不存在,则本次更新Doc操作无效

  2. 如只更新部分属性fields,其他未更新属性fields默认被置为null

前提条件

Method与URL

HTTP

复制代码
PUT https://{Endpoint}/v1/collections/{CollectionName}/docs

使用示例

说明

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

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

插入Doc

Shell

复制代码
curl -XPUT \
  -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

# example output:
# {"request_id":"b1ce1b30-14a2-4e38-9931-f0b832660da9","code":0,"message":"Success","output":[{"doc_op":"update","id":"1","code":0,"message":""}]}

插入带有Fields的Doc

Shell

复制代码
curl -XPUT \
  -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

# example output:
# {"request_id":"0d22a37f-e906-4121-8408-7f1b685bb211","code":0,"message":"Success","output":[{"doc_op":"update","id":"2","code":0,"message":""}]}

批量插入Doc

Shell

复制代码
curl -XPUT \
  -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

# example output:
# {"request_id":"d9a81bbc-7010-4902-a91c-7402e13143fa","code":0,"message":"Success","output":[{"doc_op":"update","id":"3","code":0,"message":""},{"doc_op":"update","id":"4","code":0,"message":""},{"doc_op":"update","id":"5","code":0,"message":""}]}

插入带有Sparse Vector的Doc

Shell

复制代码
curl -XPUT \
  -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

# example output:
# {"request_id":"bb28479a-1a54-4d0b-a083-6399ac7bceeb","code":0,"message":"Success","output":[{"doc_op":"update","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 | 返回更新的结果,DocOpResult列表 | |
| usage | map | 对Serverless实例(按量付费)集合的Doc更新请求,成功后返回实际消耗的写请求单元数 | { Usage: { write_units: 5 } } |

相关推荐
AI分享猿3 分钟前
游戏原画与建筑灵感:AI图像生成如何服务前期设计
人工智能·游戏
凌虚8 分钟前
面向 MySQL 用户的 PostgreSQL 快速上手指南
数据库·后端·架构
五阿哥永琪18 分钟前
MySQL中操作json的函数!
数据库·mysql·json
来者皆善22 分钟前
了解Mysql优化吗?如何优化索引?
数据库·mysql
字节跳动视频云技术团队29 分钟前
为什么 AI 视频,需要“懂生成”的画质增强
人工智能
后端小肥肠1 小时前
我做了个能一键搭建个人工作台的 Skill,已开源
人工智能·aigc·agent
码云之上1 小时前
AI Agent 工程化总览篇:从 Prompt 到 Harness
前端·人工智能
2501_926978331 小时前
以说明书 DNA 为模板——完整 AGI 的结构图景
前端·人工智能·经验分享·笔记·ai写作
IT_陈寒1 小时前
Vite静态资源引用这个坑我踩得有点疼
前端·人工智能·后端