Anyone used many WHERE filters in DELETE

Description

I looked at the support page for delete_many but nowhere does it mention how to put multiple properties: Delete objects | Weaviate

Is it even possible?

Can I delete all objects where property A = “Hello” and property B = “World”?

Here is the code I have so far, but it is throwing assertion error:

metadata = {
            "document_name": "my_document",
            "document_type": "xml",
            "source": "source1"
        }

filters = {
            "operator": "And",
            "operands": [
                {
                    "path": [key],
                    "operator": "Equal",
                    "valueString": value
                } for key, value in metadata.items()
            ]
        }
        print(filters)
        collection = self.__get_tenant_collection_object(self.collection_name, tenant_name)

        response = collection.data.delete_many(
            where=filters
        )

I want to delete all documents that have

            "document_name" = "my_document"
AND
            "document_type" = "xml"
AND
            "source" = "source1"

Server Setup Information

  • Weaviate Server Version: Cloud
  • Deployment Method:
  • Multi Node? Number of Running Nodes: Cloud
  • Client Language and Version: Python 3.10, Weaviate 4.8.1
  • Multitenancy?: yes

@Mohamed_Shahin is this something you could assist with? It is a blocker for further development on Weaviate.

hi @Analitiq !

You can for sure do that.

This is how to do it using python v4 client:

client.collections.delete("Test")
collection = client.collections.create(
    "Test",
    properties=[
        wvc.config.Property(
            name="text", data_type=wvc.config.DataType.TEXT
        )
    ]
)
collection.data.insert({"document_name": "my_document", "document_type": "xml", "source": "source1"})
collection.data.insert({"document_name": "my_document", "document_type": "xml", "source": "source2"})

We now have two objects:

collection.aggregate.over_all()

AggregateReturn(properties={}, total_count=2)

Now we delete:

collection.data.delete_many(
    where=(
        wvc.query.Filter.by_property("document_name").equal("my_document") &
        wvc.query.Filter.by_property("document_type").equal("xml") &
        wvc.query.Filter.by_property("source").equal("source1")
    )
)

If we now check the total count, we get:

AggregateReturn(properties={}, total_count=1)

1 Like

@Analitiq I was about to confirm that with you, but @DudaNogueira was faster! Thank you so much, @DudaNogueira.

Also, adding to Duda’s response, I would recommend you always refer to the Python client to learn more about available features. For example, in relation to deletion, you can check this out: Python Client Test Collection Filter.

1 Like