如何通过HTTP API检索Doc

ops/2024/12/27 12:53:06/

本文介绍如何通过HTTP API在Collection中进行相似性检索。


前提条件

  • 已创建Cluster:创建Cluster。

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

Method与URL

HTTP

POST https://{Endpoint}/v1/collections/{CollectionName}/query

使用示例

说明

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

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

根据向量进行相似性检索

Bash

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vector": [0.1, 0.2, 0.3, 0.4],"topk": 10,"include_vector": true}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/query# example output:
# {
#   "code": 0,
#   "request_id": "2cd1cac7-f1ee-4d15-82a8-b65e75d8fd13",
#   "message": "Success",
#   "output": [
#     {
#       "id": "1",
#       "vector":[
#         0.10000000149011612,
#         0.20000000298023224,
#         0.30000001192092896,
#         0.4000000059604645
#       ],
#       "fields": {
#         "name": "zhangshan",
#         "weight": null,
#         "age": 20,
#         "anykey": "anyvalue"
#       },
#       "score": 0.3
#     }
#   ]
# }

根据主键(对应的向量)进行相似性检索

Bash

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"id": "1","topk": 1,"include_vector": true}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/query# example output:
# {
#   "code":0,
#   "request_id":"fab4e8a2-15e4-4b55-816f-3b66b7a44962",
#   "message":"Success",
#   "output":[
#     {
#       "id":"1",
#       "vector":[
#         0.10000000149011612,
#         0.20000000298023224,
#         0.30000001192092896,
#         0.4000000059604645
#       ],
#        "fields": {
#         "name": "zhangshan",
#         "weight": null,
#         "age": 20,
#         "anykey": "anyvalue"
#       },
#       "score": 0.3
#     }
#   ]
# }

带过滤条件的相似性检索

Bash

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"filter": "age > 18","topk": 1,"include_vector": true}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/query# example output:
# {
#   "code":0,
#   "request_id":"4c7331d8-fba1-4c3a-8673-124568670de7",
#   "message":"Success",
#   "output":[
#     {
#       "id":"1",
#       "vector":[
#         0.10000000149011612,
#         0.20000000298023224,
#         0.30000001192092896,
#         0.4000000059604645
#       ],
#        "fields": {
#         "name": "zhangshan",
#         "weight": null,
#         "age": 20,
#         "anykey": "anyvalue"
#       },
#       "score": 0.0
#     }
#   ]
# }

带有Sparse Vector的向量检索

Bash

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vector": [0.1, 0.2, 0.3, 0.4],"sparse_vector":{"1":0.4, "10000":0.6, "222222":0.8},"topk": 1,"include_vector": true}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/query# example output:
# {
#   "code":0,
#   "request_id":"ad84f7a0-b4b2-4023-ae80-b6f092609a53",
#   "message":"Success",
#   "output":[
#     {
#       "id":"2",
#       "vector":[
#         0.10000000149011612,
#         0.20000000298023224,
#         0.30000001192092896,
#         0.4000000059604645
#       ],
#       "fields":{"name":null,"weight":null,"age":null},
#       "score":1.46,
#       "sparse_vector":{
#         "10000":0.6,
#         "1":0.4,
#         "222222":0.8
#       }
#     }
#   ]
# }

向量检索高级参数

说明

详情可参考 向量检索高级参数。

curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vector": [0.1, 0.2, 0.3, 0.4], "vector_param":{ "radius": 0.53, "is_linear": false, "ef": 1000 },"topk": 10,"include_vector": true
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart_euclidean/query#example output:
#{
#    "code": 0,
#    "request_id": "59df860b-7d29-466b-a345-0bfe9e27329e",
#    "message": "Success",
#    "output": [
#        {
#            "id": "2",
#            "vector": [
#                0.20000000298023224,
#                0.30000001192092896,
#                0.4000000059604645,
#                0.5
#            ],
#            "fields": {
#                "anykey1": "str-value",
#                "anykey2": 1,
#                "name": "zhangshan",
#                "weight": null,
#                "anykey3": true,
#                "anykey4": 3.1415925,
#                "age": 70
#            },
#            "score": 0.04
#        },
#        {
#            "id": "3",
#            "vector": [
#                0.30000001192092896,
#                0.4000000059604645,
#                0.5,
#                0.6000000238418579
#            ],
#            "fields": {
#                "name": null,
#                "weight": null,
#                "age": null
#            },
#            "score": 0.16000001
#        },
#        {
#            "id": "4",
#            "vector": [
#                0.4000000059604645,
#                0.5,
#                0.6000000238418579,
#                0.699999988079071
#            ],
#            "fields": {
#                "name": "zhangsan",
#                "weight": null,
#                "age": 20
#            },
#            "score": 0.36
#        }
#    ]
#}

向量检索

说明

详情可参考 多向量检索

RrfRanker 示例
curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vectors": {"title": {"vector": [0.1, 0.2, 0.3, 0.4]}, "content": {"vector": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6], "param": {"num_candidates": 10}}},"topk": 20,"rerank": {"ranker_name": "rrf", "ranker_params": {"rank_constant":"100"} }
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/multi_vector_demo/query# example output:
#{
#    "code": 0,
#    "request_id": "db20ba2b-9dc6-4c23-9266-430e6fb1a70d",
#    "message": "Success",
#    "output": [
#        {
#            "id": "1",
#            "fields": {
#                "author": null
#            },
#            "score": 0.019704912
#        },
#        {
#            "id": "2",
#            "fields": {
#                "author": "zhangsan"
#            },
#            "score": 0.00990099
#        },
#        {
#            "id": "3",
#            "fields": {
#                "author": null,
#                "anykey": "anyvalue"
#            },
#            "score": 0.009803922
#        }
#    ]
#}
WeightedRanker 示例
curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vectors": {"title": {"vector": [0.1, 0.2, 0.3, 0.4]}, "content": {"vector": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6], "param": {"num_candidates": 10}}},"topk": 20,"rerank": {"ranker_name": "weighted", "ranker_params": {"weights": "{\"title\":0.2, \"content\":0.8}" }}
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/multi_vector_demo/query# example output:
#{
#    "code": 0,
#    "request_id": "c7413fa9-92fd-4493-8f21-6c65c83e7b91",
#    "message": "Success",
#    "output": [
#        {
#            "id": "1",
#            "fields": {
#                "author": null
#            },
#            "score": 0.8156271
#        },
#        {
#            "id": "3",
#            "fields": {
#                "author": null,
#                "anykey": "anyvalue"
#            },
#            "score": 0.5880098
#        },
#        {
#            "id": "2",
#            "fields": {
#                "author": "zhangsan"
#            },
#            "score": 0.2
#        }
#    ]
#}
使用多向量的一个向量执行检索
curl -XPOST \-H 'dashvector-auth-token: YOUR_API_KEY' \-H 'Content-Type: application/json' \-d '{"vectors": {"title": {"vector": [0.1, 0.2, 0.3, 0.4], "param":{ "radius": 0.1, "is_linear": true, "ef": 1000 }}},"topk": 20,"include_vector": true
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/multi_vector_demo/query# example output:
#{
#    "code": 0,
#    "request_id": "b9bc3d5a-8edf-4d5b-916d-0ced6ae570cb",
#    "message": "Success",
#    "output": [
#        {
#            "id": "4",
#            "vectors": {
#                "title": [
#                    0.10000000149011612,
#                    0.20000000298023224,
#                    0.30000001192092896,
#                    0.4000000059604645
#                ]
#            },
#            "fields": {
#                "author": "zhangsan"
#            },
#            "score": 0.0
#        },
#        {
#            "id": "2",
#            "vectors": {
#                "title": [
#                    0.10000000149011612,
#                    0.20000000298023224,
#                    0.30000001192092896,
#                    0.4000000059604645
#                ]
#            },
#            "fields": {
#                "author": "zhangsan"
#            },
#            "score": 0.0
#        }
#    ]
#}

入参描述

说明

vectorid两个入参需要二选一使用,如都不传入,则仅完成条件过滤。

参数

Location

类型

必填

说明

{Endpoint}

path

str

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

{CollectionName}

path

str

Collection名称

dashvector-auth-token

header

str

api-key

vector

body

array

向量数据

sparse_vector

body

dict

稀疏向量

id

body

str

主键,表示根据主键对应的向量进行相似性检索

topk

body

int

返回topk相似性结果,默认10

filter

body

str

过滤条件,需满足SQL where子句规范,详见条件过滤检索

include_vector

body

bool

是否返回向量数据,默认false

output_fields

body

array

返回field的字段名列表,默认返回所有Fields

partition

body

str

Partition名称

vectors

body

dict

多个向量检索,类型为Map<String, VectorQuery>,详情参考多向量检索

rerank

body

dict

融合排序参数,详情参考多向量检索

vector_param

body

dict

高级检索参数,详情参考 向量检索高级参数

出参描述

字段

类型

描述

示例

code

int

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

0

message

str

返回消息

success

request_id

str

请求唯一id

19215409-ea66-4db9-8764-26ce2eb5bb99

output

array

相似性检索结果,Doc列表

usage

map

对Serverless实例(按量付费)集合的Doc检索请求,成功后返回实际消耗的读请求单元数

{Usage: {read_units: 8}
}

http://www.ppmy.cn/ops/145378.html

相关文章

【MySQL】在MySQL中如何定位慢查询?

MySQL慢查询定位面试问答总结 一、面试官提问 在MySQL中如何定位慢查询&#xff1f; 二、面试者回答 &#xff08;一&#xff09;整体思路 定位慢查询主要有两种方式&#xff0c;一种是使用开源工具&#xff0c;另一种是利用MySQL自带的慢日志查询功能。 &#xff08;二&a…

使用Webpack构建微前端应用

英文社区对 Webpack Module Federation 的响应非常热烈&#xff0c;甚至被誉为“A game-changer in JavaScript architecture”&#xff0c;相对而言国内对此热度并不高&#xff0c;这一方面是因为 MF 强依赖于 Webpack5&#xff0c;升级成本有点高&#xff1b;另一方面是国内已…

美食推荐系统|Java|SSM|JSP|

【技术栈】 1⃣️&#xff1a;架构: B/S、MVC 2⃣️&#xff1a;系统环境&#xff1a;Windowsh/Mac 3⃣️&#xff1a;开发环境&#xff1a;IDEA、JDK1.8、Maven、Mysql5.7 4⃣️&#xff1a;技术栈&#xff1a;Java、Mysql、SSM、Mybatis-Plus、JSP、jquery,html 5⃣️数据库可…

【安全编码】Web平台如何设计防止重放攻击

我们先来做一道关于防重放的题&#xff0c;答案在文末 防止重放攻击最有效的方法是&#xff08; &#xff09;。 A.对用户密码进行加密存储使用 B.使用一次一密的加密方式 C.强制用户经常修改用户密码 D.强制用户设置复杂度高的密码 如果这道题目自己拿不准&#xff0c;或者…

区块链期末复习3.2:比特币脚本

目录 一、输入输出脚本的执行 二、简单脚本实例及压栈过程 1.P2PK&#xff08;pay to public key hash&#xff09; 2、P2PH&#xff08;pay to public key hash&#xff09; 3.多重签名 4.比特币脚本的应用&#xff1a; 三、其他常见指令 1.OP_EQUAL与OP&#xff3f;EQ…

数据仓库在英雄云表单中的应用-如何反向利用它实现更高效的数据管理?-英雄云

在现代企业的数据管理中&#xff0c;数据仓库作为核心组件&#xff0c;能够有效整合和分析来自不同来源的数据。英雄云的云表单功能与数据仓库的结合&#xff0c;为企业提供了高效的数据管理解决方案。本文将探讨数据仓库在英雄云表单中的应用&#xff0c;以及如何反向利用这一…

Kafka可视化工具 Offset Explorer (以前叫Kafka Tool)

数据的存储是基于 主题&#xff08;Topic&#xff09; 和 分区&#xff08;Partition&#xff09; 的 Kafka是一个高可靠性的分布式消息系统&#xff0c;广泛应用于大规模数据处理和实时, 为了更方便地管理和监控Kafka集群&#xff0c;开发人员和运维人员经常需要使用可视化工具…

HDR视频技术之十一:HEVCH.265 的 HDR 编码方案

前文我们对 HEVC 的 HDR 编码优化技术做了介绍&#xff0c;侧重编码性能的提升。 本章主要阐述 HEVC 中 HDR/WCG 相关的整体编码方案&#xff0c; 包括不同应用场景下的 HEVC 扩展编码技术。 1 背景 HDR 信号一般意味着使用更多比特&#xff0c;一般的 HDR 信号倾向于使用 10…