From bea2afa5e87fa5c5a41c76c8f37b450231f36e52 Mon Sep 17 00:00:00 2001 From: Anush Date: Mon, 9 Sep 2024 16:20:04 +0530 Subject: [PATCH] docs: New Go SDK snippets (#1149) --- .../documentation/cloud/authentication.md | 11 + .../documentation/concepts/collections.md | 277 +++++++++++- .../content/documentation/concepts/explore.md | 203 +++++++++ .../documentation/concepts/filtering.md | 410 ++++++++++++++++++ .../documentation/concepts/hybrid-queries.md | 219 ++++++++++ .../documentation/concepts/indexing.md | 183 +++++++- .../content/documentation/concepts/payload.md | 188 ++++++++ .../content/documentation/concepts/points.md | 331 +++++++++++++- .../content/documentation/concepts/search.md | 285 +++++++++++- .../documentation/concepts/snapshots.md | 90 ++++ .../content/documentation/concepts/storage.md | 73 ++++ .../content/documentation/concepts/vectors.md | 243 ++++++++++- .../guides/distributed_deployment.md | 198 ++++++++- .../guides/multiple-partitions.md | 104 +++++ .../content/documentation/guides/optimize.md | 180 +++++++- .../documentation/guides/quantization.md | 208 +++++++++ .../content/documentation/guides/security.md | 21 + .../content/documentation/quickstart.md | 120 ++++- qdrant-landing/static/docs/misc/go.webp | Bin 1330 -> 980 bytes .../assets/css/components/_lang-switcher.scss | 4 + .../qdrant-2024/static/icons/outline/go.svg | 6 + 21 files changed, 3307 insertions(+), 47 deletions(-) create mode 100644 qdrant-landing/themes/qdrant-2024/static/icons/outline/go.svg diff --git a/qdrant-landing/content/documentation/cloud/authentication.md b/qdrant-landing/content/documentation/cloud/authentication.md index 9862f95de..43c41fe74 100644 --- a/qdrant-landing/content/documentation/cloud/authentication.md +++ b/qdrant-landing/content/documentation/cloud/authentication.md @@ -101,3 +101,14 @@ var client = new QdrantClient( apiKey: "" ); ``` + +```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: "", + UseTLS: true, +}) +``` diff --git a/qdrant-landing/content/documentation/concepts/collections.md b/qdrant-landing/content/documentation/concepts/collections.md index 2c7768523..e15077ee5 100644 --- a/qdrant-landing/content/documentation/concepts/collections.md +++ b/qdrant-landing/content/documentation/concepts/collections.md @@ -116,6 +116,27 @@ 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: 100, + Distance: qdrant.Distance_Cosine, + }), +}) +``` + In addition to the required options, you can also specify custom values for the following collection options: * `hnsw_config` - see [indexing](../indexing/#vector-index) for details. @@ -254,6 +275,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: 100, + Distance: qdrant.Distance_Cosine, + }), + InitFromCollection: qdrant.PtrOf("{from_collection_name}"), +}) +``` + ### Collection with multiple vectors *Available as of v0.10.0* @@ -388,6 +431,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.NewVectorsConfigMap( + map[string]*qdrant.VectorParams{ + "image": { + Size: 4, + Distance: qdrant.Distance_Dot, + }, + "text": { + Size: 8, + Distance: qdrant.Distance_Cosine, + }, + }), +}) +``` + For rare use cases, it is possible to create a collection without any vector storage. *Available as of v1.1.1* @@ -517,6 +588,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: 1024, + Distance: qdrant.Distance_Cosine, + Datatype: qdrant.Datatype_Uint8.Enum(), + }), +}) +``` + Vectors with `uint8` datatype are stored in a more compact format, which can save memory and improve search speed at the cost of some precision. If you choose to use the `uint8` datatype, elements of the vector will be stored as unsigned 8-bit integers, which can take values **from 0 to 255**. @@ -632,6 +725,27 @@ 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_namee}", + SparseVectorsConfig: qdrant.NewSparseVectorsConfig( + map[string]*qdrant.SparseVectorParams{ + "text": {}, + }), +}) +``` + Outside of a unique name, there are no required configuration parameters for sparse vectors. The distance function for sparse vectors is always `Dot` and does not need to be specified. @@ -670,6 +784,12 @@ client.collectionExistsAsync("{collection_name}").get(); await client.CollectionExistsAsync("{collection_name}"); ``` +```go +import "context" + +client.CollectionExists(context.Background(), "my_collection") +``` + ### Delete collection ```http @@ -693,23 +813,19 @@ client.delete_collection("{collection_name}").await?; ``` ```java -import io.qdrant.client.QdrantClient; -import io.qdrant.client.QdrantGrpcClient; - -QdrantClient client = - new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build()); - client.deleteCollectionAsync("{collection_name}").get(); ``` ```csharp -using Qdrant.Client; - -var client = new QdrantClient("localhost", 6334); - await client.DeleteCollectionAsync("{collection_name}"); ``` +```go +import "context" + +client.DeleteCollection(context.Background(), "{collection_name}") +``` + ### Update collection parameters Dynamic parameter updates may be helpful, for example, for more efficient initial loading of vectors. @@ -788,6 +904,26 @@ await client.UpdateCollectionAsync( ); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{ + CollectionName: "{collection_name}", + OptimizersConfig: &qdrant.OptimizersConfigDiff{ + IndexingThreshold: qdrant.PtrOf(uint64(10000)), + }, +}) +``` + The following parameters can be updated: * `optimizers_config` - see [optimizer](../optimizer/) for details. @@ -1103,6 +1239,38 @@ await client.UpdateCollectionAsync( ); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{ + CollectionName: "{collection_name}", + VectorsConfig: qdrant.NewVectorsConfigDiffMap( + map[string]*qdrant.VectorParamsDiff{ + "my_vector": { + HnswConfig: &qdrant.HnswConfigDiff{ + M: qdrant.PtrOf(uint64(3)), + EfConstruct: qdrant.PtrOf(uint64(123)), + }, + }, + }), + QuantizationConfig: qdrant.NewQuantizationDiffScalar( + &qdrant.ScalarQuantization{ + Type: qdrant.QuantizationType_Int8, + Quantile: qdrant.PtrOf(float32(0.8)), + AlwaysRam: qdrant.PtrOf(true), + }), +}) +``` + ## Collection info Qdrant allows determining the configuration parameters of an existing collection to better understand how the points are @@ -1136,6 +1304,12 @@ client.getCollectionInfoAsync("{collection_name}").get(); await client.GetCollectionInfoAsync("{collection_name}"); ``` +```go +import "context" + +client.GetCollectionInfo(context.Background(), "{collection_name}") +``` +
Expected result @@ -1276,6 +1450,24 @@ await client.UpdateCollectionAsync( ); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{ + CollectionName: "{collection_name}", + OptimizersConfig: &qdrant.OptimizersConfigDiff{}, +}) +``` + ### Approximate point and vector counts You may be interested in the count attributes: @@ -1401,6 +1593,12 @@ client.createAliasAsync("production_collection", "example_collection").get(); await client.CreateAliasAsync(aliasName: "production_collection", collectionName: "example_collection"); ``` +```go +import "context" + +client.CreateAlias(context.Background(), "production_collection", "example_collection") +``` + ### Remove alias ```bash @@ -1464,6 +1662,12 @@ client.deleteAliasAsync("production_collection").get(); await client.DeleteAliasAsync("production_collection"); ``` +```go +import "context" + +client.DeleteAlias(context.Background(), "production_collection") +``` + ### Switch collection Multiple alias actions are performed atomically. @@ -1562,6 +1766,14 @@ client.createAliasAsync("production_collection", "example_collection").get(); await client.DeleteAliasAsync("production_collection"); await client.CreateAliasAsync(aliasName: "production_collection", collectionName: "example_collection"); ``` + +```go +import "context" + +client.DeleteAlias(context.Background(), "production_collection") +client.CreateAlias(context.Background(), "production_collection", "example_collection") +``` + ### List collection aliases ```http @@ -1614,6 +1826,21 @@ var client = new QdrantClient("localhost", 6334); await client.ListCollectionAliasesAsync("{collection_name}"); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.ListCollectionAliases(context.Background(), "{collection_name}") +``` + ### List all aliases ```http @@ -1667,6 +1894,21 @@ var client = new QdrantClient("localhost", 6334); await client.ListAliasesAsync(); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.ListAliases(context.Background()) +``` + ### List all collections ```http @@ -1719,3 +1961,18 @@ var client = new QdrantClient("localhost", 6334); await client.ListCollectionsAsync(); ``` + +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +client.ListCollections(context.Background()) +``` diff --git a/qdrant-landing/content/documentation/concepts/explore.md b/qdrant-landing/content/documentation/concepts/explore.md index 28c956f0e..797c472fd 100644 --- a/qdrant-landing/content/documentation/concepts/explore.md +++ b/qdrant-landing/content/documentation/concepts/explore.md @@ -169,6 +169,37 @@ 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.NewQueryRecommend(&qdrant.RecommendInput{ + Positive: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(100)), + qdrant.NewVectorInputID(qdrant.NewIDNum(231)), + }, + Negative: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(718)), + }, + }), + Filter: &qdrant.Filter{ + Must: []*qdrant.Condition{ + qdrant.NewMatch("city", "London"), + }, + }, +}) +``` + Example result of this API would be ```json @@ -335,6 +366,33 @@ 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.NewQueryRecommend(&qdrant.RecommendInput{ + Positive: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(100)), + qdrant.NewVectorInputID(qdrant.NewIDNum(231)), + }, + Negative: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(718)), + }, + }), + Using: qdrant.PtrOf("image"), +}) +``` + Parameter `using` specifies which stored vectors to use for the recommendation. ### Lookup vectors from another collection @@ -470,6 +528,37 @@ 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.NewQueryRecommend(&qdrant.RecommendInput{ + Positive: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(100)), + qdrant.NewVectorInputID(qdrant.NewIDNum(231)), + }, + Negative: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(718)), + }, + }), + Using: qdrant.PtrOf("image"), + LookupFrom: &qdrant.LookupLocation{ + CollectionName: "{external_collection_name}", + VectorName: qdrant.PtrOf("{external_vector_name}"), + }, +}) +``` + Vectors are retrieved from the external collection by ids provided in the `positive` and `negative` lists. These vectors then used to perform the recommendation in the current collection, comparing against the "using" or default vector. @@ -730,6 +819,59 @@ await client.QueryBatchAsync( ); ``` +```go +import ( + "context" + + "github.com/qdrant/go-client/qdrant" +) + +client, err := qdrant.NewClient(&qdrant.Config{ + Host: "localhost", + Port: 6334, +}) + +filter := qdrant.Filter{ + Must: []*qdrant.Condition{ + qdrant.NewMatch("city", "London"), + }, +} +client.QueryBatch(context.Background(), &qdrant.QueryBatchPoints{ + CollectionName: "{collection_name}", + QueryPoints: []*qdrant.QueryPoints{ + { + CollectionName: "{collection_name}", + Query: qdrant.NewQueryRecommend(&qdrant.RecommendInput{ + Positive: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(100)), + qdrant.NewVectorInputID(qdrant.NewIDNum(231)), + }, + Negative: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(718)), + }, + }, + ), + Filter: &filter, + }, + { + CollectionName: "{collection_name}", + Query: qdrant.NewQueryRecommend(&qdrant.RecommendInput{ + Positive: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(200)), + qdrant.NewVectorInputID(qdrant.NewIDNum(67)), + }, + Negative: []*qdrant.VectorInput{ + qdrant.NewVectorInputID(qdrant.NewIDNum(300)), + }, + }, + ), + Filter: &filter, + }, + }, +}, +) +``` + The result of this API contains one array per recommendation requests. ```json @@ -947,6 +1089,38 @@ 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.NewQueryDiscover(&qdrant.DiscoverInput{ + Target: qdrant.NewVectorInput(0.2, 0.1, 0.9, 0.7), + Context: &qdrant.ContextInput{ + Pairs: []*qdrant.ContextInputPair{ + { + Positive: qdrant.NewVectorInputID(qdrant.NewIDNum(100)), + Negative: qdrant.NewVectorInputID(qdrant.NewIDNum(718)), + }, + { + Positive: qdrant.NewVectorInputID(qdrant.NewIDNum(200)), + Negative: qdrant.NewVectorInputID(qdrant.NewIDNum(300)), + }, + }, + }, + }), +}) +``` +