@@ -33,6 +33,9 @@ var vectorValueType = reflect.TypeOf([]float32{})
33
33
// VectorType represents the VECTOR(N) type.
34
34
// It stores a fixed-length array of N floating point numbers.
35
35
type VectorType struct {
36
+ // The number of floats in the vector.
37
+ // If Dimensions is 0, then the type can hold a variable number of floats, but this is only used
38
+ // as the return type of some functions, and in values sent over the wire.
36
39
Dimensions int
37
40
}
38
41
@@ -99,15 +102,15 @@ func (t VectorType) Convert(ctx context.Context, v interface{}) (interface{}, sq
99
102
}
100
103
return result , sql .InRange , nil
101
104
case []float32 :
102
- if len (val ) != t .Dimensions {
105
+ if t . Dimensions != 0 && len (val ) != t .Dimensions {
103
106
return nil , sql .OutOfRange , fmt .Errorf ("VECTOR dimension mismatch: expected %d, got %d" , t .Dimensions , len (val ))
104
107
}
105
108
return val , sql .InRange , nil
106
109
case []interface {}:
107
- if len (val ) != t .Dimensions {
110
+ if t . Dimensions != 0 && len (val ) != t .Dimensions {
108
111
return nil , sql .OutOfRange , fmt .Errorf ("VECTOR dimension mismatch: expected %d, got %d" , t .Dimensions , len (val ))
109
112
}
110
- result := make ([]float32 , t . Dimensions )
113
+ result := make ([]float32 , len ( val ) )
111
114
for i , elem := range val {
112
115
switch e := elem .(type ) {
113
116
case float64 :
@@ -182,7 +185,7 @@ func (t VectorType) String() string {
182
185
183
186
// Type implements Type interface.
184
187
func (t VectorType ) Type () query.Type {
185
- return sqltypes .TypeJSON
188
+ return sqltypes .Vector
186
189
}
187
190
188
191
// ValueType implements Type interface.
0 commit comments