You can use the Python SDK V2 to call the DeleteVectors operation to delete vector data based on specified keys. This operation is irreversible. Proceed with caution.
Permissions
An Alibaba Cloud account has all permissions by default. A Resource Access Management (RAM) user or RAM role has no permissions by default. The Alibaba Cloud account or an administrator must grant permissions using a RAM policy or a bucket policy.
|
API |
Action |
Description |
|
DeleteVectors |
|
Deletes vector data. |
Method definition
delete_vectors(request: DeleteVectorsRequest, **kwargs) → DeleteVectorsResult
Request parameters
|
Parameter |
Type |
Description |
|
request |
DeleteVectorsRequest |
Sets the request parameters, including the bucket name, index name, and a list of vector keys. For more information, see DeleteVectorsRequest. |
Return value
|
Type |
Description |
|
DeleteVectorsResult |
The return value. For more information, see DeleteVectorsResult. |
For the complete definition of the delete_vectors method, see delete_vectors.
Sample code
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="vector delete vectors sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The OSS access endpoint')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account ID.', required=True)
def main():
args = parser.parse_args()
# Load credentials from environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
cfg.account_id = args.account_id
cfg.use_internal_endpoint = True # Set to False or remove this line to access OSS over the public network.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
vector_client = oss_vectors.Client(cfg)
keys = ['key1', 'key2', 'key3']
result = vector_client.delete_vectors(oss_vectors.models.DeleteVectorsRequest(
bucket=args.bucket,
index_name=args.index_name,
keys=keys,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
if __name__ == "__main__":
main()
References
For the complete sample code for deleting vector data, see delete_vectors.py.