### Install Qdrant Go Client Source: https://github.com/qdrant/go-client/blob/master/README.md Use the go get command to add the library to your project. ```bash go get -u github.com/qdrant/go-client ``` -------------------------------- ### GetPointsClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting the points client. ```go pointsClient := client.GetPointsClient() ``` -------------------------------- ### GetGrpcClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting a gRPC client. ```go grpcClient := client.GetGrpcClient() conn := grpcClient.Conn() ``` -------------------------------- ### GetConnection Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting an underlying gRPC connection. ```go conn := client.GetConnection() state := conn.GetState() ``` -------------------------------- ### GetQdrantClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting the main Qdrant client. ```go qdrantClient := client.GetQdrantClient() ``` -------------------------------- ### GetSnapshotsClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting the snapshots client. ```go snapshotsClient := client.GetSnapshotsClient() ``` -------------------------------- ### GetCollectionsClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of getting the collections client. ```go collectionsClient := client.GetCollectionsClient() ``` -------------------------------- ### NewClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of creating a new Qdrant client. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, }) if err != nil { log.Fatal(err) } defer client.Close() ``` -------------------------------- ### DefaultClient Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of creating a client using DefaultClient. ```go client, err := qdrant.DefaultClient() if err != nil { log.Fatal(err) } defer client.Close() ``` -------------------------------- ### Basic Connection Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example of establishing a basic connection to Qdrant. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, }) ``` -------------------------------- ### Retry Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example demonstrating the usage of RetryConfig. ```go config := &qdrant.RetryConfig{ MaxRetries: 3, BaseBackoff: 100 * time.Millisecond, MaxBackoff: 5 * time.Second, } client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, RetryConfig: config, }) ``` -------------------------------- ### Connection Pool Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example of configuring a connection pool for Qdrant. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, PoolSize: 5, // Create 5 connections with round-robin distribution }) ``` -------------------------------- ### Close Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Example of deferring the Close call. ```go defer client.Close() ``` -------------------------------- ### UpdateClusterCollectionSetup Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/collections.md Updates cluster setup for a collection including shard movements, replications, and transfers. ```go err := client.UpdateClusterCollectionSetup(ctx, qdrant.NewUpdateCollectionClusterMoveShard("my_collection", &qdrant.MoveShard{ ShardId: 1, FromPeer: 1, ToPeer: 2, }), ) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Connection with Custom TLS Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example of connecting with custom TLS configuration. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, UseTLS: true, TLSConfig: &tls.Config{ InsecureSkipVerify: false, MinVersion: tls.VersionTLS13, }, }) ``` -------------------------------- ### Connection Pooling Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Configures the client with a connection pool size of 10. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, PoolSize: 10, // Pool of 10 connections }) ``` -------------------------------- ### Filtering Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Demonstrates composing complex filters with must, should, and must-not conditions. ```go filter := &qdrant.Filter{ Must: []*qdrant.Condition{ qdrant.NewMatch("category", "electronics"), }, Should: []*qdrant.Condition{ qdrant.NewRange("price", &qdrant.Range{ Lte: qdrant.PtrOf(1000.0), }), }, } ``` -------------------------------- ### With Retry Configuration Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example of configuring automatic retries for transient failures. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, RetryConfig: &qdrant.RetryConfig{ MaxRetries: 3, BaseBackoff: 100 * time.Millisecond, MaxBackoff: 5 * time.Second, }, }) ``` -------------------------------- ### Cloud Connection with API Key Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Example of connecting to Qdrant Cloud with an API key and TLS enabled. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "xyz-example.eu-central.aws.cloud.qdrant.io", Port: 6334, APIKey: "your-api-key", UseTLS: true, }) ``` -------------------------------- ### Error Handling Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Demonstrates how to handle errors returned by the Qdrant Go Client, specifically checking for `QdrantError`. ```go info, err := client.GetCollectionInfo(ctx, "my_collection") if err != nil { var qdErr *qdrant.QdrantError if errors.As(err, &qdErr) { fmt.Printf("Operation failed: %s\n", qdErr.Error()) } } ``` -------------------------------- ### NewAliasCreate Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates an alias operation for creating an alias. ```go op := qdrant.NewAliasCreate("my_alias", "my_collection") ``` -------------------------------- ### NewMatchInt Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches an integer value. ```go condition := qdrant.NewMatchInt("age", 25) ``` -------------------------------- ### Custom Headers Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Adds custom headers 'X-Custom-Header' and 'X-Request-ID' to all gRPC requests. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, Headers: map[string]string{ "X-Custom-Header": "value", "X-Request-ID": "trace-id", }, }) ``` -------------------------------- ### NewVectorsConfig Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a `VectorsConfig` from `VectorParams`. ```go config := qdrant.NewVectorsConfig(&qdrant.VectorParams{ Size: 384, Distance: qdrant.Distance_Cosine, }) ``` -------------------------------- ### Count Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/points.md Example usage of the Count function to retrieve the total number of points in a collection. ```go count, err := client.Count(ctx, &qdrant.CountPoints{ CollectionName: "my_collection", CountAll: true, }) if err != nil { log.Fatal(err) } fmt.Printf("Total points: %d\n", count) ``` -------------------------------- ### ScrollAll Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/points.md Demonstrates how to use ScrollAll to iterate through all points in a collection, handling pagination and errors. ```go iterator := client.ScrollAll(ctx, &qdrant.ScrollPoints{ CollectionName: "my_collection", }) for { points, err := iterator.Next() if err == io.EOF { break } if err != nil { log.Fatal(err) } // Process points } ``` -------------------------------- ### NewMatchInts Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches any of the given integer values. ```go condition := qdrant.NewMatchInts("status_code", 200, 201, 204) ``` -------------------------------- ### NewMatchBool Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches a boolean value. ```go condition := qdrant.NewMatchBool("verified", true) ``` -------------------------------- ### NewValueMap Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Converts a map to Qdrant payload values. ```go payload := qdrant.NewValueMap(map[string]any{ "name": "John", "age": 30, "active": true, "tags": []any{"vip", "verified"}, }) ``` -------------------------------- ### NewMatchKeywords Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches any of the given keywords. ```go condition := qdrant.NewMatchKeywords("city", "London", "Paris", "Berlin") ``` -------------------------------- ### Example of using Unwrap with QdrantError Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Demonstrates how to check for QdrantError and unwrap the inner error. ```go err := client.Upsert(ctx, &request) if err != nil { var qdErr *qdrant.QdrantError if errors.As(err, &qdErr) { fmt.Println("Operation:", qdErr.operationName) fmt.Println("Inner error:", qdErr.Unwrap()) } } ``` -------------------------------- ### NewMatch Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches an exact keyword. ```go filter := &qdrant.Filter{ Must: []*qdrant.Condition{ qdrant.NewMatch("city", "London"), }, } ``` -------------------------------- ### SetPayload Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/points.md Shows how to set or update payload fields for specific points in a collection using SetPayload. ```go result, err := client.SetPayload(ctx, &qdrant.SetPayloadPoints{ CollectionName: "my_collection", Payload: qdrant.NewValueMap(map[string]any{"city": "Paris"}), PointsSelector: qdrant.NewPointsSelectorIDs([]*qdrant.PointId{ qdrant.NewIDNum(1), }), }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Query Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/points.md Performs a universal query on points, supporting search, recommend, discover, and filtering. This example demonstrates how to use the Query method to retrieve points from a collection. ```go results, err := client.Query(ctx, &qdrant.QueryPoints{ CollectionName: "my_collection", Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), Limit: 10, WithPayload: qdrant.NewWithPayload(true), }) if err != nil { log.Fatal(err) } for _, point := range results { fmt.Printf("Point %v Score: %f\n", point.Id, point.Score) } ``` -------------------------------- ### NewRange Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a range condition for numeric or date fields. ```go condition := qdrant.NewRange("age", &qdrant.Range{ Gte: qdrant.PtrOf(18.0), Lt: qdrant.PtrOf(65.0), }) ``` -------------------------------- ### NewGeoRadius Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition matching points within a radius from a center point. ```go condition := qdrant.NewGeoRadius("location", 51.5074, -0.1278, 1000) ``` -------------------------------- ### NewWithVectorsInclude Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a `WithVectorsSelector` including specific named vectors. ```go selector := qdrant.NewWithVectorsInclude("text_vector", "image_vector") ``` -------------------------------- ### Handling gRPC Errors Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Example of how to unwrap a QdrantError and check for specific gRPC status codes. ```go import ( "errors" "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/qdrant/go-client/qdrant" ) err := client.CreateCollection(ctx, request) if err != nil { var qdErr *qdrant.QdrantError if errors.As(err, &qdErr) { inner := qdErr.Unwrap() st, ok := status.FromError(inner) if ok { switch st.Code() { case codes.AlreadyExists: fmt.Println("Collection already exists") case codes.InvalidArgument: fmt.Println("Invalid collection parameters") default: fmt.Printf("Error code: %v\n", st.Code()) } } } } ``` -------------------------------- ### UpdateAliases Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/collections.md Performs multiple alias operations (create, delete, rename) in a single request. ```go err := client.UpdateAliases(ctx, []*qdrant.AliasOperations{ qdrant.NewAliasCreate("alias1", "collection1"), qdrant.NewAliasDelete("old_alias"), }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Build Qdrant Go Project Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Compile the project and download all dependencies. This is a prerequisite for running tests and making changes. ```bash go build ./... ``` -------------------------------- ### Error Handling Pattern 1: Simple Error Check Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md A basic example of checking for errors after an operation. ```go info, err := client.GetCollectionInfo(ctx, "my_collection") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Instantiate Qdrant Client Source: https://github.com/qdrant/go-client/blob/master/README.md Create a new client instance to connect to a Qdrant server. ```go import "github.com/qdrant/go-client/qdrant" client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, }) ``` ```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, // uses default config with minimum TLS version set to 1.3 // PoolSize: 3, // KeepAliveTime: 10, // KeepAliveTimeout: 2, // TLSConfig: &tls.Config{...}, // GrpcOptions: []grpc.DialOption{}, }) ``` -------------------------------- ### Environment Variables Integration Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Demonstrates how to integrate environment variables to configure the Qdrant client. ```go import ( "os" "strconv" "github.com/qdrant/go-client/qdrant" ) host := os.Getenv("QDRANT_HOST") if host == "" { host = "localhost" } portStr := os.Getenv("QDRANT_PORT") port := 6334 if portStr != "" { port, _ = strconv.Atoi(portStr) } apiKey := os.Getenv("QDRANT_API_KEY") useTLS := os.Getenv("QDRANT_USE_TLS") == "true" client, err := qdrant.NewClient(&qdrant.Config{ Host: host, Port: port, APIKey: apiKey, UseTLS: useTLS, }) ``` -------------------------------- ### Get Points Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/points.md Retrieves points by their IDs. ```go func (c *Client) Get(ctx context.Context, request *GetPoints) ([]*RetrievedPoint, error) points, err := client.Get(ctx, &qdrant.GetPoints{ CollectionName: "my_collection", IdsList: &qdrant.PointIdList{ Ids: []*qdrant.PointId{ qdrant.NewIDNum(1), qdrant.NewIDNum(2), }, }, WithPayload: qdrant.NewWithPayload(true), WithVectors: qdrant.NewWithVectors(true), }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Create a Collection Source: https://github.com/qdrant/go-client/blob/master/README.md Initialize a new collection with specific vector parameters. ```go import ( "context" "github.com/qdrant/go-client/qdrant" ) client.CreateCollection(context.Background(), &qdrant.CreateCollection{ CollectionName: "{collection_name}", VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ Size: 4, Distance: qdrant.Distance_Cosine, }), }) ``` -------------------------------- ### NewDefaultGrpcClient Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Creates a gRPC client with default configuration. ```go func NewDefaultGrpcClient() (*GrpcClient, error) ``` -------------------------------- ### NewHasVector Example Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition checking if a point has the specified vector. ```go condition := qdrant.NewHasVector("image_vector") ``` -------------------------------- ### Sync Proto Definitions (Release) Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Generate client stubs from upstream Qdrant proto definitions for a release. This script uses the 'master' branch. ```bash BRANCH=master sh internal/tools/sync_proto.sh ``` -------------------------------- ### Create a Collection Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Creates a new collection with specified vector configuration. ```go err := client.CreateCollection(ctx, &qdrant.CreateCollection{ CollectionName: "documents", VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ Size: 384, Distance: qdrant.Distance_Cosine, }), }) ``` -------------------------------- ### NewGrpcClientFromConn Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Creates a gRPC client from an existing grpc.ClientConn. ```go func NewGrpcClientFromConn(conn *grpc.ClientConn) *GrpcClient ``` ```go conn, err := grpc.NewClient("localhost:6334") if err != nil { log.Fatal(err) } grpcClient := qdrant.NewGrpcClientFromConn(conn) ``` -------------------------------- ### Sync Proto Definitions (Development) Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Generate the latest client stubs from upstream Qdrant proto definitions for development. This script uses the 'dev' branch. ```bash BRANCH=dev sh internal/tools/sync_proto.sh ``` -------------------------------- ### Config Struct Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Configuration object for the Qdrant client. ```go type Config struct { Host string Port int APIKey string UseTLS bool TLSConfig *tls.Config GrpcOptions []grpc.DialOption SkipCompatibilityCheck bool PoolSize uint KeepAliveTime int KeepAliveTimeout uint RetryConfig *RetryConfig VersionCheckTimeout time.Duration Headers map[string]string } ``` -------------------------------- ### Basic Connection Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Establishes a basic connection to the Qdrant client. ```go import "github.com/qdrant/go-client/qdrant" client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, }) if err != nil { log.Fatal(err) } defer client.Close() ``` -------------------------------- ### Run Qdrant Go Integration Tests Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Execute the test suites using Testcontainers Go. This command pulls a Qdrant Docker image, so ensure Docker is running. ```bash go test -v ./... ``` -------------------------------- ### RetrievedPoint Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md A point returned from Get, Scroll, or other retrieval operations. ```go type RetrievedPoint struct { Id *PointId Vectors *VectorOutput Payload map[string]*Value ShardKey *ShardKey } ``` -------------------------------- ### Version Checking Timeout Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Sets a timeout of 30 seconds for the client-server version compatibility check. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, VersionCheckTimeout: 30 * time.Second, }) ``` -------------------------------- ### Skip Compatibility Check Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Skips the client-server version compatibility check entirely. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, SkipCompatibilityCheck: true, }) ``` -------------------------------- ### NewQueryRecommend Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for recommend operations. ```go func NewQueryRecommend(recommend *RecommendInput) *Query ``` -------------------------------- ### NewClient Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Creates a new Qdrant client with specified configuration. Manages connection pooling. ```go func NewClient(config *Config) (*Client, error) ``` -------------------------------- ### Snapshots Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the Snapshots service gRPC client. ```go func (c *GrpcClient) Snapshots() SnapshotsClient ``` -------------------------------- ### NewGrpcClient Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Creates a new gRPC client with custom configuration. ```go func NewGrpcClient(config *Config) (*GrpcClient, error) ``` -------------------------------- ### NewQueryContext Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for context operations. ```go func NewQueryContext(context *ContextInput) *Query ``` -------------------------------- ### Format Qdrant Go Code Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Apply standard Go formatting to your code using Gofmt. This ensures consistency across the project. ```bash gofmt -s -w . ``` -------------------------------- ### DefaultClient Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Creates a client with default configuration connecting to localhost:6334 without TLS. ```go func DefaultClient() (*Client, error) ``` -------------------------------- ### Qdrant Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the Qdrant service gRPC client. ```go func (c *GrpcClient) Qdrant() QdrantClient ``` -------------------------------- ### Collections Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the Collections service gRPC client. ```go func (c *GrpcClient) Collections() CollectionsClient ``` -------------------------------- ### NewQueryOrderBy Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for ordering points. ```go func NewQueryOrderBy(orderBy *OrderBy) *Query ``` -------------------------------- ### Conn Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the underlying gRPC connection. ```go func (c *GrpcClient) Conn() *grpc.ClientConn ``` -------------------------------- ### NewQueryDense Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from dense vectors. ```go func NewQueryDense(vector []float32) *Query ``` -------------------------------- ### Default TLS Configuration Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Enables secure connections using default TLS configuration. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "example.qdrant.io", Port: 6334, UseTLS: true, // Uses default TLS config with TLS 1.3 minimum }) ``` -------------------------------- ### NewQueryDiscover Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for discover operations. ```go func NewQueryDiscover(discover *DiscoverInput) *Query ``` -------------------------------- ### GetPointsClient Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the low-level gRPC client for the points service. ```go func (c *Client) GetPointsClient() PointsClient ``` -------------------------------- ### GetSnapshotsClient Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the low-level gRPC client for the snapshots service. ```go func (c *Client) GetSnapshotsClient() SnapshotsClient ``` -------------------------------- ### Custom TLS Configuration Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Configures the client with custom TLS settings, including server name and minimum TLS version. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "example.qdrant.io", Port: 6334, UseTLS: true, TLSConfig: &tls.Config{ ServerName: "example.qdrant.io", InsecureSkipVerify: false, MinVersion: tls.VersionTLS13, }, }) ``` -------------------------------- ### Lint Qdrant Go Code Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Check your code for warnings and adherence to project standards using golangci-lint. This helps maintain code quality. ```bash golangci-lint run ``` -------------------------------- ### NewWithPayloadInclude Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a WithPayloadSelector including specific fields. ```go func NewWithPayloadInclude(include ...string) *WithPayloadSelector ``` ```go selector := qdrant.NewWithPayloadInclude("name", "city") ``` -------------------------------- ### Points Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the Points service gRPC client. ```go func (c *GrpcClient) Points() PointsClient ``` -------------------------------- ### Connection Pooling Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Configures the client to maintain multiple gRPC connections for load distribution. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, PoolSize: 5, // Create 5 connections with round-robin }) ``` -------------------------------- ### GetConnection Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns one of the underlying gRPC connections from the pool. ```go func (c *Client) GetConnection() *grpc.ClientConn ``` -------------------------------- ### NewQuerySparse Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from sparse vectors. ```go func NewQuerySparse(indices []uint32, values []float32) *Query ``` -------------------------------- ### CreateFullSnapshot Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/snapshots.md Creates a snapshot of the entire storage including all collections. ```go snapshot, err := client.CreateFullSnapshot(ctx) if err != nil { log.Fatal(err) } fmt.Printf("Full snapshot created: %s\n", snapshot.Name) ``` -------------------------------- ### GetCollectionsClient Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the low-level gRPC client for the collections service. ```go func (c *Client) GetCollectionsClient() CollectionsClient ``` -------------------------------- ### NewVectorsDense Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Vectors instance for dense vectors. ```go func NewVectorsDense(vector []float32) *Vectors ``` -------------------------------- ### NewVectorInputSparse Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a VectorInput for sparse vectors. ```go func NewVectorInputSparse(indices []uint32, values []float32) *VectorInput ``` -------------------------------- ### NewVectorsSparse Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Vectors instance for sparse vectors. ```go func NewVectorsSparse(indices []uint32, values []float32) *Vectors ``` -------------------------------- ### NewQueryMulti Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from multi vectors. ```go func NewQueryMulti(vectors [][]float32) *Query ``` -------------------------------- ### NewVectorsMulti Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Vectors instance for multi vectors. ```go func NewVectorsMulti(vectors [][]float32) *Vectors ``` -------------------------------- ### GetQdrantClient Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the low-level gRPC client for the main Qdrant service. ```go func (c *Client) GetQdrantClient() QdrantClient ``` -------------------------------- ### NewVectorInputDense Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a VectorInput for dense vectors. ```go func NewVectorInputDense(vector []float32) *VectorInput ``` -------------------------------- ### SnapshotDescription Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Provides details about a snapshot, including its name, creation timestamp, and size. ```go type SnapshotDescription struct { Name string CreatedAt *timestamppb.Timestamp Size *uint64 } ``` -------------------------------- ### NewShardKeyNum Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a shard key from an unsigned integer. ```go func NewShardKeyNum(key uint64) *ShardKey ``` -------------------------------- ### NewVectorInputMulti Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a VectorInput for multi vectors. ```go func NewVectorInputMulti(vectors [][]float32) *VectorInput ``` -------------------------------- ### NewShardKey Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a shard key from a string. Alias for NewShardKeyKeyword(). ```go func NewShardKey(key string) *ShardKey ``` -------------------------------- ### GrpcClient Struct Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Lower-level gRPC client that wraps a single grpc.ClientConn and provides access to service stubs. ```go type GrpcClient struct { conn *grpc.ClientConn qdrant QdrantClient collections CollectionsClient points PointsClient snapshots SnapshotsClient } ``` -------------------------------- ### NewQuery Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from dense vectors. Alias for NewQueryDense(). ```go func NewQuery(values ...float32) *Query ``` ```go query := qdrant.NewQuery(0.1, 0.2, 0.3, 0.4) ``` -------------------------------- ### NewQueryRRF Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for Reciprocal Rank Fusion. ```go func NewQueryRRF(rrf *Rrf) *Query ``` -------------------------------- ### Custom Keepalive Configuration Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Configures custom keepalive settings with a 30-second ping interval and a 5-second timeout. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, KeepAliveTime: 30, // Ping every 30 seconds KeepAliveTimeout: 5, // Wait 5 seconds for response }) ``` -------------------------------- ### Query Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Universal query specification supporting search, recommend, discover, and more. ```go type Query struct { Variant interface{} // Nearest, Recommend, Discover, Context, etc. } ``` -------------------------------- ### Close Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Closes all underlying gRPC connections. Must be called to properly clean up resources. ```go func (c *Client) Close() error ``` -------------------------------- ### GetGrpcClient Method Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Returns the underlying gRPC client from the pool in a round-robin fashion. ```go func (c *Client) GetGrpcClient() *GrpcClient ``` -------------------------------- ### NewQueryNearest Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from a VectorInput. ```go func NewQueryNearest(nearest *VectorInput) *Query ``` -------------------------------- ### NewPointsSelectorFilter Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a points selector from a filter. ```go func NewPointsSelectorFilter(filter *Filter) *PointsSelector ``` -------------------------------- ### NewWithPayloadExclude Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a WithPayloadSelector excluding specific fields. ```go func NewWithPayloadExclude(exclude ...string) *WithPayloadSelector ``` -------------------------------- ### NewQueryID Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for nearest neighbor search from a point ID. ```go func NewQueryID(id *PointId) *Query ``` -------------------------------- ### NewVectorsMap Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Vectors instance from a map of named vectors. ```go func NewVectorsMap(vectors map[string]*Vector) *Vectors ``` ```go vectors := qdrant.NewVectorsMap(map[string]*qdrant.Vector{ "text_vector": qdrant.NewVector(0.1, 0.2, 0.3), "image_vector": qdrant.NewVector(0.4, 0.5, 0.6), }) ``` -------------------------------- ### PtrOf Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Generic helper function that returns a pointer to any value. ```go func PtrOf[T any](t T) *T ``` ```go intPtr := qdrant.PtrOf(42) boolPtr := qdrant.PtrOf(true) ``` -------------------------------- ### NewVectors Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Vectors instance for dense vectors. Alias for NewVectorsDense(). ```go func NewVectors(values ...float32) *Vectors ``` ```go vectors := qdrant.NewVectors(0.1, 0.2, 0.3, 0.4) ``` -------------------------------- ### Search Vectors Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Performs a vector similarity search within a collection. ```go results, err := client.Query(ctx, &qdrant.QueryPoints{ CollectionName: "documents", Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), Limit: 10, WithPayload: qdrant.NewWithPayload(true), }) ``` -------------------------------- ### CreateCollection Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/collections.md Creates a new collection with specified parameters including vector configuration, distance metric, and optional quantization settings. ```go func (c *Client) CreateCollection(ctx context.Context, request *CreateCollection) error ``` ```go err := client.CreateCollection(ctx, &qdrant.CreateCollection{ CollectionName: "my_collection", VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ Size: 384, Distance: qdrant.Distance_Cosine, }), }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### CreateCollection Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Defines the structure for creating a new collection in Qdrant, including vector configurations and optional settings. ```go type CreateCollection struct { CollectionName string VectorsConfig *VectorsConfig // Optional sparse vectors SparseVectorsConfig *SparseVectorConfig // Optional configuration ShardingMethod *ShardingMethod OptimizersConfig *OptimizersConfig ReplicationFactor *uint32 WriteConsistency *WriteConsistency } ``` -------------------------------- ### Insert Vectors Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Inserts points (vectors and payloads) into a collection. ```go result, err := client.Upsert(ctx, &qdrant.UpsertPoints{ CollectionName: "documents", Points: []*qdrant.PointStruct{ { Id: qdrant.NewIDNum(1), Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4), Payload: qdrant.NewValueMap(map[string]any{ "title": "Example Document", "category": "tech", }), }, }, }) ``` -------------------------------- ### Search with Filter Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Performs a vector search with an applied filter. ```go results, err := client.Query(ctx, &qdrant.QueryPoints{ CollectionName: "documents", Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), Filter: &qdrant.Filter{ Must: []*qdrant.Condition{ qdrant.NewMatch("category", "tech"), }, }, Limit: 10, WithPayload: qdrant.NewWithPayload(true), }) ``` -------------------------------- ### Configuring automatic retries with RetryConfig Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Shows how to configure the client for automatic retries on resource exhaustion errors. ```go client, err := qdrant.NewClient(&qdrant.Config{ Host: "localhost", Port: 6334, RetryConfig: &qdrant.RetryConfig{ MaxRetries: 3, BaseBackoff: 100 * time.Millisecond, MaxBackoff: 5 * time.Second, }, }) // Client automatically retries on ResourceExhausted ``` -------------------------------- ### Close Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md Closes the underlying gRPC connection. ```go func (c *GrpcClient) Close() error ``` -------------------------------- ### QueryPoints Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Request for universal query operation. ```go type QueryPoints struct { CollectionName string Query *Query Filter *Filter WithPayload *WithPayloadSelector WithVectors *WithVectorsSelector Limit uint64 Offset uint64 } ``` -------------------------------- ### NewQueryMMR Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a Query for MMR (Maximal Marginal Relevance) re-ranking. ```go func NewQueryMMR(nearest *VectorInput, mmr *Mmr) *Query ``` -------------------------------- ### NewWithPayload Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a WithPayloadSelector with payload enabled/disabled. Alias for NewWithPayloadEnable(). ```go func NewWithPayload(enable bool) *WithPayloadSelector ``` ```go selector := qdrant.NewWithPayload(true) ``` -------------------------------- ### Tag and Push Git Release Source: https://github.com/qdrant/go-client/blob/master/CONTRIBUTING.md Create a new Git tag for a release and push it to the remote repository. This action is part of the release process. ```bash git tag v1.11.0 git push --tags ``` -------------------------------- ### NewPointsSelectorIDs Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a points selector from a list of IDs. ```go func NewPointsSelectorIDs(ids []*PointId) *PointsSelector ``` -------------------------------- ### RetryConfig Struct Source: https://github.com/qdrant/go-client/blob/master/_autodocs/configuration.md Configures automatic retry behavior for transient gRPC failures. ```go type RetryConfig struct { MaxRetries uint BaseBackoff time.Duration MaxBackoff time.Duration } ``` -------------------------------- ### Client Struct Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/client.md The Client struct manages one or more gRPC connections for Qdrant. ```go type Client struct { clients []*GrpcClient next uint32 } ``` -------------------------------- ### NewID Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a point ID from a UUID string. Alias for NewIDUUID(). ```go func NewID(uuid string) *PointId ``` ```go id := qdrant.NewID("550e8400-e29b-41d4-a716-446655440000") ``` -------------------------------- ### Payload Values Conversion Source: https://github.com/qdrant/go-client/blob/master/_autodocs/README.md Shows how the client auto-converts Go types to Qdrant payload values. ```go // Auto-converts Go types to Qdrant payload values payload := qdrant.NewValueMap(map[string]any{ "title": "Document", // string "count": 42, // int64 "score": 3.14, // float64 "active": true, // bool "tags": []any{"a", "b"}, // list "metadata": map[string]any{"key": "value"}, // struct }) ``` -------------------------------- ### CollectionInfo Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Information about a collection. ```go type CollectionInfo struct { Name string Status CollectionStatus VectorsCount uint64 PointsCount uint64 VectorsConfig *VectorsConfig PayloadSchema map[string]*PayloadSchemaInfo ShardingMethod *ShardingMethod } ``` -------------------------------- ### VectorsConfig Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Vector configuration for collection. ```go type VectorsConfig struct { Config interface{} // Params or ParamsMap } ``` -------------------------------- ### Search Vectors Source: https://github.com/qdrant/go-client/blob/master/README.md Perform similarity searches on vectors, optionally with filtering conditions. ```go searchResult, err := client.Query(context.Background(), &qdrant.QueryPoints{ CollectionName: "{collection_name}", Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7), }) ``` ```go searchResult, err := 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"), }, }, WithPayload: qdrant.NewWithPayload(true), }) ``` -------------------------------- ### Error Method for QdrantError Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Returns the error as a formatted string. ```go func (e *QdrantError) Error() string ``` -------------------------------- ### AliasDescription Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Describes an alias, mapping an alias name to a collection name. ```go type AliasDescription struct { AliasName string CollectionName string } ``` -------------------------------- ### NewVectorInputID Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a VectorInput from a point ID. ```go func NewVectorInputID(id *PointId) *VectorInput ``` -------------------------------- ### NewIDNum Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a point ID from a positive integer. ```go func NewIDNum(num uint64) *PointId ``` ```go id := qdrant.NewIDNum(42) ``` -------------------------------- ### NewPointsSelector Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a points selector from IDs. Alias for NewPointsSelectorIDs(). ```go func NewPointsSelector(ids ...*PointId) *PointsSelector ``` -------------------------------- ### ListFullSnapshots Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/snapshots.md Retrieves a list of all full snapshots of the entire storage. ```go snapshots, err := client.ListFullSnapshots(ctx) if err != nil { log.Fatal(err) } for _, snapshot := range snapshots { fmt.Printf("Full snapshot: %s\n", snapshot.Name) } ``` -------------------------------- ### NewMatchTextAny Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition that matches any word in the text. ```go func NewMatchTextAny(field, textAny string) *Condition ``` -------------------------------- ### GeoBoundingBox Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Geographic bounding box. ```go type GeoBoundingBox struct { TopLeft *GeoPoint BottomRight *GeoPoint } ``` -------------------------------- ### ListAliases Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/collections.md Lists all aliases in the system. ```go aliases, err := client.ListAliases(ctx) if err != nil { log.Fatal(err) } for _, alias := range aliases { fmt.Printf("Alias: %s -> Collection: %s\n", alias.AliasName, alias.CollectionName) } ``` -------------------------------- ### BatchResult Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Contains the results for points from a single query within a batch operation. ```go type BatchResult struct { Points []*ScoredPoint } ``` -------------------------------- ### VectorInput Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Vector input for queries, supports multiple formats including cloud inference. ```go type VectorInput struct { Variant interface{} } ``` -------------------------------- ### Vector Type Source: https://github.com/qdrant/go-client/blob/master/_autodocs/types.md Low-level vector representation. ```go type Vector struct { // Dense, sparse, or multi-dense vector Vector interface{} } ``` -------------------------------- ### CreateSnapshot Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/snapshots.md Creates a snapshot of a specific collection. Snapshots are read-only copies useful for backup and restore operations. ```go snapshot, err := client.CreateSnapshot(ctx, "my_collection") if err != nil { log.Fatal(err) } fmt.Printf("Snapshot created: %s\n", snapshot.Name) ``` -------------------------------- ### Handling QdrantResourceExhaustedError with manual retries Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Demonstrates how to catch QdrantResourceExhaustedError and implement manual retry logic. ```go result, err := client.Upsert(ctx, &request) if err != nil { var resourceErr *qdrant.QdrantResourceExhaustedError if errors.As(err, &resourceErr) { fmt.Printf("Rate limited. Retry after %d seconds\n", resourceErr.RetryAfterS) time.Sleep(time.Duration(resourceErr.RetryAfterS) * time.Second) // Retry operation result, err = client.Upsert(ctx, &request) } } ``` -------------------------------- ### NewWithVectors Function Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/helpers.md Creates a WithVectorsSelector with vectors enabled/disabled. Alias for NewWithVectorsEnable(). ```go func NewWithVectors(enable bool) *WithVectorsSelector ``` -------------------------------- ### Error Method for QdrantResourceExhaustedError Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Returns the error as a formatted string. ```go func (e *QdrantResourceExhaustedError) Error() string ``` -------------------------------- ### Upsert Points Source: https://github.com/qdrant/go-client/blob/master/README.md Insert or update vectors and their associated payloads in a collection. ```go operationInfo, err := client.Upsert(context.Background(), &qdrant.UpsertPoints{ CollectionName: "{collection_name}", Points: []*qdrant.PointStruct{ { Id: qdrant.NewIDNum(1), Vectors: qdrant.NewVectors(0.05, 0.61, 0.76, 0.74), Payload: qdrant.NewValueMap(map[string]any{"city": "London"}), }, { Id: qdrant.NewIDNum(2), Vectors: qdrant.NewVectors(0.19, 0.81, 0.75, 0.11), Payload: qdrant.NewValueMap(map[string]any{"age": 32}), }, { Id: qdrant.NewIDNum(3), Vectors: qdrant.NewVectors(0.36, 0.55, 0.47, 0.94), Payload: qdrant.NewValueMap(map[string]any{"vegan": true}), }, }, }) ``` -------------------------------- ### Error Handling Pattern 3: Checking for Specific Conditions (ResourceExhaustedError) Source: https://github.com/qdrant/go-client/blob/master/_autodocs/errors.md Shows how to differentiate between QdrantResourceExhaustedError and other errors. ```go result, err := client.Upsert(ctx, &request) if err != nil { var resourceErr *qdrant.QdrantResourceExhaustedError if errors.As(err, &resourceErr) { // Handle rate limit fmt.Printf("Rate limited, retry after %d seconds\n", resourceErr.RetryAfterS) } else { // Handle other errors log.Fatal(err) } } ``` -------------------------------- ### NewMatchExceptInts Source: https://github.com/qdrant/go-client/blob/master/_autodocs/api-reference/conditions.md Creates a condition matching any value except the given integers. ```go func NewMatchExceptInts(field string, values ...int64) *Condition ```