-
Notifications
You must be signed in to change notification settings - Fork 104
/
search.go
89 lines (76 loc) · 2.08 KB
/
search.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package vector
import (
"errors"
)
// VectorQueryCombination specifies how elements in the array are combined.
//
// # VOLATILE
//
// This API is VOLATILE and subject to change at any time.
type VectorQueryCombination string
const (
VectorQueryCombinationNotSet VectorQueryCombination = ""
VectorQueryCombinationAnd VectorQueryCombination = "and"
VectorQueryCombinationOr VectorQueryCombination = "or"
)
// SearchOptions specifies the options available to vector Search.
//
// # VOLATILE
//
// This API is VOLATILE and subject to change at any time.
type SearchOptions struct {
VectorQueryCombination VectorQueryCombination
}
// Search specifies a vector Search.
//
// # VOLATILE
//
// This API is VOLATILE and subject to change at any time.
type Search struct {
queries []*Query
vectorQueryCombination VectorQueryCombination
}
// NewSearch constructs a new vector Search.
//
// # VOLATILE
//
// This API is VOLATILE and subject to change at any time.
func NewSearch(queries []*Query, opts *SearchOptions) *Search {
if opts == nil {
opts = &SearchOptions{}
}
return &Search{
queries: queries,
vectorQueryCombination: opts.VectorQueryCombination,
}
}
// InternalSearch is used for internal functionality.
// Internal: This should never be used and is not supported.
type InternalSearch struct {
Queries []InternalQuery
VectorQueryCombination VectorQueryCombination
}
// Internal is used for internal functionality.
// Internal: This should never be used and is not supported.
func (s *Search) Internal() InternalSearch {
queries := make([]InternalQuery, len(s.queries))
for i, query := range s.queries {
queries[i] = query.Internal()
}
return InternalSearch{
Queries: queries,
VectorQueryCombination: s.vectorQueryCombination,
}
}
// Validate verifies that settings in the search (including all queries) are valid.
func (s InternalSearch) Validate() error {
if len(s.Queries) == 0 {
return errors.New("queries cannot be empty")
}
for _, query := range s.Queries {
if err := query.Validate(); err != nil {
return err
}
}
return nil
}