All Products
Search
Document Center

Vector Retrieval Service:Delete documents

Last Updated:Apr 11, 2024

This topic describes how to delete one or more documents from a collection based on the document ID or ID list by using the SDK for Python.

Note

If the ID of a document to be deleted does not exist, the delete operation is invalid for the document.

Prerequisites

API definition

Collection.delete(
    ids: Union[str, List[str]],
    partition: Optional[str] = None,
    async_req: bool = False,
    delete_all: bool = False
) -> DashVectorResponse

Example

Note
  1. You need to replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster in the sample code for the code to run properly.

  2. You need to create a collection named quickstart in advance. For more information, see the "Example" section of the Create a collection topic. You also need to insert some documents in advance. For more information, see Insert documents.

import dashvector

client = dashvector.Client(
    api_key='YOUR_API_KEY',
    endpoint='YOUR_CLUSTER_ENDPOINT'
)
collection = client.get(name='quickstart')

ret = collection.delete('1')
# Check whether the delete method is successfully called.
if ret:
    print('delete success')

# Delete multiple documents at a time.
ret = collection.delete(['1','2'])

# Delete all data from the partition.
ret = collection.delete(delete_all=True)

Request parameters

Parameter

Type

Default value

Description

ids

str or List[str]

-

The primary key or primary key list.

partition

Optional[str]

None

Optional. The name of the partition.

async_req

bool

False

Optional. Specifies whether to enable the asynchronous mode.

delete_all

bool

False

Optional. Specifies whether to delete all data from the partition. If the value is True, the ids parameter must be left empty.

Response parameters

Note

A DashVectorResponse object is returned, which contains the operation result, as described in the following table.

Parameter

Type

Description

Example

code

int

The returned status code. For more information, see Status codes.

0

message

str

The returned message.

success

request_id

str

The unique ID of the request.

19215409-ea66-4db9-8764-26ce2eb5bb99