如何通过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 |

相关推荐
overmind10 小时前
oeasy Python 116 用列表乱序shuffle来洗牌抓拍玩升级拖拉机
服务器·windows·python
念越10 小时前
MySQL报错:Column count doesn‘t match value count at row 1 解决方案(超详细)
数据库·mysql
A懿轩A10 小时前
【Java 基础编程】Java 枚举与注解从零到一:Enum 用法 + 常用注解 + 自定义注解实战
java·开发语言·python
狮子座明仔10 小时前
Agent World Model:给智能体造一个“矩阵世界“——无限合成环境驱动的强化学习
人工智能·线性代数·语言模型·矩阵
OpenMiniServer10 小时前
AI 大模型的本质:基于大数据的拟合,而非创造
大数据·人工智能
tuokuac10 小时前
MyBatis-Plus调用getEntity()触发异常
java·mybatis
SmartBrain10 小时前
FastAPI实战(第二部分):用户注册接口开发详解
数据库·人工智能·python·fastapi
星爷AG I10 小时前
12-6 心理理论(AGI基础理论)
人工智能·agi
向哆哆10 小时前
102类农业害虫图像识别数据集:智慧农业与精准防控的高质量资源
人工智能
橙露10 小时前
不同语言共享内存的各个方案以及使用场景
大数据