Search code examples
pythonvectorweaviate

Is there a delete by query in Weaviate?


I would like to delete records by query. The documentation does not mention this. I woudl like to do similar to:

where_filter = {
    "path": ["hash"],
    "operator": "Equal",
    "valueText": hash,
}

return (
    client.query
        .get("Collection", ["question", "answer", 'file', 'hash'])
        .with_where(where_filter)
        .do()
)

but instead of querying I would like to delete the records.

Is it event possible in Weaviate. Could not find an answer in the internet.


Solution

  • Yes, it is possible. Look at the docs for batch delete. For example:

    import weaviate
    
    client = weaviate.Client("http://localhost:8080")
    
    # Optionally set the consistency level
    client.batch.consistency_level = weaviate.data.replication.ConsistencyLevel.ALL  # default QUORUM
    result = client.batch.delete_objects(
      class_name="Author",
      # same where operator as in the GraphQL API
      where={
        "operator": "Equal",
        "path": ["name"],
        "valueText": "Jane"
      },
      output="verbose",
      dry_run=False
    )
    
    print(result)