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:
A DashVector cluster. For more information, see Create a cluster
An API key. For more information, see Manage API keys
The latest version of the DashVector SDK. For more information, see Install DashVector SDK
API signature
// DashVectorCollection
public Response<Void> deletePartition(String name);Request parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| name | String | Yes | - | Name of the partition to delete. |
Sample code
Before you run this example, replace the placeholder values:
| Placeholder | Description |
|---|---|
<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:
| Method | Return type | Description | Example |
|---|---|---|---|
| getCode() | int | Status code. For more information, see Status codes. | 0 |
| getMessasge() | String | Response message. | success |
| getRequestId() | String | Unique request ID. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
| isSuccess() | Boolean | Whether the operation succeeded. | true |