55 "strconv"
66)
77
8+ // note: the APIs is experimental and may be subject to change.
89type VectorSetCmdable interface {
910 VAdd (ctx context.Context , key , element string , val Vector ) * BoolCmd
1011 VAddWithArgs (ctx context.Context , key , element string , val Vector , addArgs * VAddArgs ) * BoolCmd
@@ -14,15 +15,16 @@ type VectorSetCmdable interface {
1415 VGetAttr (ctx context.Context , key , element string ) * StringCmd
1516 VInfo (ctx context.Context , key string ) * MapStringInterfaceCmd
1617 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
1819 VRandMember (ctx context.Context , key string ) * StringCmd
1920 VRandMemberCount (ctx context.Context , key string , count int ) * StringSliceCmd
2021 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
2224 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
2426 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
2628}
2729
2830type Vector interface {
@@ -42,7 +44,7 @@ func (v *VectorFP32) Value() []any {
4244 return []any {vectorFormatFP32 , v .Val }
4345}
4446
45- var _ Vector = & VectorFP32 {}
47+ var _ Vector = ( * VectorFP32 )( nil )
4648
4749type VectorValues struct {
4850 Val []float64
@@ -58,7 +60,7 @@ func (v *VectorValues) Value() []any {
5860 return res
5961}
6062
61- var _ Vector = & VectorValues {}
63+ var _ Vector = ( * VectorValues )( nil )
6264
6365type VectorRef struct {
6466 Name string // the name of the referent vector
@@ -68,9 +70,27 @@ func (v *VectorRef) Value() []any {
6870 return []any {"ele" , v .Name }
6971}
7072
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 )
7291
7392// `VADD key (FP32 | VALUES num) vector element`
93+ // note: the API is experimental and may be subject to change.
7494func (c cmdable ) VAdd (ctx context.Context , key , element string , val Vector ) * BoolCmd {
7595 return c .VAddWithArgs (ctx , key , element , val , & VAddArgs {})
7696}
@@ -120,6 +140,7 @@ func (v VAddArgs) appendArgs(args []any) []any {
120140}
121141
122142// `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.
123144func (c cmdable ) VAddWithArgs (ctx context.Context , key , element string , val Vector , addArgs * VAddArgs ) * BoolCmd {
124145 if addArgs == nil {
125146 addArgs = & VAddArgs {}
@@ -137,20 +158,23 @@ func (c cmdable) VAddWithArgs(ctx context.Context, key, element string, val Vect
137158}
138159
139160// `VCARD key`
161+ // note: the API is experimental and may be subject to change.
140162func (c cmdable ) VCard (ctx context.Context , key string ) * IntCmd {
141163 cmd := NewIntCmd (ctx , "vcard" , key )
142164 _ = c (ctx , cmd )
143165 return cmd
144166}
145167
146168// `VDIM key`
169+ // note: the API is experimental and may be subject to change.
147170func (c cmdable ) VDim (ctx context.Context , key string ) * IntCmd {
148171 cmd := NewIntCmd (ctx , "vdim" , key )
149172 _ = c (ctx , cmd )
150173 return cmd
151174}
152175
153176// `VEMB key element [RAW]`
177+ // note: the API is experimental and may be subject to change.
154178func (c cmdable ) VEmb (ctx context.Context , key , element string , raw bool ) * SliceCmd {
155179 args := []any {"vemb" , key , element }
156180 if raw {
@@ -162,68 +186,87 @@ func (c cmdable) VEmb(ctx context.Context, key, element string, raw bool) *Slice
162186}
163187
164188// `VGETATTR key element`
189+ // note: the API is experimental and may be subject to change.
165190func (c cmdable ) VGetAttr (ctx context.Context , key , element string ) * StringCmd {
166191 cmd := NewStringCmd (ctx , "vgetattr" , key , element )
167192 _ = c (ctx , cmd )
168193 return cmd
169194}
170195
171196// `VINFO key`
197+ // note: the API is experimental and may be subject to change.
172198func (c cmdable ) VInfo (ctx context.Context , key string ) * MapStringInterfaceCmd {
173199 cmd := NewMapStringInterfaceCmd (ctx , "vinfo" , key )
174200 _ = c (ctx , cmd )
175201 return cmd
176202}
177203
178204// `VLINKS key element`
205+ // note: the API is experimental and may be subject to change.
179206func (c cmdable ) VLinks (ctx context.Context , key , element string ) * StringSliceCmd {
180207 cmd := NewStringSliceCmd (ctx , "vlinks" , key , element )
181208 _ = c (ctx , cmd )
182209 return cmd
183210}
184211
185212// `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 {
187215 cmd := NewVectorInfoSliceCmd (ctx , "vlinks" , key , element , "withscores" )
188216 _ = c (ctx , cmd )
189217 return cmd
190218}
191219
192220// `VRANDMEMBER key`
221+ // note: the API is experimental and may be subject to change.
193222func (c cmdable ) VRandMember (ctx context.Context , key string ) * StringCmd {
194223 cmd := NewStringCmd (ctx , "vrandmember" , key )
195224 _ = c (ctx , cmd )
196225 return cmd
197226}
198227
199228// `VRANDMEMBER key [count]`
229+ // note: the API is experimental and may be subject to change.
200230func (c cmdable ) VRandMemberCount (ctx context.Context , key string , count int ) * StringSliceCmd {
201231 cmd := NewStringSliceCmd (ctx , "vrandmember" , key , count )
202232 _ = c (ctx , cmd )
203233 return cmd
204234}
205235
206236// `VREM key element`
237+ // note: the API is experimental and may be subject to change.
207238func (c cmdable ) VRem (ctx context.Context , key , element string ) * BoolCmd {
208239 cmd := NewBoolCmd (ctx , "vrem" , key , element )
209240 _ = c (ctx , cmd )
210241 return cmd
211242}
212243
213244// `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 , "" )
216257 _ = c (ctx , cmd )
217258 return cmd
218259}
219260
220261// `VSIM key (ELE | FP32 | VALUES num) (vector | element)`
262+ // note: the API is experimental and may be subject to change.
221263func (c cmdable ) VSim (ctx context.Context , key string , val Vector ) * StringSliceCmd {
222264 return c .VSimWithArgs (ctx , key , val , & VSimArgs {})
223265}
224266
225267// `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 {
227270 return c .VSimWithArgsWithScores (ctx , key , val , & VSimArgs {})
228271}
229272
@@ -265,6 +308,7 @@ func (v VSimArgs) appendArgs(args []any) []any {
265308
266309// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [COUNT num]
267310// [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.
268312func (c cmdable ) VSimWithArgs (ctx context.Context , key string , val Vector , simArgs * VSimArgs ) * StringSliceCmd {
269313 if simArgs == nil {
270314 simArgs = & VSimArgs {}
@@ -279,7 +323,8 @@ func (c cmdable) VSimWithArgs(ctx context.Context, key string, val Vector, simAr
279323
280324// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [COUNT num]
281325// [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 {
283328 if simArgs == nil {
284329 simArgs = & VSimArgs {}
285330 }
0 commit comments