Call DeleteVectors to remove vector data from a vector index by specifying a list of keys. The deletion is irreversible.
Permissions
An Alibaba Cloud account has all permissions by default. A Resource Access Management (RAM) user or RAM role has no permissions by default. Grant the required permission using a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| DeleteVectors | oss:DeleteVectors | Deletes vector data |
Prerequisites
Before you begin, ensure that you have:
An OSS bucket with a vector index
The
oss:DeleteVectorspermission on the bucketPython SDK V2 installed (
alibabacloud-oss-v2)Credentials configured as environment variables
Delete vectors by key
This operation is irreversible. Deleted vector data cannot be recovered.
The following example deletes vectors identified by a list of keys.
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 domain names that other services can use to access OSS')
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()
# Use 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
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()Method reference
Method signature
delete_vectors(request: DeleteVectorsRequest, **kwargs) → DeleteVectorsResultRequest 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 method definition, see delete_vectors.
References
For the complete sample code, see delete_vectors.py.