diff --git a/src/NRedisStack/Search/Schema.cs b/src/NRedisStack/Search/Schema.cs index abecb187..56b3c84e 100644 --- a/src/NRedisStack/Search/Schema.cs +++ b/src/NRedisStack/Search/Schema.cs @@ -223,7 +223,7 @@ internal override void AddFieldTypeArgs(List args) args.Add(Algorithm.ToString()); if (Attributes != null) { - args.Add(Attributes.Count()); + args.Add(Attributes.Count() * 2); foreach (var attribute in Attributes) { diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index fcdf95f8..e5d0c653 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1806,7 +1806,7 @@ public void TestFieldsCommandBuilder() "vec", "VECTOR", "FLAT", - "1", + "2", "dim", "10" }; @@ -1876,6 +1876,40 @@ public async Task Test_ListAsync() Assert.Equal(await ft._ListAsync(), new RedisResult[] { }); } + [Fact] + public async Task TestVectorCount_Issue70() + { + var schema = new Schema().AddVectorField("fieldTest", Schema.VectorField.VectorAlgo.HNSW, new Dictionary() + { + ["TYPE"] = "FLOAT32", + ["DIM"] = "128", + ["DISTANCE_METRIC"] = "COSINE" + }); + + var actual = SearchCommandBuilder.Create("test", new FTCreateParams(), schema); + var expected = new List() + { + "test", + "SCHEMA", + "fieldTest", + "VECTOR", + "HNSW", + "6", + "TYPE", + "FLOAT32", + "DIM", + "128", + "DISTANCE_METRIC", + "COSINE" + }; + Assert.Equal("FT.CREATE", actual.Command); + for (int i = 0; i < actual.Args.Length; i++) + { + Assert.Equal(expected[i].ToString(), actual.Args[i].ToString()); + } + Assert.Equal(expected.Count(), actual.Args.Length); + } + [Fact] public void TestModulePrefixs1() {