本文介紹如何通過Python SDK建立一個DashVector Client。
通過DashVector Client可串連DashVector服務端,進行Collection相關操作。
前提條件
已建立Cluster:建立Cluster。
已獲得API-KEY:API-KEY管理。
已安裝最新版SDK:安裝DashVector SDK。
介面定義
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,代碼才能正常運行。
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 代表不逾時。 |
endpoint參數,可在控制台Cluster詳情中查看。
protocol參數,建議使用預設值
DashVectorProtocol.GRPC
,可獲得更高的效能體驗。
出參描述
返回結果為Client對象,Client對象中可擷取本次操作結果資訊,如下表所示。
欄位 | 類型 | 描述 | 樣本 |
code | int | 傳回值,參考返回狀態代碼說明 | 0 |
message | str | 返回訊息 | success |
request_id | str | 請求唯一id | 19215409-ea66-4db9-8764-26ce2eb5bb99 |