Skip to main content

Delete objects

LICENSE Weaviate on Stackoverflow badge Weaviate issues on GitHub badge Weaviate version badge Weaviate total Docker pulls badge Go Report Card

Overview

This page will show you how to delete objects in Weaviate by their id or a set of criteria.

Requirements

To delete a specific object, you'll need its id and class name.

To delete objects by a set of criteria, you'll need their class name, and a where filter.

Multi-tenancy

For classes where multi-tenancy is enabled, you will also need to specify the tenant name when deleting objects. See Manage data: multi-tenancy operations for details on how.

Why specify the class name?
Class Name in Object CRUD Operations

Prior to Weaviate v1.14 it was possible to manipulate objects using only their ID without specifying the class name. This way is still supported for backward compatibility, but is considered deprecated now. Avoid using the deprecated endpoints, as they will be removed with Weaviate v2.0.0.


The reason for the deprecation is that classes generally act like namespaces, therefore duplicate IDs are possible.


Additionally, where multi-tenancy (available from v1.20.0) is enabled, the tenant name is required.


It is thus recommended to always include the class name when manipulating objects.

Delete object by id

To delete an object, specify its class name and id as shown below.

uuid_to_delete = '...'  # replace with the id of the object you want to delete

client.data_object.delete(
uuid=uuid_to_delete,
class_name='EphemeralObject', # Class of the object to be deleted
)
REST endpoint

Delete multiple objects

To delete multiple objects that match a set of criteria, specify the class and a where filter.

Optionally, set output to 'verbose' to see more details (ID and deletion status).

client.batch.delete_objects(
class_name='EphemeralObject',
where={
'path': ['name'],
'operator': 'Like',
'valueText': 'EphemeralObject*'
},
)
REST endpoint
Limit per query

There is a configurable maximum limit on the number of objects that can be deleted in a single query (default 10,000). To delete more objects than the limit, re-run the query.

ContainsAny / ContainsAll

You can use ContainsAny / ContainsAll filters with the where argument to delete objects that contains a specific value in a property.

Note that when using ContainsAny or ContainsAll, the query must be entered as an array of values. The client-specific syntax varies as follows:

client.batch.delete_objects(
class_name='EphemeralObject',
where={
'path': ['name'],
'operator': 'ContainsAny',
'valueTextArray': ['asia', 'europe'] # Note the array syntax
},
)

Dry-run

You can set the dryRun option to check how many objects would be deleted, without actually performing the deletion.

result = (
client.batch.delete_objects(
class_name='EphemeralObject',
# Same `where` filter as in the GraphQL API
where={
'path': ['name'],
'operator': 'Like',
'valueText': 'EphemeralObject*'
},
dry_run=True,
output='verbose'
)
)

import json
print(json.dumps(result, indent=2))
Example response

It should produce a response like the one below:

{
"dryRun": true,
"match": {
"class": "EphemeralObject",
"where": {
"operands": null,
"operator": "Like",
"path": [
"name"
],
"valueText": "EphemeralObject*"
}
},
"output": "verbose",
"results": {
"failed": 0,
"limit": 10000,
"matches": 5,
"objects": [
{
"id": "208cf21f-f824-40f1-95cb-f923bc840ca6",
"status": "DRYRUN"
},
{
"id": "8b2dddd4-2dc7-422c-885d-f9d5ff4e80c8",
"status": "DRYRUN"
},
{
"id": "49b3b2b4-3a77-48cd-8e39-27e83c811fcc",
"status": "DRYRUN"
},
{
"id": "847b31d0-dab4-4c1c-8cd3-af07c9d3dc2c",
"status": "DRYRUN"
},
{
"id": "147d9cea-5f9c-40c1-884a-f99bc8e9bf06",
"status": "DRYRUN"
}
],
"successful": 0
}
}

More Resources

For additional information, try these sources.

  1. Frequently Asked Questions
  2. Weaviate Community Forum
  3. Knowledge base of old issues
  4. Stackoverflow
  5. Weaviate slack channel