Files
zooqueen 9e556726a6 give the module one identity, the one its own tests import
The test package would not build:

  client.DeleteVectorName undefined (type *"github.com/hanzoai/vector-go/qdrant".Client
    has no field or method DeleteVectorName)
  undefined: qdrant.DeleteVectorNameRequest

Both exist here — qdrant/points.go:259 and qdrant/points.pb.go:2876. They were
missing because go.mod still declared `module github.com/qdrant/go-client`
while the tests import github.com/hanzoai/vector-go/qdrant, so the module
listed ITSELF as a dependency at v0.1.1 and the tests type-checked against that
published release instead of the tree they sit in. Anything added since v0.1.1
was invisible to its own test suite.

The module is now named where it is published, the self-require is gone, and
the two test files still on the old path follow the other nine.

getClientVersion's packageName came along, and not for tidiness: it compares
that string to bi.Main.Path and to the dependency list to report the client
version, so leaving the old path there would have reported unknownVersion.

go build and go vet are both clean — vet compiles the test package, which is
what could not build before.
2026-08-10 22:20:42 -07:00

143 lines
4.0 KiB
Go

package qdrant
import (
"fmt"
"log/slog"
"runtime/debug"
"google.golang.org/grpc"
)
// Lower level client for Qdrant gRPC API.
type GrpcClient struct {
conn *grpc.ClientConn
// Qdrant service interface
// https://github.com/qdrant/qdrant/blob/master/lib/api/src/grpc/proto/qdrant.proto
qdrant QdrantClient
// Collections service interface
// https://github.com/qdrant/qdrant/blob/master/lib/api/src/grpc/proto/collections_service.proto
collections CollectionsClient
// Points service interface
// https://github.com/qdrant/qdrant/blob/master/lib/api/src/grpc/proto/points_service.proto
points PointsClient
// Snapshots service interface
// https://github.com/qdrant/qdrant/blob/master/lib/api/src/grpc/proto/snapshots_service.proto
snapshots SnapshotsClient
}
// Create a new gRPC client with default configuration.
func NewDefaultGrpcClient() (*GrpcClient, error) {
return NewGrpcClient(&Config{})
}
// Create a new gRPC client with custom configuration.
func NewGrpcClient(config *Config) (*GrpcClient, error) {
// We append config.GrpcOptions in the end
// so that user's explicit options take precedence
clientVersion := getClientVersion()
var grpcOptions []grpc.DialOption
grpcOptions = append(grpcOptions,
config.getTransportCreds(),
config.getMetadataInterceptor(),
config.getRateLimitInterceptor(),
grpc.WithUserAgent(fmt.Sprintf("go-client/%s", clientVersion)),
)
if config.RetryConfig != nil {
grpcOptions = append(grpcOptions,
grpc.WithChainUnaryInterceptor(config.RetryConfig.retryInterceptor()),
)
}
grpcOptions = append(grpcOptions, config.getKeepAliveParams()...)
config.GrpcOptions = append(grpcOptions, config.GrpcOptions...)
conn, err := grpc.NewClient(config.getAddr(), config.GrpcOptions...)
if err != nil {
return nil, err
}
newGrpcClientFromConn := NewGrpcClientFromConn(conn)
if !config.SkipCompatibilityCheck {
serverVersion := getServerVersion(newGrpcClientFromConn, config.getVersionCheckTimeout())
logger := slog.Default()
if serverVersion == unknownVersion {
logger.Warn("Failed to obtain server version. " +
"Unable to check client-server compatibility. " +
"Set SkipCompatibilityCheck=true to skip version check.")
} else if !IsCompatible(clientVersion, serverVersion) {
logger.Warn("Client version is not compatible with server version. "+
"Major versions should match and minor version difference must not exceed 1. "+
"Set SkipCompatibilityCheck=true to skip version check.",
"clientVersion", clientVersion, "serverVersion", serverVersion)
}
}
return newGrpcClientFromConn, nil
}
// Create a new gRPC client from existing connection.
func NewGrpcClientFromConn(conn *grpc.ClientConn) *GrpcClient {
return &GrpcClient{
conn: conn,
qdrant: NewQdrantClient(conn),
points: NewPointsClient(conn),
collections: NewCollectionsClient(conn),
snapshots: NewSnapshotsClient(conn),
}
}
// Get the underlying gRPC connection.
func (c *GrpcClient) Conn() *grpc.ClientConn {
return c.conn
}
// Get the Qdrant service interface.
func (c *GrpcClient) Qdrant() QdrantClient {
return c.qdrant
}
// Get the Collections service interface.
func (c *GrpcClient) Points() PointsClient {
return c.points
}
// Get the Points service interface.
func (c *GrpcClient) Collections() CollectionsClient {
return c.collections
}
// Get the Snapshots service interface.
func (c *GrpcClient) Snapshots() SnapshotsClient {
return c.snapshots
}
// Tears down the *grpc.ClientConn and all underlying connections.
func (c *GrpcClient) Close() error {
return c.conn.Close()
}
func getClientVersion() string {
// Must match this module's path: getClientVersion compares it against
// bi.Main.Path and the dependency list to report the client version, so a
// stale name here silently reports unknownVersion.
packageName := "github.com/hanzoai/vector-go"
bi, ok := debug.ReadBuildInfo()
if !ok {
return unknownVersion
}
if bi.Main.Path == packageName {
return bi.Main.Version
}
for _, dep := range bi.Deps {
if dep.Path == packageName {
return dep.Version
}
}
return unknownVersion
}