首页 DashVector Developer Reference SDK for Java Create a DashVector client

Create a DashVector client

更新时间: 2026-03-11 01:01:14

To interact with DashVector collections, vectors, and similarity searches through your application, you first need a DashVectorClient instance that connects to the DashVector server. This page shows how to create one using the Java SDK.

Quick start

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.common.DashVectorException;

public class Main {
    public static void main(String[] args) throws DashVectorException {
        DashVectorClient client = new DashVectorClient(
            "<your-api-key>",
            "<your-cluster-endpoint>"
        );
        // Use the client to manage collections, insert vectors, and run searches.
    }
}

Replace <your-api-key> and <your-cluster-endpoint> with your actual values. For details, see Initialize the client.

Prerequisites

Before you begin, make sure that you have:

Initialize the client

The DashVectorClient class provides two constructors:

package com.aliyun.dashvector;

// Initialize with an API key and cluster endpoint
DashVectorClient(String apiKey, String endpoint);

// Initialize with a configuration object
DashVectorClient(DashVectorClientConfig config);

Replace the following placeholders with your actual values:

PlaceholderDescriptionWhere to find it
<your-api-key>API key for authenticationManage API keys
<your-cluster-endpoint>Cluster endpoint URLCluster details page in the console
Note

Do not hardcode API keys in production code. Store them as environment variables or use a secrets manager.

Basic initialization

Pass the API key and endpoint directly:

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.common.DashVectorException;

public class Main {
    public static void main(String[] args) throws DashVectorException {
        DashVectorClient client = new DashVectorClient(
            "<your-api-key>",
            "<your-cluster-endpoint>"
        );
    }
}

Configuration-based initialization

Use DashVectorClientConfig to set additional options such as a custom timeout:

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 {
        DashVectorClientConfig config = DashVectorClientConfig.builder()
            .apiKey("<your-api-key>")
            .endpoint("<your-cluster-endpoint>")
            .timeout(10f)   // Timeout in seconds. Set to -1 for no timeout.
            .build();

        DashVectorClient client = new DashVectorClient(config);
    }
}

Configuration parameters

Use the DashVectorClientConfigBuilder methods to build a DashVectorClientConfig object.

MethodRequiredDefaultDescription
apiKey(String apiKey)Yes-API key for authentication
endpoint(String endpoint)Yes-Cluster endpoint. Available on the cluster details page in the console
timeout(Float timeout)No10.0fTimeout period in seconds. Set to -1 for no timeout
build()--Builds the DashVectorClientConfig object
Note

If DashVectorException is thrown during client initialization, you can analyze the cause based on the exception details.

What's next

After you create a client, use it to perform operations on collections such as creating a collection, inserting vectors, and running similarity searches. For details, see the DashVector API documentation.

上一篇: SDK for Java 下一篇: Operations on collections