Skip to content

Commit 30b9d4d

Browse files
committed
add vector test for default dialect
1 parent b54b71a commit 30b9d4d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: search_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,30 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
911911
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
912912
})
913913

914+
It("should FTCreate VECTOR with default dialect", Label("search", "ftcreate"), func() {
915+
hnswOptions := &redis.FTHNSWOptions{Type: "FLOAT32", Dim: 2, DistanceMetric: "L2"}
916+
val, err := client.FTCreate(ctx, "idx1",
917+
&redis.FTCreateOptions{},
918+
&redis.FieldSchema{FieldName: "v", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptions}}).Result()
919+
Expect(err).NotTo(HaveOccurred())
920+
Expect(val).To(BeEquivalentTo("OK"))
921+
WaitForIndexing(client, "idx1")
922+
923+
client.HSet(ctx, "a", "v", "aaaaaaaa")
924+
client.HSet(ctx, "b", "v", "aaaabaaa")
925+
client.HSet(ctx, "c", "v", "aaaaabaa")
926+
927+
searchOptions := &redis.FTSearchOptions{
928+
Return: []redis.FTSearchReturn{{FieldName: "__v_score"}},
929+
SortBy: []redis.FTSearchSortBy{{FieldName: "__v_score", Asc: true}},
930+
Params: map[string]interface{}{"vec": "aaaaaaaa"},
931+
}
932+
res, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 2 @v $vec]", searchOptions).Result()
933+
Expect(err).NotTo(HaveOccurred())
934+
Expect(res.Docs[0].ID).To(BeEquivalentTo("a"))
935+
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
936+
})
937+
914938
It("should FTCreate and FTSearch text params", Label("search", "ftcreate", "ftsearch"), func() {
915939
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "name", FieldType: redis.SearchFieldTypeText}).Result()
916940
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)