如何通过Python SDK新建一个DashVector Client

本文介绍如何通过Python SDK新建一个DashVector Client。

说明

通过DashVector Client可连接DashVector服务端,进行Collection相关操作。

前提条件

接口定义

Python示例:

复制代码
dashvector.Client(
    api_key: str,
    endpoint: str,
    protocol: dashvector.DashVectorProtocol = dashvector.DashVectorProtocol.GRPC,
    timeout: float = 10.0
) -> Client

使用示例

说明

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

Python示例:

复制代码
import dashvector

client = dashvector.Client(
    api_key='YOUR_API_KEY',
    endpoint='YOUR_CLUSTER_ENDPOINT'
)

# 判断client是否创建成功
if client:
    print('create client success!')

# 等同于下列代码
# from dashvector import DashVectorCode
# if client.code == DashVectorCode.Success:
#     print('create client success!')

入参描述

|--------------|--------------------|-------------------------|------------------------------------------------------|
| 参数 | 类型 | 默认值 | 说明 |
| api_key | str | - | api-key |
| endpoint | str | - | Cluster的Endpoint |
| protocol(可选) | DashVectorProtocol | DashVectorProtocol.GRPC | 通信协议,DashVectorProtocol.GRPC、DashVectorProtocol.HTTP |
| timeout(可选) | float | 10.0 | 超时时间(单位:秒),-1 代表不超时。 |

说明

1.endpoint参数,可在控制台Cluster详情中查看。

2.protocol参数,建议使用默认值DashVectorProtocol.GRPC,可获得更高的性能体验。

出参描述

说明

返回结果为Client对象,Client对象中可获取本次操作结果信息,如下表所示。

|------------|--------|---------------------------------------------------------------------------------|--------------------------------------|
| 字段 | 类型 | 描述 | 示例 |
| code | int | 返回值,参考返回状态码说明 | 0 |
| message | str | 返回消息 | success |
| request_id | str | 请求唯一id | 19215409-ea66-4db9-8764-26ce2eb5bb99 |

相关推荐
AI科技11 分钟前
原因大揭秘:为什么别人的编曲伴奏做得又快又好,2026年度甄选5款AI编曲软件汇总
人工智能
Mark_Aussie16 分钟前
Dify本地部署及使用
人工智能
dLYG DUMS17 分钟前
DBeaver连接本地MySQL、创建数据库表的基础操作
数据库·mysql
小熊Coding21 分钟前
Python2D射击冒险闯关游戏2.0版本
python·pygame
guo_xiao_xiao_23 分钟前
YOLOv11高空俯视场景猫狗人目标检测数据集-1488张-bag-1_4
人工智能·yolo·目标检测
FYKJ_201035 分钟前
springboot校园兼职平台--附源码02041
java·javascript·spring boot·python·eclipse·django·php
玩转单片机与嵌入式1 小时前
玩转边缘AI(TInyML):需要掌握的C++知识汇总!
开发语言·c++·人工智能
Rubin智造社1 小时前
2026年热门AI工具汇总|8大类别全覆盖,办公/创作/编程一键解锁
人工智能·ai作画·aigc·ai工具
feasibility.1 小时前
SpaceMind论文解读:太空具身智能的范式跃迁 —— 中科院发布首个自进化太空机器人智能体框架
人工智能·科技·机器人·具身智能·skills·太空·进化