REST - /v1/batch
For client examples, see this section.
Batch create objects
For sending data objects to Weaviate in bulk.
Performance
For best performance, we recommend using batching for insertion and deletion. Also consider that:
- The vectorization module/tool may be acting as a bottleneck.
- Avoid duplicate vectors for multiple data objects.
- Object-level errors may occur even if the batch request is successful.
- If your import slows down after a particular number of objects (e.g. 2M), check to see if the
vectorCacheMaxObjects
in your schema is larger than the number of objects. Also, see this example.
Method and URL
POST /v1/batch/objects[?consistency_level=ONE|QUORUM|ALL]
Parameters
The URL supports an optional consistency level query parameter:
Name | Location | Type | Description |
---|---|---|---|
consistency_level | query param | string | Optional consistency level: ONE , QUORUM (default) or ALL . |
The POST body requires the following field:
Name | Type | Required | Description |
---|---|---|---|
objects | array of data objects | yes | Array of objects |
Example request
- Python (v4)
- Python (v3)
- JavaScript/TypeScript
- Go
- Java
- Curl
import weaviate
import weaviate.classes as wvc
from weaviate.util import generate_uuid5
client = weaviate.connect_to_local()
try:
first_object_props = {"name": "Jane Doe"}
first_object_uuid = generate_uuid5(first_object_props)
with client.batch.fixed_size( # client.batch.dynamic() or client.batch.rate_limit() also possible
batch_size=100,
consistency_level=wvc.ConsistencyLevel.QUORUM
) as batch:
# Add objects to the batch, e.g.
batch.add_object(
collection="Author",
properties=first_object_props,
uuid=first_object_uuid,
# tenant="tenantA" # Optional; specify the tenant in multi-tenancy collections
)
finally:
client.close()
import weaviate
client = weaviate.Client("http://localhost:8080")
first_object_props = {
"name": "Jane Doe",
"writesFor": [{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"
}]
}
second_object_props = {
"name": "John Doe",
"writesFor": [{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"
}]
}
# Python client specific configurations can be set with `client.batch.configure`
# the settings can be applied to both `objects` AND `references`.
# You have to only set them once.
client.batch.configure(
# `batch_size` takes an `int` value to enable auto-batching
# (`None` is used for manual batching)
batch_size=100,
# dynamically update the `batch_size` based on import speed
dynamic=False,
# `timeout_retries` takes an `int` value to retry on time outs
timeout_retries=3,
# checks for batch-item creation errors
# this is the default in weaviate-client >= 3.6.0
callback=weaviate.util.check_batch_result,
consistency_level=weaviate.data.replication.ConsistencyLevel.ALL, # default QUORUM
)
with client.batch as batch:
# Add object without a custom vector.
# When using vectorization modules this can be used
# or when you don't want to set a vector
batch.add_data_object(
data_object=first_object_props,
class_name="Author",
uuid="36ddd591-2dee-4e7e-a3cc-eb86d30a4303",
# tenant="tenantA", # Optional; specify the tenant in multi-tenancy collections
)
# Add object with a custom vector
batch.add_data_object(
data_object=second_object_props,
class_name="Author",
uuid="36ddd591-2dee-4e7e-a3cc-eb86d30a4304",
vector=[0.1, 0.2, 0.3],
# tenant="tenantA", # Optional; specify the tenant in multi-tenancy collections
)
import weaviate from 'weaviate-ts-client';
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
const toImport = [{
class: 'Author',
id: '36ddd591-2dee-4e7e-a3cc-eb86d30a4303',
properties: {
name: 'Jane Doe',
writesFor: [{
beacon: 'weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80',
}],
},
},
{
class: 'Author',
id: '36ddd591-2dee-4e7e-a3cc-eb86d30a4304',
properties: {
name: 'John Doe',
writesFor: [{
beacon: 'weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80',
}],
},
}];
const response = await client.batch
.objectsBatcher()
.withObject(toImport[0])
.withObject(toImport[1])
.withConsistencyLevel('ALL') // default QUORUM
// .withTenant('tenantA') // Optional; specify the tenant in multi-tenancy collections
.do();
console.log(JSON.stringify(response, null, 2));
/* The following is also possible:
const toImport = [
client.data
.creator()
.withClassName('Author')
.withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303')
.withProperties({
name: 'Jane Doe',
writesFor: [{
beacon: 'weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80',
}],
})
.payload(), // note the .payload(), not .do()!
client.data
.creator()
.withClassName('Author')
.withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4304')
.withProperties({
name: 'John Doe',
writesFor: [{
beacon: 'weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80',
}],
})
.payload(), // note the .payload(), not .do()!
];
const response = await client.batch
.objectsBatcher()
.withObject(toImport[0])
.withObject(toImport[1])
.withConsistencyLevel('ALL') // default QUORUM
// .withTenant('tenantA') // Optional; specify the tenant in multi-tenancy collections
.do();
console.log(JSON.stringify(response, null, 2));
*/
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate/entities/models"
"github.com/weaviate/weaviate-go-client/v4/weaviate/data/replication" // for consistency levels
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
objects := []*models.Object{
{
Class: "Author",
ID: "36ddd591-2dee-4e7e-a3cc-eb86d30a4303",
Properties: map[string]interface{}{
"name": "Jane Doe",
"writesFor": map[string]string{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80",
},
},
},
{
Class: "Author",
ID: "36ddd591-2dee-4e7e-a3cc-eb86d30a4304",
Properties: map[string]interface{}{
"name": "John Doe",
"writesFor": map[string]string{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80",
},
},
},
}
result, err := client.Batch().ObjectsBatcher().
WithObject(objects[0]).
WithObject(objects[1]).
WithConsistencyLevel(replication.ConsistencyLevel.ALL). // default QUORUM
// WithTenant("tenantA"). // Optional; specify the tenant in multi-tenancy collections
Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", result)
}
package io.weaviate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.batch.model.ObjectGetResponse;
import io.weaviate.client.v1.data.model.WeaviateObject;
import io.weaviate.client.v1.data.replication.model.ConsistencyLevel;
public class App {
public static void main(String[] args) {
Config config = new Config("http", "localhost:8080");
WeaviateClient client = new WeaviateClient(config);
List<WeaviateObject> objects = new ArrayList() {
{
add(
WeaviateObject.builder()
.className("Author")
.id("36ddd591-2dee-4e7e-a3cc-eb86d30a4303")
.properties(new HashMap() {
{
put("name", "Jane Doe");
put("writesFor", new HashMap() {
{
put("beacon", "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80");
}
});
}
})
// .withTenant("tenantA") // Optional; specify the tenant in multi-tenancy collections
.build()
);
add(
WeaviateObject.builder()
.className("Author")
.id("36ddd591-2dee-4e7e-a3cc-eb86d30a4304")
.properties(new HashMap() {
{
put("name", "John Doe");
put("writesFor", new HashMap() {
{
put("beacon", "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80");
}
});
}
})
// .withTenant("tenantA") // Optional; specify the tenant in multi-tenancy collections
.build()
);
}
};
Result<ObjectGetResponse[]> result = client.batch().objectsBatcher()
.withObject(objects.get(0))
.withObject(objects.get(1))
.withConsistencyLevel(ConsistencyLevel.ALL) // default QUORUM
.run();
if (result.hasErrors()) {
System.out.println(result.getError());
return;
}
System.out.println(result.getResult());
}
}
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{
"objects": [{
"class": "Author",
"id": "36ddd591-2dee-4e7e-a3cc-eb86d30a4303",
"properties": {
"name": "Jane Doe",
"writesFor": [{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"
}]
},
}, {
"class": "Author",
"id": "36ddd591-2dee-4e7e-a3cc-eb86d30a4304",
"properties": {
"name": "John Doe",
"writesFor": [{
"beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"
}]
}
}]
}' \
http://localhost:8080/v1/batch/objects?consistency_level=ALL
Batch create references
For batch adding cross-references between data objects in bulk.
Method and URL
POST /v1/batch/references
Parameters
The URL supports an optional consistency level query parameter:
Name | Location | Type | Description |
---|---|---|---|
consistency_level | query param | string | Optional consistency level: ONE , QUORUM (default) or ALL . |
The POST body is an array of elements with the following fields:
Name | Type | Required | Description |
---|---|---|---|
from | Weaviate Beacon (long-form) | yes | The beacon, with the cross-reference property name at the end: weaviate://localhost/{CollectionName}/{id}/{crefPropertyName} |
to | Weaviate Beacon (regular) | yes | The beacon, formatted as weaviate://localhost/{CollectionName}/{id} |
For backward compatibility, you can omit the collection name in the
short-form beacon format that is used for to
. You can specify it as
weaviate://localhost/{id}
. This is, however, considered deprecated and will be
removed with a future release, as duplicate IDs across collections could mean that
this beacon is not uniquely identifiable. For the long-form beacon - used as part
of from
- you always need to specify the full beacon, including the reference
property name.
Example request
- Python (v4)
- Python (v3)
- JavaScript/TypeScript
- Go
- Java
- Curl
import weaviate
import weaviate.classes as wvc
from weaviate.util import generate_uuid5
client = weaviate.connect_to_local()
try:
first_object_props = {"name": "Jane Doe"}
first_object_uuid = generate_uuid5(first_object_props)
with client.batch.fixed_size( # client.batch.dynamic() or client.batch.rate_limit(requests_per_minute=<N>) also possible
batch_size=100,
consistency_level=wvc.ConsistencyLevel.QUORUM
) as batch:
# Add references to the batch, e.g.
batch.add_reference(
from_collection="Author",
from_property="writesFor",
from_uuid=first_object_uuid,
to=first_target_uuid,
# tenant="tenantA" # Optional; specify the tenant in multi-tenancy collections
)
finally:
client.close()
import weaviate
client = weaviate.Client("http://localhost:8080")
# Python client specific configurations can be set with `client.batch.configure`
# the settings can be applied to both `objects` AND `references`.
# You have to only set them once.
client.batch.configure(
# `batch_size` takes an `int` value to enable auto-batching
# (`None` is used for manual batching)
batch_size=100,
# dynamically update the `batch_size` based on import speed
dynamic=False,
# `timeout_retries` takes an `int` value to retry on time outs
timeout_retries=3,
# checks for batch-item creation errors
# this is the default in weaviate-client >= 3.6.0
callback=weaviate.util.check_batch_result,
consistency_level=weaviate.data.replication.ConsistencyLevel.ALL, # default QUORUM
)
with client.batch as batch:
# Format for batching is as follows:
# batch.add_reference(
# from_object_uuid=<from_object_uuid>,
# from_object_class_name=<from_object_class_name>,
# from_property_name=<from_property_name>
# to_object_uuid=<to_object_uuid>,
# to_object_class_name=<to_object_class_name>,
# tenant=<TenantName> # Only required for multi-tenancy
# )
batch.add_reference(
from_object_uuid="36ddd591-2dee-4e7e-a3cc-eb86d30a4303",
from_object_class_name="Author",
from_property_name="wroteArticles",
to_object_uuid="6bb06a43-e7f0-393e-9ecf-3c0f4e129064",
to_object_class_name="Article",
# tenant="tenantA", # Optional; specify the tenant in multi-tenancy collections
)
batch.add_reference(
from_object_uuid="36ddd591-2dee-4e7e-a3cc-eb86d30a4303",
from_object_class_name="Author",
from_property_name="wroteArticles",
to_object_uuid="b72912b9-e5d7-304e-a654-66dc63c55b32",
to_object_class_name="Article",
# tenant="tenantA", # Optional; specify the tenant in multi-tenancy collections
)
import weaviate from 'weaviate-ts-client';
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
const response = await client.batch
.referencesBatcher()
.withReference({
from: 'weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles',
to: 'weaviate://localhost/Article/6bb06a43-e7f0-393e-9ecf-3c0f4e129064',
// prior to v1.14 omit the class name as part of the 'to' beacon and specify it as weaviate://localhost/<id>
})
.withReference({
from: 'weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles',
to: 'weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32',
// prior to v1.14 omit the class name as part of the 'to' beacon and specify it as weaviate://localhost/<id>
})
.withReference({
from: 'weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4304/wroteArticles',
to: 'weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32',
// prior to v1.14 omit the class name as part of the 'to' beacon and specify it as weaviate://localhost/<id>
})
.withConsistencyLevel('ALL') // default QUORUM
// .withTenant('tenantA') // Optional; specify the tenant in multi-tenancy collections
.do();
console.log(JSON.stringify(response, null, 2));
/* This is also possible with a builder pattern:
const response = await client.batch
.referencesBatcher()
.withReference(
client.batch
.referencePayloadBuilder()
.withFromClassName('Author')
.withFromRefProp('wroteArticles')
.withFromId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303')
.withToClassName('Article') // prior to v1.14 omit .withToClassName()
.withToId('6bb06a43-e7f0-393e-9ecf-3c0f4e129064')
.payload()
)
.withReference(
client.batch
.referencePayloadBuilder()
.withFromClassName('Author')
.withFromRefProp('wroteArticles')
.withFromId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303')
.withToClassName('Article') // prior to v1.14 omit .withToClassName()
.withToId('b72912b9-e5d7-304e-a654-66dc63c55b32')
.payload()
)
.withReference(
client.batch
.referencePayloadBuilder()
.withFromClassName('Author')
.withFromRefProp('wroteArticles')
.withFromId('36ddd591-2dee-4e7e-a3cc-eb86d30a4304')
.withToClassName('Article') // prior to v1.14 omit .withToClassName()
.withToId('b72912b9-e5d7-304e-a654-66dc63c55b32')
.payload()
)
.withConsistencyLevel('ALL') // default QUORUM
// .withTenant('tenantA') // Optional; specify the tenant in multi-tenancy collections
.do();
console.log(JSON.stringify(response, null, 2));
*/
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate/entities/models"
"github.com/weaviate/weaviate-go-client/v4/weaviate/data/replication" // for consistency levels
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
ref := []*models.BatchReference{
{
From: "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles",
To: "weaviate://localhost/Article/6bb06a43-e7f0-393e-9ecf-3c0f4e129064",
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
},
{
From: "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles",
To: "weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32",
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
},
{
From: "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4304/wroteArticles",
To: "weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32",
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
},
}
result, err := client.Batch().ReferencesBatcher().
WithReference(ref[0]).
WithReference(ref[1]).
WithReference(ref[2]).
WithConsistencyLevel(replication.ConsistencyLevel.ALL). // default QUORUM
// WithTenant("tenantA"). // Optional; specify the tenant in multi-tenancy collections
Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", result)
}
package io.weaviate;
import java.util.ArrayList;
import java.util.List;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.batch.model.BatchReference;
import io.weaviate.client.v1.batch.model.BatchReferenceResponse;
import io.weaviate.client.v1.data.replication.model.ConsistencyLevel;
public class App {
public static void main(String[] args) {
Config config = new Config("http", "localhost:8080");
WeaviateClient client = new WeaviateClient(config);
List<BatchReference> refs = new ArrayList() {
{
add(
BatchReference.builder()
.from("weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles")
.to("weaviate://localhost/Article/6bb06a43-e7f0-393e-9ecf-3c0f4e129064")
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
.build()
);
add(
BatchReference.builder()
.from("weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles")
.to("weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32")
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
.build()
);
add(
BatchReference.builder()
.from("weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4304/wroteArticles")
.to("weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32")
// prior to v1.14 omit the class name as part of the "to" beacon and specify it as weaviate://localhost/<id>
.build()
);
}
};
Result<BatchReferenceResponse[]> result = client.batch().referencesBatcher()
.withReference(refs.get(0))
.withReference(refs.get(1))
.withReference(refs.get(2))
.withConsistencyLevel(ConsistencyLevel.ALL) // default QUORUM
// .withTenant("tenantA") // Optional; specify the tenant in multi-tenancy collections
.run();
if (result.hasErrors()) {
System.out.println(result.getError());
return;
}
System.out.println(result.getResult());
}
}
# Note that for this query to work with Weaviate versions older than v1.14 you
# need to omit the class name in the "to" beacon and specify it as
# weaviate://localhost/<id>. The long-form beacon used in "from" is unchanged.
curl \
-X POST \
-H "Content-Type: application/json" \
-d '[{
"from": "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles",
"to": "weaviate://localhost/Article/6bb06a43-e7f0-393e-9ecf-3c0f4e129064"
}, {
"from": "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4303/wroteArticles",
"to": "weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32"
}, {
"from": "weaviate://localhost/Author/36ddd591-2dee-4e7e-a3cc-eb86d30a4304/wroteArticles",
"to": "weaviate://localhost/Article/b72912b9-e5d7-304e-a654-66dc63c55b32"
}]' \
http://localhost:8080/v1/batch/references?consistency_level=ALL
Batch delete
You can use the HTTP verb DELETE
on the /v1/batch/objects
endpoint to delete all objects that match a particular expression.
The request body takes a single where Filter and will delete all objects matched. It also returns the number of matched objects and potential errors. Note that there is a limit to the number of objects to be deleted at once using this filter.
Maximum number of deletes per query
There is an upper limit (QUERY_MAXIMUM_RESULTS
) to how many objects can be deleted using a single query. This protects against unexpected memory surges and very-long-running requests which would be prone to client-side timeouts or network interruptions.
Objects are deleted in the same order that they would be returned in an equivalent Get query. To delete more objects than the limit, run the same query multiple times until no objects are matched anymore.
The default QUERY_MAXIMUM_RESULTS
value is 10,000. This may be configurable, e.g. in the environment variables.
Dry-run before deletion
Set the dry-run option to show which objects would be matched using the specified filter without deleting any objects. Depending on the configured verbosity, you will either receive a count of affected objects, or a list of IDs.
Method and URL
DELETE /v1/batch/objects[?consistency_level=ONE|QUORUM|ALL]
Parameters
The URL supports an optional consistency level query parameter:
Name | Location | Type | Description |
---|---|---|---|
consistency_level | query param | string | Optional consistency level: ONE , QUORUM (default) or ALL . |
The body requires the following fields:
Name | Type | Required | Description |
---|---|---|---|
match | object | yes | Object outlining how to find the objects to be deleted (see example below) |
output | string | no | Optional verbosity level, minimal (default) or verbose |
dryRun | bool | no | If true, objects will not be deleted yet, but merely listed. Defaults to false . |
A request body in detail
{
"match": {
"class": "<CollectionName>", # required
"where": { /* where filter object */ }, # required
},
"output": "<output verbosity>", # Optional, one of "minimal" or "verbose". Defaults to "minimal".
"dryRun": <bool> # Optional. If true, objects will not be deleted yet, but merely listed. Defaults to "false".
}
Possible values for output
:
Value | Effect |
---|---|
minimal | The result only includes counts. Information about objects is omitted if the deletes were successful. Only if an error occurred, will the object be described. |
verbose | The result lists all affected objects with their ID and deletion status, including both successful and unsuccessful deletes. |
A response body in detail
{
"match": {
"class": "<CollectionName>", # matches the request
"where": { /* where filter object */ }, # matches the request
},
"output": "<output verbosity>", # matches the request
"dryRun": <bool>,
"results": {
"matches": "<int>", # how many objects were matched by the filter
"limit": "<int>", # the most amount of objects that can be deleted in a single query, matches QUERY_MAXIMUM_RESULTS
"successful": "<int>", # how many objects were successfully deleted in this round
"failed": "<int>", # how many objects should have been deleted but could not be deleted
"objects": [{ # one JSON object per weaviate object
"id": "<id>", # this successfully deleted object would be omitted with output=minimal
"status": "SUCCESS", # possible status values are: "SUCCESS", "FAILED", "DRYRUN"
"error": null
}, {
"id": "<id>", # this error object will always be listed, even with output=minimal
"status": "FAILED",
"errors": {
"error": [{
"message": "<error-string>"
}]
}
}]
}
}
Example request
- Python (v4)
- Python (v3)
- JavaScript/TypeScript
- Go
- Java
- Curl
import weaviate
import weaviate.classes as wvc
from weaviate.util import generate_uuid5
client = weaviate.connect_to_local()
try:
authors = client.collections.get("Author")
# authors = authors.with_tenant("tenantA") # Optional; specify the tenant in multi-tenancy collections
# authors = authors.with_consistency_level(wvc.config.ConsistencyLevel.QUORUM) # Optional; specify the consistency level
response = authors.data.delete_many(
where=wvc.query.Filter.by_property("name").equal("Jane Doe"),
verbose=True,
dry_run=False,
)
print(f"Matched {response.matches} objects.")
print(f"Deleted {response.successful} objects.")
finally:
client.close()
import weaviate
client = weaviate.Client("http://localhost:8080")
# Optionally set the consistency level
client.batch.consistency_level = (
weaviate.data.replication.ConsistencyLevel.ALL # default QUORUM
)
result = client.batch.delete_objects(
class_name="Author",
where={"operator": "Equal", "path": ["name"], "valueText": "Jane"}, # same where operator as in the GraphQL API
output="verbose",
dry_run=False,
# tenant="tenantA" # Optional; specify the tenant in multi-tenancy collections
)
print(result)
import weaviate from 'weaviate-ts-client';
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
const response = await client.batch
.objectsBatchDeleter()
.withClassName('Article')
.withOutput('verbose')
.withDryRun(false)
.withWhere({
operator: 'GreaterThan',
path: ['_creationTimeUnix'],
valueText: '1651514874263',
})
.withConsistencyLevel('ALL') // default QUORUM
// .withTenant('tenantA') // Optional; specify the tenant in multi-tenancy collections
.do();
console.log(JSON.stringify(response, null, 2));
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/filters"
"github.com/weaviate/weaviate-go-client/v4/weaviate/data/replication" // for consistency levels
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
where := filters.Where().
WithOperator(filters.GreaterThan).
WithPath([]string{"_creationTimeUnix"}).
WithValueString("1651514874263")
result, err := client.Batch().ObjectsBatchDeleter().
WithClassName("Article").
WithOutput("verbose").
WithDryRun(false).
WithWhere(where).
WithConsistencyLevel(replication.ConsistencyLevel.ALL). // default QUORUM
// WithTenant("tenantA"). // Optional; specify the tenant in multi-tenancy collections
Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", result)
}
package io.weaviate;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.batch.model.BatchDeleteOutput;
import io.weaviate.client.v1.batch.model.BatchDeleteResponse;
import io.weaviate.client.v1.filters.Operator;
import io.weaviate.client.v1.filters.WhereFilter;
import io.weaviate.client.v1.data.replication.model.ConsistencyLevel;
public class App {
public static void main(String[] args) {
Config config = new Config("http", "localhost:8080");
WeaviateClient client = new WeaviateClient(config);
WhereFilter where = WhereFilter.builder()
.operator(Operator.GreaterThan)
.path(new String[]{ "_creationTimeUnix" })
.valueText("1651514874263")
.build();
Result<BatchDeleteResponse> result = client.batch().objectsBatchDeleter()
.withClassName("Article")
.withOutput(BatchDeleteOutput.VERBOSE)
.withDryRun(false)
.withWhere(where)
.withConsistencyLevel(ConsistencyLevel.ALL) // default QUORUM
// .withTenant("tenantA") // Optional; specify the tenant in multi-tenancy collections
.run();
if (result.hasErrors()) {
System.out.println(result.getError());
return;
}
System.out.println(result.getResult());
}
}
curl \
-X DELETE \
-H "Content-Type: application/json" \
-d '{
"match": {
"class": "Author",
"where": {
"valueText": "Jane",
"path": ["name"],
"operator": "Equal"
}
},
"output": "verbose",
"dryRun": false
}' \
http://localhost:8080/v1/batch/objects?consistency_level=ALL
Multi-tenancy
You can use batching in collections with multi-tenancy is enabled. For example, batch creation of objects works similarly to single object creation, by passing the tenant
parameter in the object body.
Error handling
You can check if an error occurred, and of what kind.
Errors may occur on a batch request, for example when the connection to Weaviate is lost or when there is a mistake in any data objects.
A batch request will always return an HTTP 200
status code when the batch request was successful. This indicates that:
- The batch was successfully sent to Weaviate.
- There were no issues with the connection or processing of the batch.
- The request was not malformed (
4xx
status code).
However, a 200
status code does not guarantee that each batch item has been added/created. For example, adding an object to the batch that is in conflict with the schema (for example a non-existing collection name) will cause an error.
Accordingly, we recommend you check the response body for errors.
Python client library
The Weaviate Python client library provides additional functionalities for batch imports. For example, the latest Python client library supports various batching modes, as well as improved error handling.
Please refer to the client documentation for more detail.
The v4
Python client's batching is handled via the gRPC API.
Please refer to the client documentation for client-specific discussions.
Notes
In the beacon format, you need to always use localhost
as the host,
rather than the actual hostname. localhost
refers to the fact that the
beacon's target is on the same Weaviate instance, as opposed to a foreign
instance.
Questions and feedback
If you have any questions or feedback, let us know in our user forum.