All Products
Search
Document Center

DashVector:Create a partition

Last Updated:Mar 11, 2026

This topic describes how to create a partition in a DashVector collection using the Java SDK.

Prerequisites

Before you begin, make sure that you have:

API definition

// class DashVectorCollection

public Response<Void> createPartition(String name, Integer timeout);

Request parameters

ParameterTypeRequiredDefaultDescription
nameStringYes-The name of the partition to create.
timeoutIntegerNonullControls synchronous or asynchronous behavior. See the following table for details.

Timeout behavior

ValueModeBehavior
nullSynchronousBlocks until the partition is created, then returns.
-1AsynchronousThe method works in asynchronous mode.
>= 0SynchronousBlocks for up to the specified duration. Returns a timeout error if the partition is not created within this period.

Response parameters

The method returns a Response<Void> object with the following methods:

MethodReturn typeDescriptionExample
getCode()intStatus code. For more information, see Status codes.0
getMessage()StringResponse message.success
getRequestId()StringUnique request ID.19215409-ea66-4db9-8764-26ce2eb5bb99
isSuccess()BooleanWhether the operation succeeded.true

Example

Note

Before running this example, replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with your cluster endpoint. You also need a collection named quickstart. For details, see the "Example" section in Create a collection.

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
import com.aliyun.dashvector.models.responses.Response;

public class Main {
    public static void main(String[] args) throws DashVectorException {
        // 1. Connect to the cluster
        DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");

        // 2. Get the target collection
        DashVectorCollection collection = client.get("quickstart");

        // 3. Create a partition named "shoes"
        Response<Void> response = collection.createPartition("shoes");

        // 4. Verify the result
        if (response.isSuccess()) {
            System.out.println("createPartition success");
        }
    }
}

Related operations