Update objects
Weaviate allows partial or complete object updates.
Additional information
Partial updates use
PATCH
requests to the/v1/objects
REST API endpoint under the hood.Complete updates use
PUT
requests to the/v1/objects
REST API endpoint under the hood.Updates that include a
vector
property will recalculate the vector embedding (unless all updatedtext
properties 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.
Collection (class) Name in Object CRUD OperationsCollections 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 Weaviatev2.0.0
.Starting in
v1.20
, you can have multi-tenant datasets. Whenmulti-tenancy
is enabled, the tenant name is required.Always include the collection name, and, when enabled, the tenant name.
Update object properties
To update a collection property, 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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
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,
}
)
uuid = "..." # replace with the id of the object you want to update
client.data_object.update(
uuid=uuid,
class_name="JeopardyQuestion",
data_object={
"points": 100,
},
)
const myCollection = client.collections.get('JeopardyQuestion')
const response = await myCollection.data.update({
id: 'ed89d9e7-4c9d-4a6a-8d20-095cb0026f54',
properties: {
'points': 100,
},
})
console.log(response)
let id = '...'; // replace with the id of the object you want to update
await client.data
.merger() // merges properties into the object
.withId(id).withClassName('JeopardyQuestion')
.withProperties({
points: 100,
})
.do();
String id = "..."; // replace with the id of the object you want to update
client.data().updater()
.withMerge() // merges properties into the object
.withID(id)
.withClassName("JeopardyQuestion")
.withProperties(new HashMap<String, Object>() {{
put("points", 100);
}})
.run();
id := "..." // replace with the id of the object you want to update
client.Data().Updater().
WithMerge(). // merges properties into the object
WithID(id).
WithClassName("JeopardyQuestion").
WithProperties(map[string]interface{}{
"points": 100,
}).
Do(ctx)
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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
jeopardy = client.collections.get("JeopardyQuestion")
jeopardy.data.update(
uuid=uuid,
properties={
"points": 100,
},
vector=[0.12345] * 1536
)
client.data_object.update(
uuid=uuid,
class_name="JeopardyQuestion",
data_object={
"points": 100,
},
vector=[0.12345] * 1536
)
const jeopardy = client.collections.get('Jeopardy')
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 (vote for the feature request)
Coming soon
Coming soon
Replace an entire object
The entire object can be replaced by providing the collection name, id and the new object.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
jeopardy = client.collections.get("JeopardyQuestion")
jeopardy.data.replace(
uuid=uuid,
properties={
"answer": "Replaced",
# The other properties will be deleted
},
)
uuid = "..." # the id of the object you want to replace
client.data_object.replace(
uuid=uuid,
class_name="JeopardyQuestion",
data_object={
"answer": "Replaced",
# The other properties will be deleted
},
)
const myCollection = client.collections.get('JeopardyQuestion')
const response = await myCollection.data.replace({
id: 'ed89d9e7-4c9d-4a6a-8d20-095cb0026f54',
properties: {
'answer': 'Replaced',
// The other properties will be deleted
},
})
console.log(response)
id = '...'; // the id of the object you want to replace
await client.data
.updater() // replaces the entire object
.withId(id).withClassName('JeopardyQuestion')
.withProperties({
answer: 'Replaced',
// The other properties will be deleted
})
.do();
String id = "..."; // replace with the id of the object you want to update
client.data().updater() // replaces the entire object
.withID(id)
.withClassName("JeopardyQuestion")
.withProperties(new HashMap<String, Object>() {{
put("answer", "Replaced");
// The other properties will be deleted
}})
.run();
id := "..." // replace with the id of the object you want to update
client.Data().Updater(). // replaces the entire object
WithID(id).
WithClassName("JeopardyQuestion").
WithProperties(map[string]interface{}{
"answer": "Replaced",
// The other properties will be deleted
}).
Do(ctx)
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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
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"])
from typing import List
from weaviate import Client
def del_props(client: Client, uuid: str, class_name: str, prop_names: List[str]) -> None:
object_data = client.data_object.get(uuid, class_name=class_name)
for prop_name in prop_names:
if prop_name in object_data["properties"]:
del object_data["properties"][prop_name]
client.data_object.replace(object_data["properties"], class_name, uuid)
uuid = "..." # replace with the id of the object you want to delete properties from
del_props(client, uuid, "JeopardyQuestion", ["answer"])
async function deleteProperties(client: WeaviateClient, uuidToUpdate: string, collectionName: string, propNames: string[]) {
const collection = client.collections.get(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];
}
}
result = await collection.data.replace({
id: uuidToUpdate,
properties: propertiesToUpdate
})
}
}
let id = 'ed89d9e7-4c9d-4a6a-8d20-095cb0026f54'
deleteProperties(client, id, 'JeopardyQuestion', ['answer'])
async function delProps(uuid: string, className: string, propNames: string[]) {
const objectData = await client.data.getterById().withId(uuid).withClassName(className).do();
for (const propName of propNames)
if (propName in objectData.properties)
delete objectData.properties[propName];
// Replace the object
return await client.data
.updater()
.withId(uuid).withClassName(className)
.withProperties(objectData.properties)
.do();
}
id = '...'; // replace with the id of the object you want to delete properties from
await delProps(id, 'JeopardyQuestion', ['answer']);
private boolean delProps(String uuid, String className, String ...propNames) {
Result<List<WeaviateObject>> result = client.data().objectsGetter().withID(uuid).withClassName(className).run();
if (!result.hasErrors() && result.getResult() != null) {
WeaviateObject objectData = result.getResult().get(0);
for (String propName: propNames) {
objectData.getProperties().remove(propName);
}
// Replace the object
Result<Boolean> update = client.data().updater()
.withID(uuid)
.withClassName(className)
.withProperties(objectData.getProperties())
.run();
return update.getResult() != null && update.getResult().equals(true);
}
return false;
}
String id = "..."; // replace with the id of the object you want to update
boolean isUpdated = delProps(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
}
id := "..." // replace with the id of the object you want to update
isUpdated, err := delProps(id, "JeopardyQuestion", "answer")
Related pages
Questions and feedback
If you have any questions or feedback, let us know in the user forum.