mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-07 11:58:31 +02:00
tiered multitenancy docs
This commit is contained in:
@@ -361,113 +361,7 @@ A clear use-case for this feature is managing a multi-tenant collection, where e
|
||||
|
||||
To enable user-defined sharding, set `sharding_method` to `custom` during collection creation:
|
||||
|
||||
```http
|
||||
PUT /collections/{collection_name}
|
||||
{
|
||||
"shard_number": 1,
|
||||
"sharding_method": "custom"
|
||||
// ... other collection parameters
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.create_collection(
|
||||
collection_name="{collection_name}",
|
||||
shard_number=1,
|
||||
sharding_method=models.ShardingMethod.CUSTOM,
|
||||
# ... other collection parameters
|
||||
)
|
||||
```
|
||||
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
client.createCollection("{collection_name}", {
|
||||
shard_number: 1,
|
||||
sharding_method: "custom",
|
||||
// ... other collection parameters
|
||||
});
|
||||
```
|
||||
|
||||
```rust
|
||||
use qdrant_client::qdrant::{
|
||||
CreateCollectionBuilder, Distance, ShardingMethod, VectorParamsBuilder,
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("{collection_name}")
|
||||
.vectors_config(VectorParamsBuilder::new(300, Distance::Cosine))
|
||||
.shard_number(1)
|
||||
.sharding_method(ShardingMethod::Custom.into()),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
```java
|
||||
import static io.qdrant.client.ShardKeyFactory.shardKey;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Collections.CreateCollection;
|
||||
import io.qdrant.client.grpc.Collections.ShardingMethod;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.createCollectionAsync(
|
||||
CreateCollection.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
// ... other collection parameters
|
||||
.setShardNumber(1)
|
||||
.setShardingMethod(ShardingMethod.Custom)
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "{collection_name}",
|
||||
// ... other collection parameters
|
||||
shardNumber: 1,
|
||||
shardingMethod: ShardingMethod.Custom
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "{collection_name}",
|
||||
// ... other collection parameters
|
||||
ShardNumber: qdrant.PtrOf(uint32(1)),
|
||||
ShardingMethod: qdrant.ShardingMethod_Custom.Enum(),
|
||||
})
|
||||
```
|
||||
{{< code-snippet path="/documentation/headless/snippets/create-collection/with-custom-sharding/" >}}
|
||||
|
||||
In this mode, the `shard_number` means the number of shards per shard key, where points will be distributed evenly. For example, if you have 10 shard keys and a collection config with these settings:
|
||||
|
||||
@@ -487,235 +381,11 @@ For large cardinality keys, it is recommended to use [partition by payload](/doc
|
||||
|
||||
Now you need to create custom shards ([API reference](https://api.qdrant.tech/api-reference/distributed/create-shard-key#request)):
|
||||
|
||||
```http
|
||||
PUT /collections/{collection_name}/shards
|
||||
{
|
||||
"shard_key": "{shard_key}"
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.create_shard_key("{collection_name}", "{shard_key}")
|
||||
```
|
||||
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
client.createShardKey("{collection_name}", {
|
||||
shard_key: "{shard_key}"
|
||||
});
|
||||
```
|
||||
|
||||
```rust
|
||||
use qdrant_client::qdrant::{
|
||||
CreateShardKeyBuilder, CreateShardKeyRequestBuilder
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client
|
||||
.create_shard_key(
|
||||
CreateShardKeyRequestBuilder::new("{collection_name}")
|
||||
.request(CreateShardKeyBuilder::default().shard_key("{shard_key".to_string())),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
```java
|
||||
import static io.qdrant.client.ShardKeyFactory.shardKey;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Collections.CreateShardKey;
|
||||
import io.qdrant.client.grpc.Collections.CreateShardKeyRequest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.createShardKeyAsync(CreateShardKeyRequest.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setRequest(CreateShardKey.newBuilder()
|
||||
.setShardKey(shardKey("{shard_key}"))
|
||||
.build())
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.CreateShardKeyAsync(
|
||||
"{collection_name}",
|
||||
new CreateShardKey { ShardKey = new ShardKey { Keyword = "{shard_key}", } }
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.CreateShardKey(context.Background(), "{collection_name}", &qdrant.CreateShardKey{
|
||||
ShardKey: qdrant.NewShardKey("{shard_key}"),
|
||||
})
|
||||
```
|
||||
{{< code-snippet path="/documentation/headless/snippets/create-shard/create-named-shard/" >}}
|
||||
|
||||
To specify the shard for each point, you need to provide the `shard_key` field in the upsert request:
|
||||
|
||||
```http
|
||||
PUT /collections/{collection_name}/points
|
||||
{
|
||||
"points": [
|
||||
{
|
||||
"id": 1111,
|
||||
"vector": [0.1, 0.2, 0.3]
|
||||
},
|
||||
]
|
||||
"shard_key": "user_1"
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.upsert(
|
||||
collection_name="{collection_name}",
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=1111,
|
||||
vector=[0.1, 0.2, 0.3],
|
||||
),
|
||||
],
|
||||
shard_key_selector="user_1",
|
||||
)
|
||||
```
|
||||
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
client.upsert("{collection_name}", {
|
||||
points: [
|
||||
{
|
||||
id: 1111,
|
||||
vector: [0.1, 0.2, 0.3],
|
||||
},
|
||||
],
|
||||
shard_key: "user_1",
|
||||
});
|
||||
```
|
||||
|
||||
```rust
|
||||
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
|
||||
use qdrant_client::Payload;
|
||||
|
||||
client
|
||||
.upsert_points(
|
||||
UpsertPointsBuilder::new(
|
||||
"{collection_name}",
|
||||
vec![PointStruct::new(
|
||||
111,
|
||||
vec![0.1, 0.2, 0.3],
|
||||
Payload::default(),
|
||||
)],
|
||||
)
|
||||
.shard_key_selector("user_1".to_string()),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ShardKeySelectorFactory.shardKeySelector;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import io.qdrant.client.grpc.Points.UpsertPoints;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client
|
||||
.upsertAsync(
|
||||
UpsertPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPoints(
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(111))
|
||||
.setVectors(vectors(0.1f, 0.2f, 0.3f))
|
||||
.build()))
|
||||
.setShardKeySelector(shardKeySelector("user_1"))
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "{collection_name}",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new() { Id = 111, Vectors = new[] { 0.1f, 0.2f, 0.3f } }
|
||||
},
|
||||
shardKeySelector: new ShardKeySelector { ShardKeys = { new List<ShardKey> { "user_1" } } }
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(111),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3),
|
||||
},
|
||||
},
|
||||
ShardKeySelector: &qdrant.ShardKeySelector{
|
||||
ShardKeys: []*qdrant.ShardKey{
|
||||
qdrant.NewShardKey("user_1"),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
{{< code-snippet path="/documentation/headless/snippets/insert-points/with-custom-shard/" >}}
|
||||
|
||||
<aside role="alert">
|
||||
Using the same point ID across multiple shard keys is <strong>not supported<sup>*</sup></strong> and should be avoided.
|
||||
|
||||
Reference in New Issue
Block a user