mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-28 15:38:33 +02:00
docs: New Go SDK snippets (#1149)
This commit is contained in:
@@ -270,6 +270,28 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 300,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
ShardNumber: qdrant.PtrOf(uint32(6)),
|
||||
})
|
||||
```
|
||||
|
||||
To ensure all nodes in your cluster are evenly utilized, the number of shards must be a multiple of the number of nodes you are currently running in your cluster.
|
||||
|
||||
> Aside: Advanced use cases such as multitenancy may require an uneven distribution of shards. See [Multitenancy](/articles/multitenancy/).
|
||||
@@ -440,6 +462,30 @@ await client.CreateShardKeyAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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(),
|
||||
})
|
||||
|
||||
client.CreateShardKey(context.Background(), "{collection_name}", &qdrant.CreateShardKey{
|
||||
ShardKey: qdrant.NewShardKey("{shard_key}"),
|
||||
})
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```json
|
||||
@@ -562,10 +608,38 @@ await client.UpsertAsync(
|
||||
{
|
||||
new() { Id = 111, Vectors = new[] { 0.1f, 0.2f, 0.3f } }
|
||||
},
|
||||
shardKeySelector: new ShardKeySelector { ShardKeys = { new List<ShardKey> { "user_id" } } }
|
||||
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"),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
<aside role="alert">
|
||||
Using the same point ID across multiple shard keys is <strong>not supported<sup>*</sup></strong> and should be avoided.
|
||||
</aside>
|
||||
@@ -791,6 +865,29 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 300,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
ShardNumber: qdrant.PtrOf(uint32(6)),
|
||||
ReplicationFactor: qdrant.PtrOf(uint32(2)),
|
||||
})
|
||||
```
|
||||
|
||||
This code sample creates a collection with a total of 6 logical shards backed by a total of 12 physical shards.
|
||||
|
||||
Since a replication factor of "2" would require twice as much storage space, it is advised to make sure the hardware can host the additional shard replicas beforehand.
|
||||
@@ -1037,6 +1134,30 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 300,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
ShardNumber: qdrant.PtrOf(uint32(6)),
|
||||
ReplicationFactor: qdrant.PtrOf(uint32(2)),
|
||||
WriteConsistencyFactor: qdrant.PtrOf(uint32(2)),
|
||||
})
|
||||
```
|
||||
|
||||
Write operations will fail if the number of active replicas is less than the `write_consistency_factor`.
|
||||
|
||||
### Read consistency
|
||||
@@ -1151,7 +1272,7 @@ client.queryAsync(
|
||||
.setCollectionName("{collection_name}")
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")).build())
|
||||
.setQuery(nearest(.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(true).build())
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(false).build())
|
||||
.setLimit(3)
|
||||
.setReadConsistency(
|
||||
ReadConsistency.newBuilder().setType(ReadConsistencyType.Majority).build())
|
||||
@@ -1170,12 +1291,40 @@ await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f },
|
||||
filter: MatchKeyword("city", "London"),
|
||||
searchParams: new SearchParams { HnswEf = 128, Exact = true },
|
||||
searchParams: new SearchParams { HnswEf = 128, Exact = false },
|
||||
limit: 3,
|
||||
readConsistency: new ReadConsistency { Type = ReadConsistencyType.Majority }
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Filter: &qdrant.Filter{
|
||||
Must: []*qdrant.Condition{
|
||||
qdrant.NewMatch("city", "London"),
|
||||
},
|
||||
},
|
||||
Params: &qdrant.SearchParams{
|
||||
HnswEf: qdrant.PtrOf(uint64(128)),
|
||||
},
|
||||
Limit: qdrant.PtrOf(uint64(3)),
|
||||
ReadConsistency: qdrant.NewReadConsistencyType(qdrant.ReadConsistencyType_Majority),
|
||||
})
|
||||
```
|
||||
|
||||
### Write ordering
|
||||
|
||||
Write `ordering` can be specified for any write request to serialize it through a single "leader" node,
|
||||
@@ -1320,25 +1469,62 @@ await client.UpsertAsync(
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new[] { 0.9f, 0.1f, 0.1f },
|
||||
Payload = { ["city"] = "red" }
|
||||
Payload = { ["color"] = "red" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Vectors = new[] { 0.1f, 0.9f, 0.1f },
|
||||
Payload = { ["city"] = "green" }
|
||||
Payload = { ["color"] = "green" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
Vectors = new[] { 0.1f, 0.1f, 0.9f },
|
||||
Payload = { ["city"] = "blue" }
|
||||
Payload = { ["color"] = "blue" }
|
||||
}
|
||||
},
|
||||
ordering: WriteOrderingType.Strong
|
||||
);
|
||||
```
|
||||
|
||||
```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(1),
|
||||
Vectors: qdrant.NewVectors(0.9, 0.1, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "red"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.9, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "green"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(3),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.1, 0.9),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "blue"}),
|
||||
},
|
||||
},
|
||||
Ordering: &qdrant.WriteOrdering{
|
||||
Type: qdrant.WriteOrderingType_Strong,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Listener mode
|
||||
|
||||
<aside role="alert">This is an experimental feature, its behavior may change in the future.</aside>
|
||||
|
||||
@@ -176,6 +176,40 @@ await client.UpsertAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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(1),
|
||||
Vectors: qdrant.NewVectors(0.9, 0.1, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"group_id": "user_1"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.9, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"group_id": "user_1"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(3),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.1, 0.9),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"group_id": "user_2"}),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
2. Use a filter along with `group_id` to filter vectors for each user.
|
||||
|
||||
```http
|
||||
@@ -291,6 +325,29 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.1, 0.1, 0.9),
|
||||
Filter: &qdrant.Filter{
|
||||
Must: []*qdrant.Condition{
|
||||
qdrant.NewMatch("group_id", "user_1"),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Calibrate performance
|
||||
|
||||
The speed of indexation may become a bottleneck in this case, as each user's vector will be indexed into the same collection. To avoid this bottleneck, consider _bypassing the construction of a global vector index_ for the entire collection and building it only for individual groups instead.
|
||||
@@ -407,6 +464,31 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
HnswConfig: &qdrant.HnswConfigDiff{
|
||||
PayloadM: qdrant.PtrOf(uint64(16)),
|
||||
M: qdrant.PtrOf(uint64(0)),
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
3. Create keyword payload index for `group_id` field.
|
||||
|
||||
<aside role="alert">
|
||||
@@ -512,7 +594,29 @@ await client.CreatePayloadIndexAsync(
|
||||
}
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.CreateFieldIndex(context.Background(), &qdrant.CreateFieldIndexCollection{
|
||||
CollectionName: "{collection_name}",
|
||||
FieldName: "group_id",
|
||||
FieldType: qdrant.FieldType_FieldTypeKeyword.Enum(),
|
||||
FieldIndexParams: qdrant.NewPayloadIndexParams(
|
||||
&qdrant.KeywordIndexParams{
|
||||
IsTenant: qdrant.PtrOf(true),
|
||||
}),
|
||||
})
|
||||
```
|
||||
|
||||
`is_tenant=true` parameter is optional, but specifying it provides storage with additional inforamtion about the usage patterns the collection is going to use.
|
||||
|
||||
@@ -154,6 +154,32 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
OnDisk: qdrant.PtrOf(true),
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationScalar(&qdrant.ScalarQuantization{
|
||||
Type: qdrant.QuantizationType_Int8,
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
}),
|
||||
})
|
||||
```
|
||||
|
||||
`on_disk` will ensure that vectors will be stored on disk, while `always_ram` will ensure that quantized vectors will be stored in RAM.
|
||||
|
||||
Optionally, you can disable rescoring with search `params`, which will reduce the number of disk reads even further, but potentially slightly decrease the precision.
|
||||
@@ -264,6 +290,29 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Params: &qdrant.SearchParams{
|
||||
Quantization: &qdrant.QuantizationSearchParams{
|
||||
Rescore: qdrant.PtrOf(true),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Prefer high precision with low memory footprint
|
||||
|
||||
In case you need high precision, but don't have enough RAM to store vectors in memory, you can enable on-disk vectors and HNSW index.
|
||||
@@ -372,6 +421,31 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
OnDisk: qdrant.PtrOf(true),
|
||||
}),
|
||||
HnswConfig: &qdrant.HnswConfigDiff{
|
||||
OnDisk: qdrant.PtrOf(true),
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
In this scenario you can increase the precision of the search by increasing the `ef` and `m` parameters of the HNSW index, even with limited RAM.
|
||||
|
||||
```json
|
||||
@@ -399,8 +473,7 @@ PUT /collections/{collection_name}
|
||||
{
|
||||
"vectors": {
|
||||
"size": 768,
|
||||
"distance": "Cosine",
|
||||
"on_disk": true
|
||||
"distance": "Cosine"
|
||||
},
|
||||
"quantization_config": {
|
||||
"scalar": {
|
||||
@@ -418,7 +491,7 @@ client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.create_collection(
|
||||
collection_name="{collection_name}",
|
||||
vectors_config=models.VectorParams(size=768, distance=models.Distance.COSINE, on_disk=True),
|
||||
vectors_config=models.VectorParams(size=768, distance=models.Distance.COSINE),
|
||||
quantization_config=models.ScalarQuantization(
|
||||
scalar=models.ScalarQuantizationConfig(
|
||||
type=models.ScalarType.INT8,
|
||||
@@ -437,7 +510,6 @@ client.createCollection("{collection_name}", {
|
||||
vectors: {
|
||||
size: 768,
|
||||
distance: "Cosine",
|
||||
on_disk: true,
|
||||
},
|
||||
quantization_config: {
|
||||
scalar: {
|
||||
@@ -460,7 +532,7 @@ let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("{collection_name}")
|
||||
.vectors_config(VectorParamsBuilder::new(768, Distance::Cosine).on_disk(true))
|
||||
.vectors_config(VectorParamsBuilder::new(768, Distance::Cosine))
|
||||
.quantization_config(
|
||||
ScalarQuantizationBuilder::default()
|
||||
.r#type(QuantizationType::Int8.into())
|
||||
@@ -495,7 +567,6 @@ client
|
||||
VectorParams.newBuilder()
|
||||
.setSize(768)
|
||||
.setDistance(Distance.Cosine)
|
||||
.setOnDisk(true)
|
||||
.build())
|
||||
.build())
|
||||
.setQuantizationConfig(
|
||||
@@ -518,7 +589,7 @@ var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "{collection_name}",
|
||||
vectorsConfig: new VectorParams { Size = 768, Distance = Distance.Cosine, OnDisk = true},
|
||||
vectorsConfig: new VectorParams { Size = 768, Distance = Distance.Cosine},
|
||||
quantizationConfig: new QuantizationConfig
|
||||
{
|
||||
Scalar = new ScalarQuantization { Type = QuantizationType.Int8, AlwaysRam = true }
|
||||
@@ -526,6 +597,31 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationScalar(&qdrant.ScalarQuantization{
|
||||
Type: qdrant.QuantizationType_Int8,
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
}),
|
||||
})
|
||||
```
|
||||
|
||||
There are also some search-time parameters you can use to tune the search accuracy and speed:
|
||||
|
||||
```http
|
||||
@@ -619,6 +715,28 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Params: &qdrant.SearchParams{
|
||||
HnswEf: qdrant.PtrOf(uint64(128)),
|
||||
Exact: qdrant.PtrOf(false),
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
- `hnsw_ef` - controls the number of neighbors to visit during search. The higher the value, the more accurate and slower the search will be. Recommended range is 32-512.
|
||||
- `exact` - if set to `true`, will perform exact search, which will be slower, but more accurate. You can use it to compare results of the search with different `hnsw_ef` values versus the ground truth.
|
||||
|
||||
@@ -736,6 +854,30 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
OptimizersConfig: &qdrant.OptimizersConfigDiff{
|
||||
DefaultSegmentNumber: qdrant.PtrOf(uint64(16)),
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
To prefer throughput, you can set up Qdrant to use as many cores as possible for processing multiple requests in parallel.
|
||||
To do that, you can configure qdrant to use minimal number of segments, which is usually 2.
|
||||
Large segments benefit from the size of the index and overall smaller number of vector comparisons required to find the nearest neighbors. But at the same time require more time to build index.
|
||||
@@ -841,4 +983,28 @@ await client.CreateCollectionAsync(
|
||||
vectorsConfig: new VectorParams { Size = 768, Distance = Distance.Cosine },
|
||||
optimizersConfig: new OptimizersConfigDiff { DefaultSegmentNumber = 2 }
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
OptimizersConfig: &qdrant.OptimizersConfigDiff{
|
||||
DefaultSegmentNumber: qdrant.PtrOf(uint64(2)),
|
||||
},
|
||||
})
|
||||
```
|
||||
@@ -282,6 +282,34 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationScalar(
|
||||
&qdrant.ScalarQuantization{
|
||||
Type: qdrant.QuantizationType_Int8,
|
||||
Quantile: qdrant.PtrOf(float32(0.99)),
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
},
|
||||
),
|
||||
})
|
||||
```
|
||||
|
||||
There are 3 parameters that you can specify in the `quantization_config` section:
|
||||
|
||||
`type` - the type of the quantized vector components. Currently, Qdrant supports only `int8`.
|
||||
@@ -418,6 +446,32 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 1536,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationBinary(
|
||||
&qdrant.BinaryQuantization{
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
},
|
||||
),
|
||||
})
|
||||
```
|
||||
|
||||
`always_ram` - whether to keep quantized vectors always cached in RAM or not. By default, quantized vectors are loaded in the same way as the original vectors.
|
||||
However, in some setups you might want to keep quantized vectors in RAM to speed up the search process.
|
||||
|
||||
@@ -553,6 +607,33 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationProduct(
|
||||
&qdrant.ProductQuantization{
|
||||
Compression: qdrant.CompressionRatio_x16,
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
},
|
||||
),
|
||||
})
|
||||
```
|
||||
|
||||
There are two parameters that you can specify in the `quantization_config` section:
|
||||
|
||||
`compression` - compression ratio.
|
||||
@@ -697,6 +778,31 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Params: &qdrant.SearchParams{
|
||||
Quantization: &qdrant.QuantizationSearchParams{
|
||||
Ignore: qdrant.PtrOf(false),
|
||||
Rescore: qdrant.PtrOf(true),
|
||||
Oversampling: qdrant.PtrOf(2.0),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
`ignore` - Toggle whether to ignore quantized vectors during the search process. By default, Qdrant will use quantized vectors if they are available.
|
||||
|
||||
`rescore` - Having the original vectors available, Qdrant can re-evaluate top-k search results using the original vectors.
|
||||
@@ -827,6 +933,29 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Params: &qdrant.SearchParams{
|
||||
Quantization: &qdrant.QuantizationSearchParams{
|
||||
Ignore: qdrant.PtrOf(false),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
- **Adjust the quantile parameter**: The quantile parameter in scalar quantization determines the quantization bounds.
|
||||
By setting it to a value lower than 1.0, you can exclude extreme values (outliers) from the quantization bounds.
|
||||
For example, if you set the quantile to 0.99, 1% of the extreme values will be excluded.
|
||||
@@ -978,6 +1107,34 @@ await client.CreateCollectionAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
OnDisk: qdrant.PtrOf(true),
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationScalar(
|
||||
&qdrant.ScalarQuantization{
|
||||
Type: qdrant.QuantizationType_Int8,
|
||||
AlwaysRam: qdrant.PtrOf(true),
|
||||
},
|
||||
),
|
||||
})
|
||||
```
|
||||
|
||||
In this scenario, the number of disk reads may play a significant role in the search speed.
|
||||
In a system with high disk latency, the re-scoring step may become a bottleneck.
|
||||
|
||||
@@ -1089,6 +1246,29 @@ await client.QueryAsync(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Params: &qdrant.SearchParams{
|
||||
Quantization: &qdrant.QuantizationSearchParams{
|
||||
Rescore: qdrant.PtrOf(false),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
- **All on Disk** - all vectors, original and quantized, are stored on disk. This mode allows to achieve the smallest memory footprint, but at the cost of the search speed.
|
||||
|
||||
It is recommended to use this mode if you have a large collection and fast storage (e.g. SSD or NVMe).
|
||||
@@ -1226,3 +1406,31 @@ await client.CreateCollectionAsync(
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
```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}",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 768,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
OnDisk: qdrant.PtrOf(true),
|
||||
}),
|
||||
QuantizationConfig: qdrant.NewQuantizationScalar(
|
||||
&qdrant.ScalarQuantization{
|
||||
Type: qdrant.QuantizationType_Int8,
|
||||
AlwaysRam: qdrant.PtrOf(false),
|
||||
},
|
||||
),
|
||||
})
|
||||
```
|
||||
|
||||
@@ -108,6 +108,17 @@ var client = new QdrantClient(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import "github.com/qdrant/go-client/qdrant"
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "xyz-example.eu-central.aws.cloud.qdrant.io",
|
||||
Port: 6334,
|
||||
APIKey: "<paste-your-api-key-here>",
|
||||
UseTLS: true,
|
||||
})
|
||||
```
|
||||
|
||||
<aside role="alert">Internal communication channels are <strong>never</strong> protected by an API key nor bearer tokens. Internal gRPC uses port 6335 by default if running in distributed mode. You must ensure that this port is not publicly reachable and can only be used for node communication. By default, this setting is disabled for Qdrant Cloud and the Qdrant Helm chart.</aside>
|
||||
|
||||
### Read-only API key
|
||||
@@ -215,6 +226,16 @@ var client = new QdrantClient(
|
||||
);
|
||||
```
|
||||
|
||||
```go
|
||||
import "github.com/qdrant/go-client/qdrant"
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "xyz-example.eu-central.aws.cloud.qdrant.io",
|
||||
Port: 6334,
|
||||
APIKey: "<JWT>",
|
||||
UseTLS: true,
|
||||
})
|
||||
```
|
||||
#### Generating JSON Web Tokens
|
||||
|
||||
Due to the nature of JWT, anyone who knows the `api_key` can generate tokens by using any of the existing libraries and tools, it is not necessary for them to have access to the Qdrant instance to generate them.
|
||||
|
||||
Reference in New Issue
Block a user