全部產品
Search
文件中心

DashVector:建立Client

更新時間:Jul 13, 2024

本文介紹如何通過Java SDK建立一個DashVector Client。

說明

通過DashVector Client可串連DashVector服務端,進行Collection相關操作。

前提條件

介面定義

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()

-

-

構造DashVectorClientConfig對象

說明

endpoint參數,可在控制台Cluster詳情中查看。

出參描述

說明

DashVectorClient初始化期間可能拋出DashVectorException異常,可通過具體異常資訊分析初始化失敗原因。