Skip to main content

Delete objects

Weaviate allows object deletion by id or by a set of criteria.

Additional information
  • To delete objects, you must provide the collection name as well as identifying criteria (e.g. object id or filters).

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


    Collection (class) Name in Object CRUD Operations

    Collections act like namespaces, so two different collections could have duplicate IDs between them.


    Prior to Weaviate v1.14 you can manipulate objects without specifying the collection name. This method is deprecated. It will be removed in Weaviate v2.0.0.

    Starting in v1.20, you can have multi-tenant datasets. When multi-tenancy is enabled, the tenant name is required.

    Always include the collection name, and, when enabled, the tenant name.

Delete object by id

To delete by id, specify the collection name and the object id.

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

collection = client.collections.get("EphemeralObject")
collection.data.delete_by_id(
uuid_to_delete
)

Delete multiple objects

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

from weaviate.classes.query import Filter

collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=Filter.by_property("name").like("EphemeralObject*")
)
Additional information
  • There is a configurable maximum limit (QUERY_MAXIMUM_RESULTS) 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

Use ContainsAny / ContainsAll filters to delete of objects by a set of criteria.

from weaviate.classes.query import Filter

collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=Filter.by_property("name").contains_any(["europe", "asia"])
)
Additional information

This feature was added in Weaviate v1.21.

Delete multiple objects by id

To delete multiple objects by their id values, use a filter (e.g. ContainsAny) with id based criteria.

Limitations

There is an upper limit (QUERY_MAXIMUM_RESULTS) to how many objects can be deleted using a single query. This protects against unexpected memory surges and very-long-running requests which would be prone to client-side timeouts or network interruptions.

Objects are deleted in the same order that they would be fetched, by order of UUID. To delete more objects than the limit, run the same query multiple times until no objects are matched anymore.

The default QUERY_MAXIMUM_RESULTS value is 10,000. This may be configurable, e.g. in the environment variables.

from weaviate.classes.query import Filter

collection = client.collections.get("EphemeralObject")

response = collection.query.fetch_objects(limit=3) # Fetch 3 object IDs
ids = [o.uuid for o in response.objects] # These can be lists of strings, or `UUID` objects

collection.data.delete_many(
where=Filter.by_id().contains_any(ids) # Delete the 3 objects
)

Delete all objects

Objects must belong to a collection in Weaviate. Accordingly, deleting collections will remove all objects within them.

Optional parameters

  • You can use dryRun to check how many objects would be deleted, without actually performing the deletion.
  • Set output to 'verbose' to see more details (ID and deletion status) for each deletion.
from weaviate.classes.query import Filter

collection = client.collections.get("EphemeralObject")
result = collection.data.delete_many(
where=Filter.by_property("name").like("EphemeralObject*"),
dry_run=True,
verbose=True
)

print(result)
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
}
}

Questions and feedback

If you have any questions or feedback, let us know in the user forum.