3

The documentation on how to update an existing class to add a new property is clear in Weaviate documentation: https://weaviate.io/developers/weaviate/api/rest/schema#add-a-property

However, what if I wanted to remove a property from an existing class. So for example, I have an existing Product class below, and I want to remove the description property - is this possible?

{
  "class": "Product",                    
  "vectorizer": "text2vec-transformers",
  "properties": [
    {
      "name": "product_id",                     
      "description": "Reference ID of the product",              
      "dataType": ["int"],
      "moduleConfig": {                     
        "text2vec-transformers": {
          "skip": true
        }
      }              
    },
    {
      "name": "name",                     
      "description": "Display name of product",              
      "dataType": ["string"],
      "moduleConfig": {                     
        "text2vec-transformers": {
          "skip": false,   
          "vectorizePropertyName": true
        }
      }              
    }, 
    {
      "name": "description",                 
      "description": "The description of the product",          
      "dataType": ["string"],
      "moduleConfig": {                     
        "text2vec-transformers": {
          "skip": false,                     
          "vectorizePropertyName": true
        }
      }             
    }
  ]
}

and we already have existing data so it will be great if I will not go in removing the class and recreating it.

junbetterway
  • 236
  • 3
  • 13

1 Answers1

1

While there is no direct endpoint that will allow you to remove a property from all objects of a class, it's possible to use PATCH with the objects endpoint to replace the the properties of a given object with the initial object except the property you want removed. Using the Python client, this becomes:

def del_prop(uuid: str, prop_name: str, class_name: str) -> None:
    object_data = client.data_object.get(uuid, class_name=class_name)
    if prop_name in object_data["properties"]:
        del object_data["properties"][prop_name]
    client.data_object.replace(object_data["properties"], class_name, uuid)

If you'd like for Weaviate to natively support this feature, please vote for it.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
hsm207
  • 471
  • 2
  • 4