Multi-node setup
Replication settings
Currently (from v1.25.0
onwards) a replication factor cannot be changed once it is set.
This is due to the schema consensus algorithm change in v1.25
. This will be improved in future versions.
Configure replication settings, such as async replication and deletion resolution strategy.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- Java
- Go
- cURL
from weaviate.classes.config import Configure, ReplicationDeletionStrategy
client.collections.create(
"Article",
replication_config=Configure.replication(
factor=3,
async_enabled=True, # Enable asynchronous repair
deletion_strategy=ReplicationDeletionStrategy.TIME_BASED_RESOLUTION, # Added in v1.28; Set the deletion conflict resolution strategy
)
)
class_obj = {
"class": "Article",
"replicationConfig": {
"factor": 3,
"asyncEnabled": True,
"deletionStrategy": "TimeBasedResolution" # Available from Weaviate v1.28.0
},
}
client.schema.create_class(class_obj)
import { configure } from 'weaviate-client';
await client.collections.create({
name: 'Article',
replication: configure.replication({
factor: 3,
asyncEnabled: true,
deletionStrategy: 'TimeBasedResolution' // Available from Weaviate v1.28.0
}),
})
// Configure replication settings
Integer replicationFactor = 3;
Boolean asyncEnabled = true;
// Create replication configuration
ReplicationConfig replicationConfig = ReplicationConfig.builder()
.factor(replicationFactor) // factor=3
.asyncEnabled(asyncEnabled) // async_enabled=True
.deletionStrategy(ReplicationConfig.DeletionStrategy.DELETE_ON_CONFLICT)
.build();
// Create the Article collection with replication configuration
WeaviateClass articleClass = WeaviateClass.builder()
.className(collectionName)
.description("Article collection with replication configuration")
.replicationConfig(replicationConfig) // Set the replication config
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleClass)
.run();
articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
ReplicationConfig: &models.ReplicationConfig{
AsyncEnabled: true,
Factor: 3,
DeletionStrategy: models.ReplicationConfigDeletionStrategyTimeBasedResolution,
},
}
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{
"class": "Article",
"properties": [
{
"dataType": [
"string"
],
"description": "Title of the article",
"name": "title"
}
],
"replicationConfig": {
"factor": 3,
"asyncEnabled": true,
"deletionStrategy": "TimeBasedResolution"
}
}' \
http://localhost:8080/v1/schema
Additional information
To use replication factors greater than one, use a multi-node deployment.
For details on the configuration parameters, see the following:
Sharding settings
Configure sharding per collection.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure
client.collections.create(
"Article",
sharding_config=Configure.sharding(
virtual_per_physical=128,
desired_count=1,
desired_virtual_count=128,
)
)
class_obj = {
"class": "Article",
"shardingConfig": {
"virtualPerPhysical": 128,
"desiredCount": 1,
"desiredVirtualCount": 128,
},
}
client.schema.create_class(class_obj)
import { configure } from 'weaviate-client';
await client.collections.create({
name: 'Article',
sharding: configure.sharding({
virtualPerPhysical: 128,
desiredCount: 1,
desiredVirtualCount: 128,
})
})
const classWithSharding = {
class: 'Article',
vectorIndexConfig: {
distance: 'cosine',
},
shardingConfig: {
virtualPerPhysical: 128,
desiredCount: 1,
desiredVirtualCount: 128,
},
};
// Add the class to the schema
result = await client.schema.classCreator().withClass(classWithSharding).do();
// Configure sharding settings
Integer virtualPerPhysical = 128;
Integer desiredCount = 1;
Integer desiredVirtualCount = 128;
// Create sharding configuration
ShardingConfig shardingConfig = ShardingConfig.builder()
.virtualPerPhysical(virtualPerPhysical) // virtual_per_physical=128
.desiredCount(desiredCount) // desired_count=1
.desiredVirtualCount(desiredVirtualCount) // desired_virtual_count=128
.build();
// Create the Article collection with sharding configuration
WeaviateClass articleClass = WeaviateClass.builder()
.className(collectionName)
.description("Article collection with sharding configuration")
.shardingConfig(shardingConfig) // Set the sharding config
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleClass)
.run();
articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
ShardingConfig: sharding.Config{
VirtualPerPhysical: 128,
DesiredCount: 1,
DesiredVirtualCount: 128,
Key: sharding.DefaultKey,
Strategy: sharding.DefaultStrategy,
Function: sharding.DefaultFunction,
},
}
Additional information
For details on the configuration parameters, see the following:
Inspect shards (for a collection)
An index itself can be comprised of multiple shards.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Go
- Java
articles = client.collections.get("Article")
article_shards = articles.config.get_shards()
print(article_shards)
article_shards = client.schema.get_class_shards("Article")
print(article_shards)
let articles = client.collections.get('Article')
const shards = await articles.config.getShards()
console.log(JSON.stringify(shards, null, 2));
const response = await client.schema
.shardsGetter()
.withClassName('Article')
.do();
console.log(JSON.stringify(response, null, 2));
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v5/weaviate"
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
shards, err := client.Schema().
ShardsGetter().
WithClassName("Article").
Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", shards)
}
Result<Shard[]> result = client.schema().shardsGetter()
.withClassName(collectionName)
.run();
Shard[] shards = result.getResult();
if (shards == null || shards.length == 0) {
System.out.println("No shards found in this collection.");
return;
}
// Iterate over each shard and print its status
for (Shard shard : shards) {
System.out.println("Shard name: " + shard.getName());
System.out.println("Shard status: " + shard.getStatus()); // Get shard status (whether it's READY or READONLY)
}
Update shard status
You can manually update a shard to change it's status. For example, update the shard status from READONLY
to READY
after you make other changes.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Go
- Java
articles = client.collections.get("Article")
article_shards = articles.config.update_shards(
status="READY",
shard_names=shard_names # The names (List[str]) of the shard to update (or a shard name)
)
print(article_shards)
article_shards = client.schema.update_class_shard(
"Article",
status="READY",
shard_name="shard-1234"
)
print(article_shards)
let articles = client.collections.get('Article')
const shards = await articles.config.updateShards('READY', 'shard-1234')
console.log(JSON.stringify(shards, null, 2));
const shards = await client.schema.shardUpdater()
.withClassName('Article')
.withShardName('shard-1234')
.withStatus('READY')
.do()
console.log(JSON.stringify(shards, null, 2));
shardStatus, err := client.Schema().ShardUpdater().
WithClassName(myCollectionName). // Set your collection name
WithShardName(shardName). // Set the shard name to update
WithStatus("READY").
Do(ctx)
if err != nil {
// handle error
panic(err)
}
fmt.Printf("%v", shardStatus)
Result<ShardStatus> updateToReadyStatus = client.schema().shardUpdater()
.withClassName(collectionName)
.withShardName(shardName)
.withStatus(ShardStatuses.READY)
.run();
if (updateToReadyStatus.hasErrors()) {
System.out.println(updateToReadyStatus.getError());
return;
}
System.out.println(updateToReadyStatus.getResult());
Further resources
Questions and feedback
If you have any questions or feedback, let us know in the user forum.