-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpointsSearch.go
61 lines (49 loc) · 1.63 KB
/
pointsSearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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"
}