From 07e3614785ff67f053d1b15d7d7324c3f44b1f1f Mon Sep 17 00:00:00 2001 From: atakavci Date: Tue, 18 Feb 2025 16:47:54 +0300 Subject: [PATCH] test with INT8 and UINT8 vector types --- .../Search/IndexCreationTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/NRedisStack.Tests/Search/IndexCreationTests.cs b/tests/NRedisStack.Tests/Search/IndexCreationTests.cs index 0db286ef..0b7f2aa5 100644 --- a/tests/NRedisStack.Tests/Search/IndexCreationTests.cs +++ b/tests/NRedisStack.Tests/Search/IndexCreationTests.cs @@ -166,4 +166,40 @@ public void TestCreateFloat16VectorField(string endpointId) res = ft.Search("idx", q.AddParam("vec", vec2ToBytes)); Assert.Equal(2, res.TotalResults); } + + [SkipIfRedis(Comparison.LessThan, "7.9.0")] + [MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))] + public void TestCreateInt8VectorField(string endpointId) + { + IDatabase db = GetCleanDatabase(endpointId); + var ft = db.FT(2); + var schema = new Schema().AddVectorField("v", Schema.VectorField.VectorAlgo.FLAT, new Dictionary() + { + ["TYPE"] = "INT8", + ["DIM"] = "5", + ["DISTANCE_METRIC"] = "L2", + }).AddVectorField("v2", Schema.VectorField.VectorAlgo.FLAT, new Dictionary() + { + ["TYPE"] = "UINT8", + ["DIM"] = "4", + ["DISTANCE_METRIC"] = "L2", + }); + Assert.True(ft.Create("idx", new FTCreateParams(), schema)); + + byte[] vec1 = new byte[] { 2, 1, 2, 2, 2 }; + byte[] vec2 = new byte[] { 1, 2, 2, 2 }; + + var entries = new HashEntry[] { new HashEntry("v", vec1), new HashEntry("v2", vec2) }; + db.HashSet("a", entries); + db.HashSet("b", entries); + db.HashSet("c", entries); + + var q = new Query("*=>[KNN 2 @v $vec]").ReturnFields("__v_score"); + var res = ft.Search("idx", q.AddParam("vec", vec1)); + Assert.Equal(2, res.TotalResults); + + q = new Query("*=>[KNN 2 @v2 $vec]").ReturnFields("__v_score"); + res = ft.Search("idx", q.AddParam("vec", vec2)); + Assert.Equal(2, res.TotalResults); + } } \ No newline at end of file