Update objects
Weaviate allows partial or complete object updates.
Additional information
- Partial updates use
PATCHrequests to the/v1/objectsREST API endpoint under the hood. - Complete updates use
PUTrequests to the/v1/objectsREST API endpoint under the hood. - Updates that include a
vectorproperty will recalculate the vector embedding (unless all updatedtextproperties are skipped). - To update objects, you must provide the collection name, id and properties to update.
- For multi-tenancy collections, you will also need to specify the tenant name. See Manage data: multi-tenancy operations for details on how.
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.
Update object properties
This operation replaces the entire value of the specified properties only, leaving the unspecified properties. Provide the collection name, the object id, and the properties to update.
If you update the value of a previously vectorized property, Weaviate re-vectorizes the object automatically. This also reindexes the updated object.
However, if you add a new property to your collection definition, Weaviate only vectorizes the new objects. Weaviate doesn't re-vectorize and re-index existing objects when a new property is defined, only when an existing property is updated.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
uuid = "..." # replace with the id of the object you want to update
jeopardy = client.collections.use("JeopardyQuestion")
jeopardy.data.update(
uuid=uuid,
properties={
"points": 100,
}
)
Update object vector
The object vector can also be updated similarly to properties. For named vectors, provide the data as a dictionary/map similarly to the object creation.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
jeopardy = client.collections.use("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.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
jeopardy = client.collections.use("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.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
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.use(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"])
Related pages
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
