Delete Documents
Zvec provides two ways to delete documents. Choose the method that best fits your use case:
| Method | Input | When to Use |
|---|---|---|
delete() | One or more document ids | Use when you know the exact ID(s) of the documents you want to delete |
delete_by_filter() | A filter expression (e.g., publish_year < 1900) | Use for bulk deletion based on field values — ideal for cleaning up documents that match specific criteria |
Delete operations are immediate and irreversible.
Always double-check your input before running a delete operation.
Delete by IDs
Assume you've already opened a collection and have a collection object ready.
Use delete() to remove one or more documents when you know their exact IDs.
# Delete a single document
result = collection.delete(ids="doc_id_1")
print(result) # {"code":0} means success
# Delete multiple documents at once
result = collection.delete(ids=["doc_id_2", "doc_id_3"])
print(result) # [{"code":0}, {"code":0}]- When given a single
id,delete()returns oneStatusobject. - When given a list of
ids, it returns a list ofStatusobjects in the same order. {"code": 0}indicates success.- Non-zero codes indicate failure — for example, if the document
iddoes not exist.
Delete by Filter Condition
Use delete_by_filter() to remove all documents that match a boolean filter expression.
The filter can reference scalar fields (e.g., publish_year, language) using comparison and logical operators.
# Delete all books published before 1900
collection.delete_by_filter(filter="publish_year < 1900")
# Combined filter
collection.delete_by_filter(
filter='publish_year < 1900 AND (language = "English" OR language = "Chinese")'
)