Skip to main content

Update objects

Weaviate allows partial or complete object updates.

Additional information

Update object properties

Update one or more properties by providing the collection name, id and properties to update.

    uuid = "..."  # replace with the id of the object you want to update

jeopardy = client.collections.get("JeopardyQuestion")
jeopardy.data.update(
uuid=uuid,
properties={
"points": 100,
}
)

Update object vector

The object vector can also be updated similarly to properties.

    jeopardy = client.collections.get("JeopardyQuestion")
jeopardy.data.update(
uuid=uuid,
properties={
"points": 100,
},
vector=[0.12345] * 1536
)

Replace an entire object

The entire object can be replaced by providing the collection name, id and the new object.

    jeopardy = client.collections.get("JeopardyQuestion")
jeopardy.data.replace(
uuid=uuid,
properties={
"answer": "Replaced",
# The other properties will be deleted
},
)

Delete a property

Deleting or updating properties in the collection definition is not yet supported.

At object level, you can replace the object with a copy that has those properties deleted, or set to "" for text properties.

    from typing import List
from weaviate import WeaviateClient

def del_props(client: WeaviateClient, uuid_to_update: str, collection_name: str, prop_names: List[str]) -> None:
collection = client.collections.get(collection_name)

# fetch the object to update
object_data = collection.query.fetch_object_by_id(uuid_to_update)
properties_to_update = object_data.properties

# remove unwanted properties
for prop_name in prop_names:
if prop_name in properties_to_update:
del properties_to_update[prop_name]

# replace the properties
collection.data.replace(
uuid=uuid_to_update,
properties=properties_to_update
)


uuid = "..." # replace with the id of the object you want to delete properties from
del_props(client, uuid, "JeopardyQuestion", ["answer"])