From b4d395a08f4aa42b280f0269b326bd6f86516fd3 Mon Sep 17 00:00:00 2001 From: Simone Vellei Date: Sat, 25 Nov 2023 16:31:27 +0100 Subject: [PATCH] Feat Version 1.1.0 (#5) * fix indexCreate add indexDelete * fix plural * fix plural * feat: add vectors delete * feat: update vectors * Update README.md --- README.md | 22 ++++--- examples/cmd/index/create/main.go | 34 +++++++++++ examples/cmd/index/delete/main.go | 33 +++++++++++ examples/cmd/point/delete/main.go | 6 +- examples/cmd/point/search/main.go | 6 +- examples/cmd/point/upsert/main.go | 6 +- examples/cmd/vector/delete/main.go | 33 +++++++++++ examples/cmd/vector/update/main.go | 38 ++++++++++++ qdrantgo.go | 42 +++++++++++--- request/collectionDelete.go | 2 +- request/indexCreate.go | 6 +- request/indexDelete.go | 36 ++++++++++++ request/pointGet.go | 2 +- request/pointSearch.go | 61 -------------------- request/{pointDelete.go => pointsDelete.go} | 8 +-- request/pointsGet.go | 2 +- request/pointsSearch.go | 61 ++++++++++++++++++++ request/{pointUpsert.go => pointsUpsert.go} | 8 +-- request/vectorsDelete.go | 47 +++++++++++++++ request/vectorsUpdate.go | 50 ++++++++++++++++ response/indexDelete.go | 25 ++++++++ response/{pointDelete.go => pointsDelete.go} | 6 +- response/{pointSearch.go => pointsSearch.go} | 10 ++-- response/{pointUpsert.go => pointsUpsert.go} | 6 +- response/vectorsDelete.go | 25 ++++++++ response/vectorsUpdate.go | 25 ++++++++ 26 files changed, 487 insertions(+), 113 deletions(-) create mode 100644 examples/cmd/index/create/main.go create mode 100644 examples/cmd/index/delete/main.go create mode 100644 examples/cmd/vector/delete/main.go create mode 100644 examples/cmd/vector/update/main.go create mode 100644 request/indexDelete.go delete mode 100644 request/pointSearch.go rename request/{pointDelete.go => pointsDelete.go} (85%) create mode 100644 request/pointsSearch.go rename request/{pointUpsert.go => pointsUpsert.go} (85%) create mode 100644 request/vectorsDelete.go create mode 100644 request/vectorsUpdate.go create mode 100644 response/indexDelete.go rename response/{pointDelete.go => pointsDelete.go} (65%) rename response/{pointSearch.go => pointsSearch.go} (69%) rename response/{pointUpsert.go => pointsUpsert.go} (81%) create mode 100644 response/vectorsDelete.go create mode 100644 response/vectorsUpdate.go diff --git a/README.md b/README.md index ed5e95a..a927a18 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -# Unofficial Qdrant Go SDK - +# Unofficial Go client for Qdrant vector search engine [![GoDoc](https://godoc.org/github.com/henomis/qdrant-go?status.svg)](https://godoc.org/github.com/henomis/qdrant-go) [![Go Report Card](https://goreportcard.com/badge/github.com/henomis/qdrant-go)](https://goreportcard.com/report/github.com/henomis/qdrant-go) [![GitHub release](https://img.shields.io/github/release/henomis/qdrant-go.svg)](https://github.com/henomis/qdrant-go/releases) @@ -12,6 +11,7 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e ## API support ### collections + - ✅ list - ✅ create - ✅ collect info @@ -19,7 +19,7 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e - ✅ delete - ❌ update aliases - ✅ create index -- ❌ delete index +- ✅ delete index - ❌ cluster info - ❌ update cluster setup - ❌ list aliases @@ -29,14 +29,14 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e - ❌ delete snapshot - ❌ download snapshot +### points -### points - ✅ get point - ✅ get points - ✅ upsert points - ✅ delete points -- ❌ update vectors -- ❌ delete vectors +- ✅ update vectors +- ✅ delete vectors - ❌ set payload - ❌ overwrite payload - ❌ delete payload @@ -51,6 +51,7 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e - ❌ count points ### cluster + - ❌ cluster status info - ❌ tries to recover current peer Raft state - ❌ remove peer @@ -58,6 +59,7 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e - ❌ update collection cluster setup ### snapshots + - ❌ recover from uploaded snapshot - ❌ recover from snapshot - ❌ list collection snapshots @@ -70,17 +72,18 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e - ❌ download storage snapshot ### service + - ❌ collect telemetry data - ❌ collect Prometheus metrics data - ❌ set lock options - ❌ get lock options - ## Getting started ### Installation You can load qdrant-go into your project by using: + ``` go get github.com/henomis/qdrant-go ``` @@ -88,11 +91,13 @@ go get github.com/henomis/qdrant-go ### Run Qdrant You can run Qdrant using Docker: + ```shell docker run -p 6333:6333 --name qdrant --rm -v $(pwd)/config.yaml:/qdrant/config/production.yaml qdrant/qdrant ``` config.yaml file: + ```yaml service: api_key: secret-api-key @@ -104,7 +109,6 @@ Please refer to the [official documentation](https://qdrant.tech/) for more info The only thing you need to start using Qdrant's APIs is the API key. Copy and paste it in the corresponding place in the code, select the API and the parameters you want to use, and that's it. - ### Usage Please refer to the [examples folder](examples/cmd/) to see how to use the SDK. @@ -152,4 +156,4 @@ func main() { ## Who uses qdrant-go? -* [LinGoose](https://github.com/henomis/lingoose) Go framework for building awesome LLM apps \ No newline at end of file +- [LinGoose](https://github.com/henomis/lingoose) Go framework for building awesome LLM apps diff --git a/examples/cmd/index/create/main.go b/examples/cmd/index/create/main.go new file mode 100644 index 0000000..93a0a6f --- /dev/null +++ b/examples/cmd/index/create/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "context" + "fmt" + + qdrantgo "github.com/henomis/qdrant-go" + "github.com/henomis/qdrant-go/request" + "github.com/henomis/qdrant-go/response" +) + +func main() { + + client := qdrantgo.New("http://localhost:6333", "") + + wait := true + resp := &response.IndexCreate{} + err := client.IndexCreate( + context.Background(), + &request.IndexCreate{ + CollectionName: "test", + Wait: &wait, + FieldName: "test_field", + FieldSchema: "keyword", + }, + resp, + ) + if err != nil { + panic(err) + } + + fmt.Printf("resp: %#v\n", resp) + +} diff --git a/examples/cmd/index/delete/main.go b/examples/cmd/index/delete/main.go new file mode 100644 index 0000000..ab56441 --- /dev/null +++ b/examples/cmd/index/delete/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "fmt" + + qdrantgo "github.com/henomis/qdrant-go" + "github.com/henomis/qdrant-go/request" + "github.com/henomis/qdrant-go/response" +) + +func main() { + + client := qdrantgo.New("http://localhost:6333", "") + + wait := true + resp := &response.IndexDelete{} + err := client.IndexDelete( + context.Background(), + &request.IndexDelete{ + CollectionName: "test", + Wait: &wait, + FieldName: "test_field", + }, + resp, + ) + if err != nil { + panic(err) + } + + fmt.Printf("resp: %#v\n", resp) + +} diff --git a/examples/cmd/point/delete/main.go b/examples/cmd/point/delete/main.go index 5bce9b1..6ab0a3d 100644 --- a/examples/cmd/point/delete/main.go +++ b/examples/cmd/point/delete/main.go @@ -14,10 +14,10 @@ func main() { client := qdrantgo.New("http://localhost:6333", "") wait := true - resp := &response.PointDelete{} - err := client.PointDelete( + resp := &response.PointsDelete{} + err := client.PointsDelete( context.Background(), - &request.PointDelete{ + &request.PointsDelete{ CollectionName: "test", Wait: &wait, Filter: request.Filter{ diff --git a/examples/cmd/point/search/main.go b/examples/cmd/point/search/main.go index 6074d5f..db9fe4e 100644 --- a/examples/cmd/point/search/main.go +++ b/examples/cmd/point/search/main.go @@ -14,10 +14,10 @@ func main() { client := qdrantgo.New("http://localhost:6333", "") withPayload := true - resp := &response.PointSearch{} - err := client.PointSearch( + resp := &response.PointsSearch{} + err := client.PointsSearch( context.Background(), - &request.PointSearch{ + &request.PointsSearch{ CollectionName: "test", Vector: []float64{1.1, 2.2, 3.3, 4.4}, Limit: 10, diff --git a/examples/cmd/point/upsert/main.go b/examples/cmd/point/upsert/main.go index 8e1de52..80ba286 100644 --- a/examples/cmd/point/upsert/main.go +++ b/examples/cmd/point/upsert/main.go @@ -14,10 +14,10 @@ func main() { client := qdrantgo.New("http://localhost:6333", "") wait := true - resp := &response.PointUpsert{} - err := client.PointUpsert( + resp := &response.PointsUpsert{} + err := client.PointsUpsert( context.Background(), - &request.PointUpsert{ + &request.PointsUpsert{ CollectionName: "test", Wait: &wait, Points: []request.Point{ diff --git a/examples/cmd/vector/delete/main.go b/examples/cmd/vector/delete/main.go new file mode 100644 index 0000000..58c9c58 --- /dev/null +++ b/examples/cmd/vector/delete/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "fmt" + + qdrantgo "github.com/henomis/qdrant-go" + "github.com/henomis/qdrant-go/request" + "github.com/henomis/qdrant-go/response" +) + +func main() { + + client := qdrantgo.New("http://localhost:6333", "") + + wait := true + resp := &response.VectorsDelete{} + err := client.VectorsDelete( + context.Background(), + &request.VectorsDelete{ + CollectionName: "test", + Wait: &wait, + Vector: []string{"vec1"}, + }, + resp, + ) + if err != nil { + panic(err) + } + + fmt.Printf("resp: %#v\n", resp) + +} diff --git a/examples/cmd/vector/update/main.go b/examples/cmd/vector/update/main.go new file mode 100644 index 0000000..42101e6 --- /dev/null +++ b/examples/cmd/vector/update/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "fmt" + + qdrantgo "github.com/henomis/qdrant-go" + "github.com/henomis/qdrant-go/request" + "github.com/henomis/qdrant-go/response" +) + +func main() { + + client := qdrantgo.New("http://localhost:6333", "") + + wait := true + resp := &response.VectorsUpdate{} + err := client.VectorsUpdate( + context.Background(), + &request.VectorsUpdate{ + CollectionName: "test", + Wait: &wait, + Points: []request.PointVectors{ + { + ID: "45b07125-f592-414f-a9d0-160c8ecc283a", + Vector: []float64{5, 6, 7, 8}, + }, + }, + }, + resp, + ) + if err != nil { + panic(err) + } + + fmt.Printf("resp: %#v\n", resp) + +} diff --git a/qdrantgo.go b/qdrantgo.go index 5ad4ec0..6bf3df8 100644 --- a/qdrantgo.go +++ b/qdrantgo.go @@ -81,26 +81,34 @@ func (c *Client) IndexCreate( return c.restClient.Put(ctx, req, res) } -func (c *Client) PointUpsert( +func (c *Client) IndexDelete( ctx context.Context, - req *request.PointUpsert, - res *response.PointUpsert, + req *request.IndexDelete, + res *response.IndexDelete, +) error { + return c.restClient.Delete(ctx, req, res) +} + +func (c *Client) PointsUpsert( + ctx context.Context, + req *request.PointsUpsert, + res *response.PointsUpsert, ) error { return c.restClient.Put(ctx, req, res) } -func (c *Client) PointSearch( +func (c *Client) PointsSearch( ctx context.Context, - req *request.PointSearch, - res *response.PointSearch, + req *request.PointsSearch, + res *response.PointsSearch, ) error { return c.restClient.Post(ctx, req, res) } -func (c *Client) PointDelete( +func (c *Client) PointsDelete( ctx context.Context, - req *request.PointDelete, - res *response.PointDelete, + req *request.PointsDelete, + res *response.PointsDelete, ) error { return c.restClient.Post(ctx, req, res) } @@ -120,3 +128,19 @@ func (c *Client) PointsGet( ) error { return c.restClient.Post(ctx, req, res) } + +func (c *Client) VectorsUpdate( + ctx context.Context, + req *request.VectorsUpdate, + res *response.VectorsUpdate, +) error { + return c.restClient.Put(ctx, req, res) +} + +func (c *Client) VectorsDelete( + ctx context.Context, + req *request.VectorsDelete, + res *response.VectorsDelete, +) error { + return c.restClient.Post(ctx, req, res) +} diff --git a/request/collectionDelete.go b/request/collectionDelete.go index 4f85b6c..dc8aa61 100644 --- a/request/collectionDelete.go +++ b/request/collectionDelete.go @@ -13,7 +13,7 @@ type CollectionDelete struct { } func (c *CollectionDelete) Path() (string, error) { - var urlValues restclientgo.URLValues + var urlValues = restclientgo.URLValues{} urlValues.AddInt("timeout", c.Timeout) parameters := "" diff --git a/request/indexCreate.go b/request/indexCreate.go index 1f3d343..0c7d5e0 100644 --- a/request/indexCreate.go +++ b/request/indexCreate.go @@ -18,8 +18,8 @@ type IndexCreate struct { } func (c *IndexCreate) Path() (string, error) { - var urlValues restclientgo.URLValues - urlValues.AddBool("timeout", c.Wait) + var urlValues = restclientgo.URLValues{} + urlValues.AddBool("wait", c.Wait) urlValues.Add("ordering", (*string)(c.Ordering)) parameters := "" @@ -27,7 +27,7 @@ func (c *IndexCreate) Path() (string, error) { parameters = "?" + urlValues.Encode() } - return fmt.Sprintf("/collections/%s%s", c.CollectionName, parameters), nil + return fmt.Sprintf("/collections/%s/index%s", c.CollectionName, parameters), nil } func (c *IndexCreate) Encode() (io.Reader, error) { diff --git a/request/indexDelete.go b/request/indexDelete.go new file mode 100644 index 0000000..33171fd --- /dev/null +++ b/request/indexDelete.go @@ -0,0 +1,36 @@ +package request + +import ( + "fmt" + "io" + + "github.com/henomis/restclientgo" +) + +type IndexDelete struct { + CollectionName string `json:"-"` + FieldName string `json:"-"` + Wait *bool `json:"-"` + Ordering *Ordering `json:"-"` +} + +func (c *IndexDelete) Path() (string, error) { + var urlValues = restclientgo.URLValues{} + urlValues.AddBool("wait", c.Wait) + urlValues.Add("ordering", (*string)(c.Ordering)) + + parameters := "" + if len(urlValues) > 0 { + parameters = "?" + urlValues.Encode() + } + + return fmt.Sprintf("/collections/%s/index/%s%s", c.CollectionName, c.FieldName, parameters), nil +} + +func (c *IndexDelete) Encode() (io.Reader, error) { + return nil, nil +} + +func (c *IndexDelete) ContentType() string { + return "" +} diff --git a/request/pointGet.go b/request/pointGet.go index 9770411..11e7106 100644 --- a/request/pointGet.go +++ b/request/pointGet.go @@ -14,7 +14,7 @@ type PointGet struct { } func (p *PointGet) Path() (string, error) { - var urlValues restclientgo.URLValues + var urlValues = restclientgo.URLValues{} urlValues.Add("consistency", p.Consistency) parameters := "" diff --git a/request/pointSearch.go b/request/pointSearch.go deleted file mode 100644 index 69f6870..0000000 --- a/request/pointSearch.go +++ /dev/null @@ -1,61 +0,0 @@ -package request - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - - "github.com/henomis/restclientgo" -) - -type PointSearch struct { - CollectionName string `json:"-"` - Consistency *string `json:"-"` - Vector []float64 `json:"vector"` - Filter Filter `json:"filter,omitempty"` - Params *PointSearchParams `json:"params,omitempty"` - Limit int `json:"limit"` - Offset int `json:"offset"` - WithPayload *bool `json:"with_payload"` - WithVector *bool `json:"with_vector,omitempty"` - ScoreThreshold *float64 `json:"score_threshold,omitempty"` -} - -type PointSearchParams struct { - HNSWEF *int `json:"hnsw_ef,omitempty"` - Exact bool `json:"exact"` - Quantization *PointSearchParamsQuantization `json:"quantization,omitempty"` -} - -type PointSearchParamsQuantization struct { - Ignore bool `json:"ignore"` - Rescore bool `json:"rescore"` -} - -func (p *PointSearch) Path() (string, error) { - path := fmt.Sprintf("/collections/%s/points/search", p.CollectionName) - - urlValues := restclientgo.NewURLValues() - urlValues.Add("consistency", (*string)(p.Consistency)) - - urlValuesEncoded := urlValues.Encode() - if urlValuesEncoded != "" { - path = fmt.Sprintf("%s?%s", path, urlValuesEncoded) - } - - return path, nil -} - -func (p *PointSearch) Encode() (io.Reader, error) { - jsonBytes, err := json.Marshal(p) - if err != nil { - return nil, err - } - - return bytes.NewReader(jsonBytes), nil -} - -func (p *PointSearch) ContentType() string { - return "application/json" -} diff --git a/request/pointDelete.go b/request/pointsDelete.go similarity index 85% rename from request/pointDelete.go rename to request/pointsDelete.go index 2daaf34..e6ac340 100644 --- a/request/pointDelete.go +++ b/request/pointsDelete.go @@ -9,7 +9,7 @@ import ( "github.com/henomis/restclientgo" ) -type PointDelete struct { +type PointsDelete struct { CollectionName string `json:"-"` Ordering *Ordering `json:"-"` Wait *bool `json:"-"` @@ -25,7 +25,7 @@ type Filter struct { MustNot []M `json:"must_not,omitempty"` } -func (p *PointDelete) Path() (string, error) { +func (p *PointsDelete) Path() (string, error) { path := fmt.Sprintf("/collections/%s/points/delete", p.CollectionName) urlValues := restclientgo.NewURLValues() @@ -40,7 +40,7 @@ func (p *PointDelete) Path() (string, error) { return path, nil } -func (p *PointDelete) Encode() (io.Reader, error) { +func (p *PointsDelete) Encode() (io.Reader, error) { jsonBytes, err := json.Marshal(p) if err != nil { return nil, err @@ -49,6 +49,6 @@ func (p *PointDelete) Encode() (io.Reader, error) { return bytes.NewReader(jsonBytes), nil } -func (p *PointDelete) ContentType() string { +func (p *PointsDelete) ContentType() string { return "application/json" } diff --git a/request/pointsGet.go b/request/pointsGet.go index 8168b18..0ab7f0b 100644 --- a/request/pointsGet.go +++ b/request/pointsGet.go @@ -18,7 +18,7 @@ type PointsGet struct { } func (p *PointsGet) Path() (string, error) { - var urlValues restclientgo.URLValues + var urlValues = restclientgo.URLValues{} urlValues.Add("consistency", p.Consistency) parameters := "" diff --git a/request/pointsSearch.go b/request/pointsSearch.go new file mode 100644 index 0000000..67089f2 --- /dev/null +++ b/request/pointsSearch.go @@ -0,0 +1,61 @@ +package request + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/henomis/restclientgo" +) + +type PointsSearch struct { + CollectionName string `json:"-"` + Consistency *string `json:"-"` + Vector []float64 `json:"vector"` + Filter Filter `json:"filter,omitempty"` + Params *PointsSearchParams `json:"params,omitempty"` + Limit int `json:"limit"` + Offset int `json:"offset"` + WithPayload *bool `json:"with_payload"` + WithVector *bool `json:"with_vector,omitempty"` + ScoreThreshold *float64 `json:"score_threshold,omitempty"` +} + +type PointsSearchParams struct { + HNSWEF *int `json:"hnsw_ef,omitempty"` + Exact bool `json:"exact"` + Quantization *PointsSearchParamsQuantization `json:"quantization,omitempty"` +} + +type PointsSearchParamsQuantization struct { + Ignore bool `json:"ignore"` + Rescore bool `json:"rescore"` +} + +func (p *PointsSearch) Path() (string, error) { + path := fmt.Sprintf("/collections/%s/points/search", p.CollectionName) + + urlValues := restclientgo.NewURLValues() + urlValues.Add("consistency", (*string)(p.Consistency)) + + urlValuesEncoded := urlValues.Encode() + if urlValuesEncoded != "" { + path = fmt.Sprintf("%s?%s", path, urlValuesEncoded) + } + + return path, nil +} + +func (p *PointsSearch) Encode() (io.Reader, error) { + jsonBytes, err := json.Marshal(p) + if err != nil { + return nil, err + } + + return bytes.NewReader(jsonBytes), nil +} + +func (p *PointsSearch) ContentType() string { + return "application/json" +} diff --git a/request/pointUpsert.go b/request/pointsUpsert.go similarity index 85% rename from request/pointUpsert.go rename to request/pointsUpsert.go index f0e74c1..faebc23 100644 --- a/request/pointUpsert.go +++ b/request/pointsUpsert.go @@ -17,7 +17,7 @@ const ( OrderingStrong Ordering = "strong" ) -type PointUpsert struct { +type PointsUpsert struct { CollectionName string `json:"-"` Wait *bool `json:"-"` Ordering *Ordering `json:"-"` @@ -30,7 +30,7 @@ type Point struct { Payload map[string]interface{} `json:"payload,omitempty"` } -func (p *PointUpsert) Path() (string, error) { +func (p *PointsUpsert) Path() (string, error) { path := fmt.Sprintf("/collections/%s/points", p.CollectionName) urlValues := restclientgo.NewURLValues() @@ -45,7 +45,7 @@ func (p *PointUpsert) Path() (string, error) { return path, nil } -func (p *PointUpsert) Encode() (io.Reader, error) { +func (p *PointsUpsert) Encode() (io.Reader, error) { jsonBytes, err := json.Marshal(p) if err != nil { return nil, err @@ -54,6 +54,6 @@ func (p *PointUpsert) Encode() (io.Reader, error) { return bytes.NewReader(jsonBytes), nil } -func (p *PointUpsert) ContentType() string { +func (p *PointsUpsert) ContentType() string { return "application/json" } diff --git a/request/vectorsDelete.go b/request/vectorsDelete.go new file mode 100644 index 0000000..62c3b8e --- /dev/null +++ b/request/vectorsDelete.go @@ -0,0 +1,47 @@ +package request + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/henomis/restclientgo" +) + +type VectorsDelete struct { + CollectionName string `json:"-"` + Points []string `json:"points,omitempty"` + Filter Filter `json:"filter,omitempty"` + Vector []string `json:"vector"` + Wait *bool `json:"-"` + Ordering *Ordering `json:"-"` +} + +func (p *VectorsDelete) Path() (string, error) { + path := fmt.Sprintf("/collections/%s/points/vectors/delete", p.CollectionName) + + urlValues := restclientgo.NewURLValues() + urlValues.Add("ordering", (*string)(p.Ordering)) + urlValues.AddBool("wait", p.Wait) + + urlValuesEncoded := urlValues.Encode() + if urlValuesEncoded != "" { + path = fmt.Sprintf("%s?%s", path, urlValuesEncoded) + } + + return path, nil +} + +func (p *VectorsDelete) Encode() (io.Reader, error) { + jsonBytes, err := json.Marshal(p) + if err != nil { + return nil, err + } + + return bytes.NewReader(jsonBytes), nil +} + +func (p *VectorsDelete) ContentType() string { + return "application/json" +} diff --git a/request/vectorsUpdate.go b/request/vectorsUpdate.go new file mode 100644 index 0000000..685ef2d --- /dev/null +++ b/request/vectorsUpdate.go @@ -0,0 +1,50 @@ +package request + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/henomis/restclientgo" +) + +type PointVectors struct { + ID string `json:"id"` + Vector []float64 `json:"vector"` +} + +type VectorsUpdate struct { + CollectionName string `json:"-"` + Points []PointVectors `json:"points"` + Wait *bool `json:"-"` + Ordering *Ordering `json:"-"` +} + +func (p *VectorsUpdate) Path() (string, error) { + path := fmt.Sprintf("/collections/%s/points/vectors", p.CollectionName) + + urlValues := restclientgo.NewURLValues() + urlValues.Add("ordering", (*string)(p.Ordering)) + urlValues.AddBool("wait", p.Wait) + + urlValuesEncoded := urlValues.Encode() + if urlValuesEncoded != "" { + path = fmt.Sprintf("%s?%s", path, urlValuesEncoded) + } + + return path, nil +} + +func (p *VectorsUpdate) Encode() (io.Reader, error) { + jsonBytes, err := json.Marshal(p) + if err != nil { + return nil, err + } + + return bytes.NewReader(jsonBytes), nil +} + +func (p *VectorsUpdate) ContentType() string { + return "application/json" +} diff --git a/response/indexDelete.go b/response/indexDelete.go new file mode 100644 index 0000000..d263158 --- /dev/null +++ b/response/indexDelete.go @@ -0,0 +1,25 @@ +package response + +import ( + "encoding/json" + "io" +) + +type IndexDelete struct { + Response + Result OperationResult `json:"result"` +} + +func (c *IndexDelete) AcceptContentType() string { + return "application/json" +} + +func (c *IndexDelete) Decode(body io.Reader) error { + err := json.NewDecoder(body).Decode(c) + if err != nil { + return err + } + + c.Response.SetStatusMessage() + return nil +} diff --git a/response/pointDelete.go b/response/pointsDelete.go similarity index 65% rename from response/pointDelete.go rename to response/pointsDelete.go index 601e730..cd31465 100644 --- a/response/pointDelete.go +++ b/response/pointsDelete.go @@ -5,16 +5,16 @@ import ( "io" ) -type PointDelete struct { +type PointsDelete struct { Response Result OperationResult `json:"result"` } -func (p *PointDelete) AcceptContentType() string { +func (p *PointsDelete) AcceptContentType() string { return "application/json" } -func (p *PointDelete) Decode(body io.Reader) error { +func (p *PointsDelete) Decode(body io.Reader) error { err := json.NewDecoder(body).Decode(p) if err != nil { return err diff --git a/response/pointSearch.go b/response/pointsSearch.go similarity index 69% rename from response/pointSearch.go rename to response/pointsSearch.go index 30d1481..9fb8827 100644 --- a/response/pointSearch.go +++ b/response/pointsSearch.go @@ -5,12 +5,12 @@ import ( "io" ) -type PointSearch struct { +type PointsSearch struct { Response - Result []PointSearchResult `json:"result"` + Result []PointsSearchResult `json:"result"` } -type PointSearchResult struct { +type PointsSearchResult struct { ID string `json:"id"` Version uint64 `json:"version"` Score float64 `json:"score"` @@ -18,11 +18,11 @@ type PointSearchResult struct { Vector []float64 `json:"vector,omitempty"` } -func (p *PointSearch) AcceptContentType() string { +func (p *PointsSearch) AcceptContentType() string { return "application/json" } -func (p *PointSearch) Decode(body io.Reader) error { +func (p *PointsSearch) Decode(body io.Reader) error { err := json.NewDecoder(body).Decode(p) if err != nil { return err diff --git a/response/pointUpsert.go b/response/pointsUpsert.go similarity index 81% rename from response/pointUpsert.go rename to response/pointsUpsert.go index 53a73e6..032232e 100644 --- a/response/pointUpsert.go +++ b/response/pointsUpsert.go @@ -5,7 +5,7 @@ import ( "io" ) -type PointUpsert struct { +type PointsUpsert struct { Response Result OperationResult `json:"result"` } @@ -22,11 +22,11 @@ type OperationResult struct { Status OperationResultStatus `json:"status"` } -func (p *PointUpsert) AcceptContentType() string { +func (p *PointsUpsert) AcceptContentType() string { return "application/json" } -func (p *PointUpsert) Decode(body io.Reader) error { +func (p *PointsUpsert) Decode(body io.Reader) error { err := json.NewDecoder(body).Decode(p) if err != nil { return err diff --git a/response/vectorsDelete.go b/response/vectorsDelete.go new file mode 100644 index 0000000..581eb9b --- /dev/null +++ b/response/vectorsDelete.go @@ -0,0 +1,25 @@ +package response + +import ( + "encoding/json" + "io" +) + +type VectorsDelete struct { + Response + Result OperationResult `json:"result"` +} + +func (p *VectorsDelete) AcceptContentType() string { + return "application/json" +} + +func (p *VectorsDelete) Decode(body io.Reader) error { + err := json.NewDecoder(body).Decode(p) + if err != nil { + return err + } + + p.Response.SetStatusMessage() + return nil +} diff --git a/response/vectorsUpdate.go b/response/vectorsUpdate.go new file mode 100644 index 0000000..0e5022a --- /dev/null +++ b/response/vectorsUpdate.go @@ -0,0 +1,25 @@ +package response + +import ( + "encoding/json" + "io" +) + +type VectorsUpdate struct { + Response + Result OperationResult `json:"result"` +} + +func (p *VectorsUpdate) AcceptContentType() string { + return "application/json" +} + +func (p *VectorsUpdate) Decode(body io.Reader) error { + err := json.NewDecoder(body).Decode(p) + if err != nil { + return err + } + + p.Response.SetStatusMessage() + return nil +}