diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0f8319..b61bd7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,10 @@ -name: Go CI +name: Go Tests on: push: - branches: [ master, dev ] + branches: + - master pull_request: - branches: [ '**' ] jobs: build: @@ -19,6 +19,9 @@ jobs: with: go-version-file: ./go.mod + - name: Get + run: go get ./... + - name: Build run: go build ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..7e79f3a --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,23 @@ +name: golangci-lint +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 39ba9ea..c3c2fc5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -122,12 +122,7 @@ linters-settings: # Default: [] disable: - fieldalignment # too strict - # Settings per analyzer. - settings: - shadow: - # Whether to be strict about shadowing; can be noisy. - # Default: false - strict: true + - shadow # too noisy inamedparam: # Skips check for interface methods with only a single parameter. @@ -245,7 +240,6 @@ linters: - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations - goprintffuncname # checks that printf-like functions are named with f at the end - - gosec # inspects source code for security problems - intrange # finds places where for loops could make use of an integer range - lll # reports long lines - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) @@ -342,6 +336,5 @@ issues: - dupl - funlen - goconst - - gosec - noctx - wrapcheck \ No newline at end of file diff --git a/examples/authentication/main.go b/examples/authentication/main.go index 5fe2f4b..a1311a3 100644 --- a/examples/authentication/main.go +++ b/examples/authentication/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/qdrant/go-client-v2/qdrant" + "github.com/qdrant/go-client/qdrant" ) func main() { diff --git a/examples/main.go b/examples/main.go index ef377bf..e6f92fa 100644 --- a/examples/main.go +++ b/examples/main.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/qdrant/go-client-v2/qdrant" + "github.com/qdrant/go-client/qdrant" ) var ( @@ -71,7 +71,7 @@ func main() { waitUpsert := true upsertPoints := []*qdrant.PointStruct{ { - Id: qdrant.NewPointIDNum(1), + Id: qdrant.NewIDNum(1), Vectors: qdrant.NewVectors(0.05, 0.61, 0.76, 0.74), Payload: qdrant.NewValueMap(map[string]any{ "city": "Berlin", @@ -81,7 +81,7 @@ func main() { }), }, { - Id: qdrant.NewPointIDNum(2), + Id: qdrant.NewIDNum(2), Vectors: qdrant.NewVectors(0.19, 0.81, 0.75, 0.11), Payload: qdrant.NewValueMap(map[string]any{ "city": "Berlin", @@ -89,14 +89,14 @@ func main() { }), }, { - Id: qdrant.NewPointIDNum(3), + Id: qdrant.NewIDNum(3), Vectors: qdrant.NewVectors(0.36, 0.55, 0.47, 0.94), Payload: qdrant.NewValueMap(map[string]any{ "city": []any{"Berlin", "London"}, }), }, { - Id: qdrant.NewPointID("58384991-3295-4e21-b711-fd3b94fa73e3"), + Id: qdrant.NewID("58384991-3295-4e21-b711-fd3b94fa73e3"), Vectors: qdrant.NewVectors(0.35, 0.08, 0.11, 0.44), Payload: qdrant.NewValueMap(map[string]any{ "bool": true, @@ -119,8 +119,8 @@ func main() { points, err := client.Get(ctx, &qdrant.GetPoints{ CollectionName: collectionName, Ids: []*qdrant.PointId{ - qdrant.NewPointIDNum(1), - qdrant.NewPointIDNum(2), + qdrant.NewIDNum(1), + qdrant.NewIDNum(2), }, }) if err != nil { diff --git a/go.mod b/go.mod index edff2f9..5d2574e 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,68 @@ -module github.com/qdrant/go-client-v2 +module github.com/qdrant/go-client go 1.22.2 require ( + github.com/stretchr/testify v1.9.0 + github.com/testcontainers/testcontainers-go v0.33.0 google.golang.org/grpc v1.66.0 google.golang.org/protobuf v1.34.2 ) require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/containerd/containerd v1.7.18 // indirect + github.com/containerd/log v0.1.0 // indirect + github.com/containerd/platforms v0.2.1 // indirect + github.com/cpuguy83/dockercfg v0.3.1 // indirect + github.com/creack/pty v1.1.21 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/distribution/reference v0.6.0 // indirect + github.com/docker/docker v27.1.1+incompatible // indirect + github.com/docker/go-connections v0.5.0 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/klauspost/compress v1.17.4 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/patternmatcher v0.6.0 // indirect + github.com/moby/sys/sequential v0.5.0 // indirect + github.com/moby/sys/user v0.1.0 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/shirou/gopsutil/v3 v3.23.12 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/sdk v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect + golang.org/x/time v0.3.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c8afdf6..985a296 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,193 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao= +github.com/containerd/containerd v1.7.18/go.mod h1:IYEk9/IO6wAPUz2bCMVUbsfXjzw5UNP5fLz4PsUygQ4= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= +github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= +github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= +github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY= +github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= +github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= +github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= +github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= +github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= +github.com/shirou/gopsutil/v3 v3.23.12/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/testcontainers/testcontainers-go v0.33.0 h1:zJS9PfXYT5O0ZFXM2xxXfk4J5UMw/kRiISng037Gxdw= +github.com/testcontainers/testcontainers-go v0.33.0/go.mod h1:W80YpTa8D5C3Yy16icheD01UTDu+LmXIA2Keo+jWtT8= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 h1:digkEZCJWobwBqMwC0cwCq8/wkkRy/OowZg5OArWZrM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0/go.mod h1:/OpE/y70qVkndM0TrxT4KBoN3RsFZP0QaofcfYrj76I= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= +go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 h1:vlzZttNJGVqTsRFU9AmdnrcO1Znh8Ew9kCD//yjigk0= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 h1:+rdxYoE3E5htTEWIe15GlN6IfvbURM//Jt0mmkmm6ZU= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117/go.mod h1:OimBR/bc1wPO9iV4NC2bpyjy3VnAwZh5EBPQdtaE5oo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/qdrant/collections.go b/qdrant/collections.go index c62da09..c8c1fa1 100644 --- a/qdrant/collections.go +++ b/qdrant/collections.go @@ -2,6 +2,7 @@ package qdrant import ( "context" + "errors" ) // Checks the existence of a collection. @@ -103,12 +104,15 @@ func (c *Client) UpdateCollection(ctx context.Context, request *UpdateCollection // Returns: // - error: An error if the operation fails. func (c *Client) DeleteCollection(ctx context.Context, collectionName string) error { - _, err := c.GetCollectionsClient().Delete(ctx, &DeleteCollection{ + res, err := c.GetCollectionsClient().Delete(ctx, &DeleteCollection{ CollectionName: collectionName, }) if err != nil { return newQdrantErr(err, "DeleteCollection", collectionName) } + if !res.GetResult() { + return newQdrantErr(errors.New("failed to delete collection"), "DeleteCollection", collectionName) + } return nil } @@ -212,7 +216,7 @@ func (c *Client) ListCollectionAliases(ctx context.Context, collectionName strin } var aliases []string for _, alias := range resp.GetAliases() { - aliases = append(aliases, alias.GetCollectionName()) + aliases = append(aliases, alias.GetAliasName()) } return aliases, nil } diff --git a/qdrant/error.go b/qdrant/error.go index 5a32ef8..469364b 100644 --- a/qdrant/error.go +++ b/qdrant/error.go @@ -5,29 +5,29 @@ import ( "strings" ) -//nolint:revive // The linter says qdrant.QdrantErr stutters, but it's an apt name. -type QdrantErr struct { +//nolint:revive // The linter says qdrant.QdrantError stutters, but it's an apt name. +type QdrantError struct { operationName string context string err error } -// Error returns the error as string -func (e *QdrantErr) Error() string { +// Error returns the error as string. +func (e *QdrantError) Error() string { if e.context == "" { return fmt.Sprintf("%s() failed: %v", e.operationName, e.err) } return fmt.Sprintf("%s() failed: %s: %v", e.operationName, e.context, e.err) } -// Unwrap returns the inner error -func (e *QdrantErr) Unwrap() error { +// Unwrap returns the inner error. +func (e *QdrantError) Unwrap() error { return e.err } -func newQdrantErr(err error, operationName string, contexts ...string) *QdrantErr { +func newQdrantErr(err error, operationName string, contexts ...string) *QdrantError { combinedContext := strings.Join(contexts, ": ") - return &QdrantErr{ + return &QdrantError{ operationName: operationName, err: err, context: combinedContext, diff --git a/qdrant/oneof_factory.go b/qdrant/oneof_factory.go index cbc9b16..a39f345 100644 --- a/qdrant/oneof_factory.go +++ b/qdrant/oneof_factory.go @@ -283,13 +283,13 @@ func NewReadConsistencyFactor(readConsistencyFactor uint64) *ReadConsistency { } // Creates a *PointId instance from a UUID string. -// This is an alias for NewPointIDUUID(). -func NewPointID(uuid string) *PointId { - return NewPointIDUUID(uuid) +// Same as NewIDUUID(). +func NewID(uuid string) *PointId { + return NewIDUUID(uuid) } // Creates a *PointId instance from a UUID string. -func NewPointIDUUID(uuid string) *PointId { +func NewIDUUID(uuid string) *PointId { return &PointId{ PointIdOptions: &PointId_Uuid{ Uuid: uuid, @@ -298,7 +298,7 @@ func NewPointIDUUID(uuid string) *PointId { } // Creates a *PointId instance from a positive integer. -func NewPointIDNum(num uint64) *PointId { +func NewIDNum(num uint64) *PointId { return &PointId{ PointIdOptions: &PointId_Num{ Num: num, diff --git a/qdrant/qdrant.go b/qdrant/qdrant.go index 8a7242d..8bdb2e8 100644 --- a/qdrant/qdrant.go +++ b/qdrant/qdrant.go @@ -4,7 +4,7 @@ import ( "context" ) -// Check liveliness of the service +// Check liveliness of the service. func (c *Client) HealthCheck(ctx context.Context) (*HealthCheckReply, error) { resp, err := c.GetQdrantClient().HealthCheck(ctx, &HealthCheckRequest{}) if err != nil { diff --git a/qdrant_test/collections_test.go b/qdrant_test/collections_test.go new file mode 100644 index 0000000..7ec0d5b --- /dev/null +++ b/qdrant_test/collections_test.go @@ -0,0 +1,188 @@ +package qdrant_test + +import ( + "context" + "testing" + + "github.com/qdrant/go-client/qdrant" + "github.com/stretchr/testify/require" +) + +func TestCollectionsClient(t *testing.T) { + collectionName := t.Name() + vectorSize := uint64(384) + distance := qdrant.Distance_Cosine + apiKey := "" + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + + container, err := distributedQdrant(ctx, apiKey) + require.NoError(t, err) + + err = container.Start(ctx) + require.NoError(t, err) + + t.Cleanup(func() { + err := container.Terminate(ctx) + require.NoError(t, err) + }) + host, err := container.Host(ctx) + require.NoError(t, err) + + port, err := container.MappedPort(ctx, "6334/tcp") + require.NoError(t, err) + + client, err := qdrant.NewClient(&qdrant.Config{ + Host: host, + Port: port.Int(), + APIKey: apiKey, + }) + require.NoError(t, err) + + t.Run("CreateCollection", func(t *testing.T) { + err := client.CreateCollection(ctx, &qdrant.CreateCollection{ + CollectionName: collectionName, + VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ + Size: vectorSize, + Distance: distance, + }), + ShardingMethod: qdrant.ShardingMethod_Custom.Enum(), + }) + require.NoError(t, err) + + _, err = client.GetCollection(ctx, collectionName) + require.NoError(t, err) + }) + + t.Run("CollectionExists", func(t *testing.T) { + exists, err := client.CollectionExists(ctx, collectionName) + require.NoError(t, err) + require.True(t, exists) + }) + + t.Run("GetCollection", func(t *testing.T) { + collInfo, err := client.GetCollection(ctx, collectionName) + require.NoError(t, err) + require.Zero(t, collInfo.GetPointsCount()) + }) + + t.Run("ListCollections", func(t *testing.T) { + collections, err := client.ListCollections(ctx) + require.NoError(t, err) + require.Contains(t, collections, collectionName) + }) + + t.Run("UpdateCollection", func(t *testing.T) { + threshold := uint64(1000) + err := client.UpdateCollection(ctx, &qdrant.UpdateCollection{ + CollectionName: collectionName, + OptimizersConfig: &qdrant.OptimizersConfigDiff{ + IndexingThreshold: &threshold, + }, + }) + require.NoError(t, err) + + collInfo, err := client.GetCollection(ctx, collectionName) + require.NoError(t, err) + require.Equal(t, threshold, collInfo.GetConfig().GetOptimizerConfig().GetIndexingThreshold()) + }) + + t.Run("AliasOperations", func(t *testing.T) { + aliasName := "test_alias" + newAliasName := "new_test_alias" + + t.Run("CreateAlias", func(t *testing.T) { + err := client.CreateAlias(ctx, aliasName, collectionName) + require.NoError(t, err) + + aliases, err := client.ListCollectionAliases(ctx, collectionName) + require.NoError(t, err) + require.Contains(t, aliases, aliasName) + }) + + t.Run("ListCollectionAliases", func(t *testing.T) { + aliases, err := client.ListCollectionAliases(ctx, collectionName) + require.NoError(t, err) + require.Contains(t, aliases, aliasName) + }) + + t.Run("ListAliases", func(t *testing.T) { + allAliases, err := client.ListAliases(ctx) + require.NoError(t, err) + require.NotEmpty(t, allAliases) + }) + + t.Run("RenameAlias", func(t *testing.T) { + err := client.RenameAlias(ctx, aliasName, newAliasName) + require.NoError(t, err) + + aliases, err := client.ListCollectionAliases(ctx, collectionName) + require.NoError(t, err) + require.Contains(t, aliases, newAliasName) + require.NotContains(t, aliases, aliasName) + }) + + t.Run("DeleteAlias", func(t *testing.T) { + err := client.DeleteAlias(ctx, newAliasName) + require.NoError(t, err) + + aliases, err := client.ListCollectionAliases(ctx, collectionName) + require.NoError(t, err) + require.NotContains(t, aliases, newAliasName) + }) + }) + + t.Run("ShardKeyOperations", func(t *testing.T) { + shardKey := "test_shard_key" + + t.Run("CreateShardKey", func(t *testing.T) { + err := client.CreateShardKey(ctx, collectionName, &qdrant.CreateShardKey{ + ShardKey: qdrant.NewShardKey(shardKey), + }) + require.NoError(t, err) + }) + + t.Run("DeleteShardKey", func(t *testing.T) { + err := client.DeleteShardKey(ctx, collectionName, &qdrant.DeleteShardKey{ + ShardKey: qdrant.NewShardKey(shardKey), + }) + require.NoError(t, err) + }) + }) + + t.Run("DeleteCollection", func(t *testing.T) { + err := client.DeleteCollection(ctx, collectionName) + require.NoError(t, err) + + exists, err := client.CollectionExists(ctx, collectionName) + require.NoError(t, err) + require.False(t, exists) + }) + + t.Run("CreateCollectionWithInvalidParams", func(t *testing.T) { + err := client.CreateCollection(ctx, &qdrant.CreateCollection{ + CollectionName: "", + VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ + Size: 0, + Distance: qdrant.Distance_Cosine, + }), + }) + require.Error(t, err) + }) + + t.Run("UpdateNonExistentCollection", func(t *testing.T) { + err := client.UpdateCollection(ctx, &qdrant.UpdateCollection{ + CollectionName: "non_existent_collection", + OptimizersConfig: &qdrant.OptimizersConfigDiff{ + IndexingThreshold: new(uint64), + }, + }) + require.Error(t, err) + }) + + t.Run("DeleteNonExistentCollection", func(t *testing.T) { + err := client.DeleteCollection(ctx, "non_existent_collection") + require.Error(t, err) + }) +} diff --git a/qdrant_test/image_test.go b/qdrant_test/image_test.go new file mode 100644 index 0000000..b1787e5 --- /dev/null +++ b/qdrant_test/image_test.go @@ -0,0 +1,51 @@ +package qdrant_test + +import ( + "context" + "time" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" +) + +const TestImage string = "qdrant/qdrant:v1.11.3" + +// We use an instance with distributed mode enabled +// to test methods like CreateShardKey(), DeleteShardKey(). +func distributedQdrant(ctx context.Context, apiKey string) (testcontainers.Container, error) { + req := testcontainers.ContainerRequest{ + Image: TestImage, + ExposedPorts: []string{"6334/tcp"}, + Env: map[string]string{ + "QDRANT__CLUSTER__ENABLED": "true", + "QDRANT__SERVICE__API_KEY": apiKey, + }, + Cmd: []string{"./qdrant", "--uri", "http://qdrant_node_1:6335"}, + WaitingFor: wait.ForAll( + wait.ForListeningPort("6334/tcp").WithStartupTimeout(5 * time.Second), + ), + } + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ + ContainerRequest: req, + }) + + return container, err +} + +func standaloneQdrant(ctx context.Context, apiKey string) (testcontainers.Container, error) { + req := testcontainers.ContainerRequest{ + Image: TestImage, + ExposedPorts: []string{"6334/tcp"}, + Env: map[string]string{ + "QDRANT__SERVICE__API_KEY": apiKey, + }, + WaitingFor: wait.ForAll( + wait.ForListeningPort("6334/tcp").WithStartupTimeout(5 * time.Second), + ), + } + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ + ContainerRequest: req, + }) + + return container, err +} diff --git a/qdrant_test/points_test.go b/qdrant_test/points_test.go new file mode 100644 index 0000000..7879add --- /dev/null +++ b/qdrant_test/points_test.go @@ -0,0 +1,297 @@ +package qdrant_test + +import ( + "context" + "testing" + + "github.com/qdrant/go-client/qdrant" + "github.com/stretchr/testify/require" +) + +func TestPointsClient(t *testing.T) { + collectionName := t.Name() + vectorSize := uint64(4) + distance := qdrant.Distance_Cosine + apiKey := "" + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + + container, err := standaloneQdrant(ctx, apiKey) + require.NoError(t, err) + + err = container.Start(ctx) + require.NoError(t, err) + + t.Cleanup(func() { + err := container.Terminate(ctx) + require.NoError(t, err) + }) + host, err := container.Host(ctx) + require.NoError(t, err) + + port, err := container.MappedPort(ctx, "6334/tcp") + require.NoError(t, err) + + client, err := qdrant.NewClient(&qdrant.Config{ + Host: host, + Port: port.Int(), + APIKey: apiKey, + }) + require.NoError(t, err) + + err = client.CreateCollection(ctx, &qdrant.CreateCollection{ + CollectionName: collectionName, + VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ + Size: vectorSize, + Distance: distance, + }), + }) + require.NoError(t, err) + + testPointID := qdrant.NewID("ed7ac159-d8a7-41fb-9da3-66a14916330f") + wait := true + + t.Run("UpsertPoints", func(t *testing.T) { + points := []*qdrant.PointStruct{ + { + Id: testPointID, + Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4), + }, + } + res, err := client.Upsert(ctx, &qdrant.UpsertPoints{ + CollectionName: collectionName, + Points: points, + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + + // Test with invalid vector size + points[0].Vectors = qdrant.NewVectors(0.1, 0.2) + res, err = client.Upsert(ctx, &qdrant.UpsertPoints{ + CollectionName: collectionName, + Points: points, + Wait: &wait, + }) + require.Error(t, err) + require.Nil(t, res) + }) + + t.Run("GetPoints", func(t *testing.T) { + points, err := client.Get(ctx, &qdrant.GetPoints{ + CollectionName: collectionName, + Ids: []*qdrant.PointId{ + testPointID, + }, + }) + require.NoError(t, err) + require.Len(t, points, 1) + + // Test with non-existent point ID + points, err = client.Get(ctx, &qdrant.GetPoints{ + CollectionName: collectionName, + Ids: []*qdrant.PointId{ + qdrant.NewIDNum(423), + }, + }) + require.NoError(t, err) + require.Empty(t, points) + }) + + t.Run("CountPoints", func(t *testing.T) { + count, err := client.Count(ctx, &qdrant.CountPoints{ + CollectionName: collectionName, + }) + require.NoError(t, err) + require.Equal(t, uint64(1), count) + }) + + t.Run("ScrollPoints", func(t *testing.T) { + points, err := client.Scroll(ctx, &qdrant.ScrollPoints{ + CollectionName: collectionName, + }) + require.NoError(t, err) + require.Len(t, points, 1) + }) + + t.Run("UpdateVectors", func(t *testing.T) { + points := []*qdrant.PointVectors{ + { + Id: testPointID, + Vectors: qdrant.NewVectors(0.4, 0.5, 0.6, 0.7), + }, + } + res, err := client.UpdateVectors(ctx, &qdrant.UpdatePointVectors{ + CollectionName: collectionName, + Points: points, + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + + // Test with invalid vector size + points[0].Vectors = qdrant.NewVectors(0.1, 0.2) + res, err = client.UpdateVectors(ctx, &qdrant.UpdatePointVectors{ + CollectionName: collectionName, + Points: points, + Wait: &wait, + }) + require.Error(t, err) + require.Nil(t, res) + }) + + t.Run("QueryPoints", func(t *testing.T) { + res, err := client.Query(ctx, &qdrant.QueryPoints{ + CollectionName: collectionName, + Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), + }) + require.NoError(t, err) + require.Len(t, res, 1) + + // Test with invalid query vector size + res, err = client.Query(ctx, &qdrant.QueryPoints{ + CollectionName: collectionName, + Query: qdrant.NewQuery(0.1, 0.2), + }) + require.Error(t, err) + require.Nil(t, res) + }) + + t.Run("QueryBatchPoints", func(t *testing.T) { + res, err := client.QueryBatch(ctx, &qdrant.QueryBatchPoints{ + CollectionName: collectionName, + QueryPoints: []*qdrant.QueryPoints{ + { + CollectionName: collectionName, + Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), + }, + }, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("QueryGroups", func(t *testing.T) { + groups, err := client.QueryGroups(ctx, &qdrant.QueryPointGroups{ + CollectionName: collectionName, + Query: qdrant.NewQuery(0.1, 0.2, 0.3, 0.4), + GroupBy: "key", + }) + require.NoError(t, err) + require.Empty(t, groups) + }) + + t.Run("DeleteVectors", func(t *testing.T) { + res, err := client.DeleteVectors(ctx, &qdrant.DeletePointVectors{ + CollectionName: collectionName, + Vectors: &qdrant.VectorsSelector{ + // Delete the default/unnamed vector that we're using + Names: []string{""}, + }, + PointsSelector: qdrant.NewPointsSelector(testPointID), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("SetPayload", func(t *testing.T) { + res, err := client.SetPayload(ctx, &qdrant.SetPayloadPoints{ + CollectionName: collectionName, + PointsSelector: qdrant.NewPointsSelector(testPointID), + Payload: qdrant.NewValueMap(map[string]any{ + "key": "value", + "key_2": 32, + "key_3": false, + }), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("OverwritePayload", func(t *testing.T) { + res, err := client.OverwritePayload(ctx, &qdrant.SetPayloadPoints{ + CollectionName: collectionName, + PointsSelector: qdrant.NewPointsSelector(testPointID), + Payload: qdrant.NewValueMap(map[string]any{ + "key": 10, + }), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("DeletePayload", func(t *testing.T) { + res, err := client.DeletePayload(ctx, &qdrant.DeletePayloadPoints{ + CollectionName: collectionName, + PointsSelector: qdrant.NewPointsSelector(testPointID), + Keys: []string{"key"}, + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("ClearPayload", func(t *testing.T) { + res, err := client.ClearPayload(ctx, &qdrant.ClearPayloadPoints{ + CollectionName: collectionName, + Points: qdrant.NewPointsSelector(testPointID), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("CreateFieldIndex", func(t *testing.T) { + res, err := client.CreateFieldIndex(ctx, &qdrant.CreateFieldIndexCollection{ + CollectionName: collectionName, + FieldName: "key", + FieldType: qdrant.FieldType_FieldTypeKeyword.Enum(), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("DeleteFieldIndex", func(t *testing.T) { + res, err := client.DeleteFieldIndex(ctx, &qdrant.DeleteFieldIndexCollection{ + CollectionName: collectionName, + FieldName: "key", + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("UpdateBatch", func(t *testing.T) { + ops := []*qdrant.PointsUpdateOperation{ + qdrant.NewPointsUpdateDeletePayload(&qdrant.PointsUpdateOperation_DeletePayload{ + Keys: []string{"key"}, + PointsSelector: qdrant.NewPointsSelector(testPointID), + }), + } + res, err := client.UpdateBatch(ctx, &qdrant.UpdateBatchPoints{ + CollectionName: collectionName, + Operations: ops, + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + t.Run("DeletePoints", func(t *testing.T) { + res, err := client.Delete(ctx, &qdrant.DeletePoints{ + CollectionName: collectionName, + Points: qdrant.NewPointsSelector(testPointID), + Wait: &wait, + }) + require.NoError(t, err) + require.NotNil(t, res) + }) + + err = client.DeleteCollection(ctx, collectionName) + require.NoError(t, err) +} diff --git a/qdrant_test/qdrant_test.go b/qdrant_test/qdrant_test.go new file mode 100644 index 0000000..646b99d --- /dev/null +++ b/qdrant_test/qdrant_test.go @@ -0,0 +1,43 @@ +package qdrant_test + +import ( + "context" + "testing" + + "github.com/qdrant/go-client/qdrant" + "github.com/stretchr/testify/require" +) + +func TestHealthCheck(t *testing.T) { + apiKey := "" + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + + container, err := standaloneQdrant(ctx, apiKey) + require.NoError(t, err) + + err = container.Start(ctx) + require.NoError(t, err) + + t.Cleanup(func() { + err := container.Terminate(ctx) + require.NoError(t, err) + }) + host, err := container.Host(ctx) + require.NoError(t, err) + + port, err := container.MappedPort(ctx, "6334/tcp") + require.NoError(t, err) + + client, err := qdrant.NewClient(&qdrant.Config{ + Host: host, + Port: port.Int(), + APIKey: apiKey, + }) + require.NoError(t, err) + + resp, err := client.HealthCheck(ctx) + require.NoError(t, err) + require.NotNil(t, resp) +} diff --git a/qdrant_test/snapshots_test.go b/qdrant_test/snapshots_test.go new file mode 100644 index 0000000..b11533f --- /dev/null +++ b/qdrant_test/snapshots_test.go @@ -0,0 +1,94 @@ +package qdrant_test + +import ( + "context" + "testing" + + "github.com/qdrant/go-client/qdrant" + "github.com/stretchr/testify/require" +) + +func TestSnapshotsClient(t *testing.T) { + collectionName := t.Name() + apiKey := "" + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + + container, err := standaloneQdrant(ctx, apiKey) + require.NoError(t, err) + + err = container.Start(ctx) + require.NoError(t, err) + + t.Cleanup(func() { + err := container.Terminate(ctx) + require.NoError(t, err) + }) + host, err := container.Host(ctx) + require.NoError(t, err) + + port, err := container.MappedPort(ctx, "6334/tcp") + require.NoError(t, err) + + client, err := qdrant.NewClient(&qdrant.Config{ + Host: host, + Port: port.Int(), + APIKey: apiKey, + }) + require.NoError(t, err) + + err = client.CreateCollection(ctx, &qdrant.CreateCollection{ + CollectionName: collectionName, + VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{ + Size: 4, + Distance: qdrant.Distance_Cosine, + }), + }) + require.NoError(t, err) + + t.Run("CreateSnapshot", func(t *testing.T) { + snapshot, err := client.CreateSnapshot(ctx, collectionName) + require.NoError(t, err) + require.NotNil(t, snapshot) + }) + + t.Run("ListSnapshots", func(t *testing.T) { + snapshots, err := client.ListSnapshots(ctx, collectionName) + require.NoError(t, err) + require.NotEmpty(t, snapshots) + }) + + t.Run("DeleteSnapshot", func(t *testing.T) { + snapshots, err := client.ListSnapshots(ctx, collectionName) + require.NoError(t, err) + require.NotEmpty(t, snapshots) + + err = client.DeleteSnapshot(ctx, collectionName, snapshots[0].GetName()) + require.NoError(t, err) + }) + + t.Run("CreateFullSnapshot", func(t *testing.T) { + snapshot, err := client.CreateFullSnapshot(ctx) + require.NoError(t, err) + require.NotNil(t, snapshot) + }) + + t.Run("ListFullSnapshots", func(t *testing.T) { + snapshots, err := client.ListFullSnapshots(ctx) + require.NoError(t, err) + require.NotEmpty(t, snapshots) + }) + + t.Run("DeleteFullSnapshot", func(t *testing.T) { + snapshots, err := client.ListFullSnapshots(ctx) + require.NoError(t, err) + require.NotEmpty(t, snapshots) + + err = client.DeleteFullSnapshot(ctx, snapshots[0].GetName()) + require.NoError(t, err) + }) + + err = client.DeleteCollection(ctx, collectionName) + require.NoError(t, err) +}