5
5
"strconv"
6
6
)
7
7
8
+ // note: the APIs is experimental and may be subject to change.
8
9
type VectorSetCmdable interface {
9
10
VAdd (ctx context.Context , key , element string , val Vector ) * BoolCmd
10
11
VAddWithArgs (ctx context.Context , key , element string , val Vector , addArgs * VAddArgs ) * BoolCmd
@@ -14,15 +15,16 @@ type VectorSetCmdable interface {
14
15
VGetAttr (ctx context.Context , key , element string ) * StringCmd
15
16
VInfo (ctx context.Context , key string ) * MapStringInterfaceCmd
16
17
VLinks (ctx context.Context , key , element string ) * StringSliceCmd
17
- VLinksWithScores (ctx context.Context , key , element string ) * VectorInfoSliceCmd
18
+ VLinksWithScores (ctx context.Context , key , element string ) * VectorScoreSliceCmd
18
19
VRandMember (ctx context.Context , key string ) * StringCmd
19
20
VRandMemberCount (ctx context.Context , key string , count int ) * StringSliceCmd
20
21
VRem (ctx context.Context , key , element string ) * BoolCmd
21
- VSetAttr (ctx context.Context , key , element , attr string ) * BoolCmd
22
+ VSetAttr (ctx context.Context , key , element string , attr VectorAttributeMarshaller ) * BoolCmd
23
+ VRemAttr (ctx context.Context , key , element string ) * BoolCmd
22
24
VSim (ctx context.Context , key string , val Vector ) * StringSliceCmd
23
- VSimWithScores (ctx context.Context , key string , val Vector ) * VectorInfoSliceCmd
25
+ VSimWithScores (ctx context.Context , key string , val Vector ) * VectorScoreSliceCmd
24
26
VSimWithArgs (ctx context.Context , key string , val Vector , args * VSimArgs ) * StringSliceCmd
25
- VSimWithArgsWithScores (ctx context.Context , key string , val Vector , args * VSimArgs ) * VectorInfoSliceCmd
27
+ VSimWithArgsWithScores (ctx context.Context , key string , val Vector , args * VSimArgs ) * VectorScoreSliceCmd
26
28
}
27
29
28
30
type Vector interface {
@@ -42,7 +44,7 @@ func (v *VectorFP32) Value() []any {
42
44
return []any {vectorFormatFP32 , v .Val }
43
45
}
44
46
45
- var _ Vector = & VectorFP32 {}
47
+ var _ Vector = ( * VectorFP32 )( nil )
46
48
47
49
type VectorValues struct {
48
50
Val []float64
@@ -58,7 +60,7 @@ func (v *VectorValues) Value() []any {
58
60
return res
59
61
}
60
62
61
- var _ Vector = & VectorValues {}
63
+ var _ Vector = ( * VectorValues )( nil )
62
64
63
65
type VectorRef struct {
64
66
Name string // the name of the referent vector
@@ -68,9 +70,27 @@ func (v *VectorRef) Value() []any {
68
70
return []any {"ele" , v .Name }
69
71
}
70
72
71
- var _ Vector = & VectorRef {}
73
+ var _ Vector = (* VectorRef )(nil )
74
+
75
+ type VectorScore struct {
76
+ Name string
77
+ Score float64
78
+ }
79
+
80
+ type VectorAttributeMarshaller interface {
81
+ Marshall () string
82
+ }
83
+
84
+ type VectorAttributeRawString string
85
+
86
+ func (a * VectorAttributeRawString ) Marshall () string {
87
+ return string (* a )
88
+ }
89
+
90
+ var _ VectorAttributeMarshaller = (* VectorAttributeRawString )(nil )
72
91
73
92
// `VADD key (FP32 | VALUES num) vector element`
93
+ // note: the API is experimental and may be subject to change.
74
94
func (c cmdable ) VAdd (ctx context.Context , key , element string , val Vector ) * BoolCmd {
75
95
return c .VAddWithArgs (ctx , key , element , val , & VAddArgs {})
76
96
}
@@ -120,6 +140,7 @@ func (v VAddArgs) appendArgs(args []any) []any {
120
140
}
121
141
122
142
// `VADD key [REDUCE dim] (FP32 | VALUES num) vector element [CAS] [NOQUANT | Q8 | BIN] [EF build-exploration-factor] [SETATTR attributes] [M numlinks]`
143
+ // note: the API is experimental and may be subject to change.
123
144
func (c cmdable ) VAddWithArgs (ctx context.Context , key , element string , val Vector , addArgs * VAddArgs ) * BoolCmd {
124
145
if addArgs == nil {
125
146
addArgs = & VAddArgs {}
@@ -137,20 +158,23 @@ func (c cmdable) VAddWithArgs(ctx context.Context, key, element string, val Vect
137
158
}
138
159
139
160
// `VCARD key`
161
+ // note: the API is experimental and may be subject to change.
140
162
func (c cmdable ) VCard (ctx context.Context , key string ) * IntCmd {
141
163
cmd := NewIntCmd (ctx , "vcard" , key )
142
164
_ = c (ctx , cmd )
143
165
return cmd
144
166
}
145
167
146
168
// `VDIM key`
169
+ // note: the API is experimental and may be subject to change.
147
170
func (c cmdable ) VDim (ctx context.Context , key string ) * IntCmd {
148
171
cmd := NewIntCmd (ctx , "vdim" , key )
149
172
_ = c (ctx , cmd )
150
173
return cmd
151
174
}
152
175
153
176
// `VEMB key element [RAW]`
177
+ // note: the API is experimental and may be subject to change.
154
178
func (c cmdable ) VEmb (ctx context.Context , key , element string , raw bool ) * SliceCmd {
155
179
args := []any {"vemb" , key , element }
156
180
if raw {
@@ -162,68 +186,87 @@ func (c cmdable) VEmb(ctx context.Context, key, element string, raw bool) *Slice
162
186
}
163
187
164
188
// `VGETATTR key element`
189
+ // note: the API is experimental and may be subject to change.
165
190
func (c cmdable ) VGetAttr (ctx context.Context , key , element string ) * StringCmd {
166
191
cmd := NewStringCmd (ctx , "vgetattr" , key , element )
167
192
_ = c (ctx , cmd )
168
193
return cmd
169
194
}
170
195
171
196
// `VINFO key`
197
+ // note: the API is experimental and may be subject to change.
172
198
func (c cmdable ) VInfo (ctx context.Context , key string ) * MapStringInterfaceCmd {
173
199
cmd := NewMapStringInterfaceCmd (ctx , "vinfo" , key )
174
200
_ = c (ctx , cmd )
175
201
return cmd
176
202
}
177
203
178
204
// `VLINKS key element`
205
+ // note: the API is experimental and may be subject to change.
179
206
func (c cmdable ) VLinks (ctx context.Context , key , element string ) * StringSliceCmd {
180
207
cmd := NewStringSliceCmd (ctx , "vlinks" , key , element )
181
208
_ = c (ctx , cmd )
182
209
return cmd
183
210
}
184
211
185
212
// `VLINKS key element WITHSCORES`
186
- func (c cmdable ) VLinksWithScores (ctx context.Context , key , element string ) * VectorInfoSliceCmd {
213
+ // note: the API is experimental and may be subject to change.
214
+ func (c cmdable ) VLinksWithScores (ctx context.Context , key , element string ) * VectorScoreSliceCmd {
187
215
cmd := NewVectorInfoSliceCmd (ctx , "vlinks" , key , element , "withscores" )
188
216
_ = c (ctx , cmd )
189
217
return cmd
190
218
}
191
219
192
220
// `VRANDMEMBER key`
221
+ // note: the API is experimental and may be subject to change.
193
222
func (c cmdable ) VRandMember (ctx context.Context , key string ) * StringCmd {
194
223
cmd := NewStringCmd (ctx , "vrandmember" , key )
195
224
_ = c (ctx , cmd )
196
225
return cmd
197
226
}
198
227
199
228
// `VRANDMEMBER key [count]`
229
+ // note: the API is experimental and may be subject to change.
200
230
func (c cmdable ) VRandMemberCount (ctx context.Context , key string , count int ) * StringSliceCmd {
201
231
cmd := NewStringSliceCmd (ctx , "vrandmember" , key , count )
202
232
_ = c (ctx , cmd )
203
233
return cmd
204
234
}
205
235
206
236
// `VREM key element`
237
+ // note: the API is experimental and may be subject to change.
207
238
func (c cmdable ) VRem (ctx context.Context , key , element string ) * BoolCmd {
208
239
cmd := NewBoolCmd (ctx , "vrem" , key , element )
209
240
_ = c (ctx , cmd )
210
241
return cmd
211
242
}
212
243
213
244
// `VSETATTR key element "{ JSON obj }"`
214
- func (c cmdable ) VSetAttr (ctx context.Context , key , element , attr string ) * BoolCmd {
215
- cmd := NewBoolCmd (ctx , "vsetattr" , key , element , attr )
245
+ // note: the API is experimental and may be subject to change.
246
+ func (c cmdable ) VSetAttr (ctx context.Context , key , element string , attr VectorAttributeMarshaller ) * BoolCmd {
247
+ cmd := NewBoolCmd (ctx , "vsetattr" , key , element , attr .Marshall ())
248
+ _ = c (ctx , cmd )
249
+ return cmd
250
+ }
251
+
252
+ // `VREMATTR` removes attributes on a vector set element.
253
+ // is equal to `VSETATTR key element ""`
254
+ // note: the API is experimental and may be subject to change.
255
+ func (c cmdable ) VRemAttr (ctx context.Context , key , element string ) * BoolCmd {
256
+ cmd := NewBoolCmd (ctx , "vsetattr" , key , element , "" )
216
257
_ = c (ctx , cmd )
217
258
return cmd
218
259
}
219
260
220
261
// `VSIM key (ELE | FP32 | VALUES num) (vector | element)`
262
+ // note: the API is experimental and may be subject to change.
221
263
func (c cmdable ) VSim (ctx context.Context , key string , val Vector ) * StringSliceCmd {
222
264
return c .VSimWithArgs (ctx , key , val , & VSimArgs {})
223
265
}
224
266
225
267
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) WITHSCORES`
226
- func (c cmdable ) VSimWithScores (ctx context.Context , key string , val Vector ) * VectorInfoSliceCmd {
268
+ // note: the API is experimental and may be subject to change.
269
+ func (c cmdable ) VSimWithScores (ctx context.Context , key string , val Vector ) * VectorScoreSliceCmd {
227
270
return c .VSimWithArgsWithScores (ctx , key , val , & VSimArgs {})
228
271
}
229
272
@@ -265,6 +308,7 @@ func (v VSimArgs) appendArgs(args []any) []any {
265
308
266
309
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [COUNT num]
267
310
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
311
+ // note: the API is experimental and may be subject to change.
268
312
func (c cmdable ) VSimWithArgs (ctx context.Context , key string , val Vector , simArgs * VSimArgs ) * StringSliceCmd {
269
313
if simArgs == nil {
270
314
simArgs = & VSimArgs {}
@@ -279,7 +323,8 @@ func (c cmdable) VSimWithArgs(ctx context.Context, key string, val Vector, simAr
279
323
280
324
// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [COUNT num]
281
325
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
282
- func (c cmdable ) VSimWithArgsWithScores (ctx context.Context , key string , val Vector , simArgs * VSimArgs ) * VectorInfoSliceCmd {
326
+ // note: the API is experimental and may be subject to change.
327
+ func (c cmdable ) VSimWithArgsWithScores (ctx context.Context , key string , val Vector , simArgs * VSimArgs ) * VectorScoreSliceCmd {
283
328
if simArgs == nil {
284
329
simArgs = & VSimArgs {}
285
330
}
0 commit comments