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.

    import weaviate.classes as wvc

collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=wvc.query.Filter.by_property("name").like("EphemeralObject*")
)
Additional information
  • 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.

Use ContainsAny / ContainsAll

The ContainsAny / ContainsAll filters allow deletion of objects that match a set of criteria.

    import weaviate.classes as wvc

collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=wvc.query.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.

    import weaviate.classes as wvc

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=wvc.query.Filter.by_id().contains_any(ids) # Delete the 3 objects
)

Optional parameters

  • Enable 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.
    import weaviate.classes as wvc

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

print(result)
Example response

It should produce a response like the one below: