Skip to content

Commit 9ffa677

Browse files
authored
Fix: parse VECTOR field when loading schema to IndexInfo struct (#162)
1 parent d24ebe6 commit 9ffa677

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

redisearch/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ func (info *IndexInfo) loadSchema(values []interface{}, options []string) {
552552
tfOptions.Weight = float32(weight64)
553553
}
554554
f.Options = tfOptions
555+
case "VECTOR":
556+
f.Type = VectorField
557+
f.Options = VectorFieldOptions{}
555558
}
556559
sc = sc.AddField(f)
557560
}

redisearch/client_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ func TestClient_ListIndex(t *testing.T) {
11671167
assert.Equal(t, "index-list-test", indexes[0])
11681168
}
11691169

1170-
func TestClient_Info(t *testing.T) {
1170+
func TestClient_InfoSchemaFields(t *testing.T) {
11711171
c := createClient("index-info")
11721172
flush(c)
11731173
_, err := c.getRediSearchVersion()
@@ -1179,7 +1179,12 @@ func TestClient_Info(t *testing.T) {
11791179
opt.NoFrequencies = true
11801180
opt.NoOffsetVectors = true
11811181
schema := NewSchema(opt).
1182-
AddField(NewNumericField("age"))
1182+
AddField(NewNumericField("age")).
1183+
AddField(NewVectorFieldOptions("vec", VectorFieldOptions{Algorithm: Flat, Attributes: map[string]interface{}{
1184+
"TYPE": "FLOAT32",
1185+
"DIM": 2,
1186+
"DISTANCE_METRIC": "L2",
1187+
}}))
11831188

11841189
// Add the Index Definition
11851190
err = c.CreateIndexWithIndexDefinition(schema, NewIndexDefinition())
@@ -1190,8 +1195,8 @@ func TestClient_Info(t *testing.T) {
11901195
assert.True(t, info.Schema.Options.NoFieldFlags)
11911196
assert.True(t, info.Schema.Options.NoFrequencies)
11921197
assert.True(t, info.Schema.Options.NoOffsetVectors)
1193-
assert.Equal(t, 1, len(info.Schema.Fields))
1194-
expectedField := Field{
1198+
assert.Equal(t, 2, len(info.Schema.Fields))
1199+
expNumericField := Field{
11951200
Name: "age",
11961201
Type: NumericField,
11971202
Sortable: false,
@@ -1201,5 +1206,15 @@ func TestClient_Info(t *testing.T) {
12011206
As: "",
12021207
},
12031208
}
1204-
assert.True(t, reflect.DeepEqual(expectedField, info.Schema.Fields[0]))
1209+
assert.True(t, reflect.DeepEqual(expNumericField, info.Schema.Fields[0]))
1210+
expVectorField := Field{
1211+
Name: "vec",
1212+
Type: VectorField,
1213+
Sortable: false,
1214+
Options: VectorFieldOptions{
1215+
Algorithm: "",
1216+
Attributes: nil,
1217+
},
1218+
}
1219+
assert.True(t, reflect.DeepEqual(expVectorField, info.Schema.Fields[1]))
12051220
}

0 commit comments

Comments
 (0)