Delete a partition

更新时间:
复制 MD 格式

Delete a partition and all its data from a DashVector collection using the Java SDK.

Warning

Deleting a partition is irreversible. All vectors and data in the partition are permanently deleted and cannot be recovered.

Prerequisites

Before you begin, make sure that you have:

API signature

// DashVectorCollection
public Response<Void> deletePartition(String name);

Request parameters

ParameterTypeRequiredDefaultDescription
nameStringYes-Name of the partition to delete.

Sample code

Before you run this example, replace the placeholder values:

PlaceholderDescription
<your-api-key>API key for your DashVector cluster
<your-cluster-endpoint>Endpoint of your DashVector cluster

This example deletes a partition named shoes from a collection named quickstart. Create the collection and partition before you run this code:

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 {
        DashVectorClient client = new DashVectorClient("<your-api-key>", "<your-cluster-endpoint>");
        DashVectorCollection collection = client.get("quickstart");

        // Delete the partition named "shoes"
        Response<Void> response = collection.deletePartition("shoes");

        // Verify the result
        if (response.isSuccess()) {
            System.out.println("Partition deleted successfully.");
        } else {
            System.out.println("Failed to delete partition: " + response.getMessage());
        }
    }
}

Response

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

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