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.
Update object properties
Section titled “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.
uuid = "..." # replace with the id of the object you want to updateconst myCollection = client.collections.use('JeopardyQuestion')id := "..." // replace with the id of the object you want to updatejeopardy.data.update(uuid, u -> u.properties(Map.of("points", 100.0)));await jeopardy.Data.Replace( uuid, properties: new { points = 100 });Update object vector
Section titled “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.
jeopardy = client.collections.use("JeopardyQuestion")jeopardy.data.update( uuid=uuid, properties={ "points": 100, }, vector=[0.12345] * 1536)const jeopardy = client.collections.use('JeopardyQuestion')const response = await jeopardy.data.update({ id: 'ed89d9e7-4c9d-4a6a-8d20-095cb0026f54', vectors: Array(1536).fill(0.12345), // new vector value})console.log(response)Coming soon
float[] vector = new float[384];Arrays.fill(vector, 0.12345f);jeopardy.data.update(uuid, u -> u.properties(Map.of("points", 100.0)) .vectors(Vectors.of(vector)));await jeopardy.Data.Replace( uuid, properties: new { points = 100 }, vectors: vector);Replace an entire object
Section titled “Replace an entire object”The entire object can be replaced by providing the collection name, id and the new object.
jeopardy = client.collections.use("JeopardyQuestion")jeopardy.data.replace( uuid=uuid, properties={ "answer": "Replaced", # The other properties will be deleted },)const myCollection = client.collections.use('JeopardyQuestion')id := "..." // replace with the id of the object you want to updatejeopardy.data.replace( uuid, r -> r.properties(Map.of("answer", "Replaced" // The other properties will be deleted )));await jeopardy.Data.Replace( uuid, properties: new { answer = "Replaced" }// The other properties will be deleted);Delete a property
Section titled “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.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 fromasync function deleteProperties(client: WeaviateClient, uuidToUpdate: string, collectionName: string, propNames: string[]) {
const collection = client.collections.use(collectionName);
const objectData = await collection.query.fetchObjectById(uuidToUpdate);
const propertiesToUpdate = objectData?.properties;
if (propertiesToUpdate) {
for (let propName of propNames) {
if (propName in propertiesToUpdate) {
delete propertiesToUpdate[propName];
}
}
let result = await collection.data.replace({
id: uuidToUpdate,
properties: propertiesToUpdate
})
}
}
let id = 'ed89d9e7-4c9d-4a6a-8d20-095cb0026f54'
deleteProperties(client, id, 'JeopardyQuestion', ['answer'])delProps := func(uuid, className string, propNames ...string) (bool, error) {
objs, err := client.Data().ObjectsGetter().WithID(uuid).WithClassName(className).Do(ctx)
if err != nil {
return false, err
}
if objs == nil || len(objs) == 0 {
return false, fmt.Errorf("object with id: %v not found", uuid)
}
if objs[0].Properties == nil {
return false, fmt.Errorf("object with id: %v has no properties", uuid)
}
properties := objs[0].Properties.(map[string]interface{})
for _, propName := range propNames {
delete(properties, propName)
}
err = client.Data().Updater().
WithID(uuid).
WithClassName(className).
WithProperties(properties).
Do(ctx)
return err == nil, err
}private static void delProps(WeaviateClient client, String uuidToUpdate, String collectionName,
List<String> propNames) throws IOException {
CollectionHandle<Map<String, Object>> collection = client.collections.use(collectionName);
// fetch the object to update
Optional<WeaviateObject<Map<String, Object>>> objectDataOpt =
collection.query.fetchObjectById(uuidToUpdate);
if (objectDataOpt.isEmpty()) {
return;
}
Map<String, Object> propertiesToUpdate = new HashMap<>(objectDataOpt.get().properties());
// remove unwanted properties
for (String propName : propNames) {
propertiesToUpdate.remove(propName);
}
// replace the properties
collection.data.replace(uuidToUpdate, r -> r.properties(propertiesToUpdate));
}private static async Task DelProps(
WeaviateClient client,
Guid uuidToUpdate,
string collectionName,
IEnumerable<string> propNames
)
{
var collection = client.Collections.Use(collectionName);
// fetch the object to update
var objectData = await collection.Query.FetchObjectByID(uuidToUpdate);
if (objectData?.Properties is not IDictionary<string, object> propertiesToUpdate)
{
return;
}
// remove unwanted properties
foreach (var propName in propNames)
{
propertiesToUpdate.Remove(propName);
}
// replace the properties
await collection.Data.Replace(uuidToUpdate, propertiesToUpdate);
}Related pages
Section titled “Related pages”Questions and feedback
Section titled “Questions and feedback”Have a question or feedback? Here's how to reach us.