Delete a DashVector collection and all its data using the SDK for Java.
Deleting a collection permanently removes all data in it, including vectors, metadata, and indexes. This action is irreversible. Back up any data you need before deleting collections in production environments.
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 Java. For more information, see Install DashVector SDK
API definition
// DashVectorClient
public Response<Void> delete(String name);Sample code
Replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster. The collection named quickstart must already exist. To create one, see the example in Create a collection.
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
public class Main {
public static void main(String[] args) throws DashVectorException {
// Initialize the client
DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");
// Delete the collection
Response<Void> response = client.delete("quickstart");
// Verify the result
System.out.println("Success: " + response.isSuccess());
System.out.println("Code: " + response.getCode());
System.out.println("Message: " + response.getMessage());
System.out.println("Request ID: " + response.getRequestId());
}
}Replace the following placeholders with your values:
| Placeholder | Description | Example |
|---|---|---|
YOUR_API_KEY | Your API key for authentication | LTAI5tXxx |
YOUR_CLUSTER_ENDPOINT | The endpoint URL of your DashVector cluster | vrs-cn-xxx.dashvector.aliyuncs.com |
Request parameters
Parameter | Type | Required | Default value | Description |
name | String | Yes | - | The name of the collection to delete |
Response parameters
The delete method returns a Response<Void> object with the following methods:
Method | Type | Description | Example |
isSuccess() | Boolean | Whether the operation succeeded | true |
getCode() | int | The status code. For more information, see Status codes. | 0 |
getMessage() | String | The response message | success |
getRequestId() | String | The unique request ID | 19215409-ea66-4db9-8764-26ce2eb5bb99 |