本文介紹如何通過Java SDK建立一個DashVector Client。
說明
通過DashVector Client可串連DashVector服務端,進行Collection相關操作。
前提條件
已建立Cluster:建立Cluster。
已獲得API-KEY:API-KEY管理。
已安裝最新版SDK:安裝DashVector SDK。
介面定義
package com.aliyun.dashvector;
// 通過apiKey和endpoint構造
DashVectorClient(String apiKey, String endpoint);
// 通過DashVectorClientConfig構造
DashVectorClient(DashVectorClientConfig config);使用樣本
說明
需要使用您的api-key替換樣本中的YOUR_API_KEY、您的Cluster Endpoint替換樣本中的YOUR_CLUSTER_ENDPOINT,代碼才能正常運行。
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorClientConfig;
import com.aliyun.dashvector.common.DashVectorException;
public class Main {
public static void main(String[] args) throws DashVectorException {
// 通過apiKey和endpoint構造
DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");
// 通過Builder構造DashVectorClientConfig
DashVectorClientConfig config = DashVectorClientConfig.builder()
.apiKey("YOUR_API_KEY")
.endpoint("YOUR_CLUSTER_ENDPOINT")
.timeout(10f)
.build();
client = new DashVectorClient(config);
}
}入參描述
可通過DashVectorClientConfigBuilder構造DashVectorClientConfig對象,其可用方法如下:
方法 | 必填 | 預設值 | 說明 |
apiKey(String apiKey) | 是 | - | api-key |
endpoint(String endpoint) | 是 | - | Cluster的Endpoint,可在控制台“Cluster詳情”中查看 |
timeout(Float timeout) | 否 | 10.0f | 逾時時間(單位:秒),-1 代表不逾時。 |
build() | - | - | 構造 |
說明
endpoint參數,可在控制台Cluster詳情中查看。
出參描述
說明
DashVectorClient初始化期間可能拋出DashVectorException異常,可通過具體異常資訊分析初始化失敗原因。