Skip to content

Commit 7e92eb3

Browse files
authored
Wrong argument count in VectorField (#72)
Fix VectorField Count
1 parent af283a2 commit 7e92eb3

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/NRedisStack/Search/Schema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ internal override void AddFieldTypeArgs(List<object> args)
223223
args.Add(Algorithm.ToString());
224224
if (Attributes != null)
225225
{
226-
args.Add(Attributes.Count());
226+
args.Add(Attributes.Count() * 2);
227227

228228
foreach (var attribute in Attributes)
229229
{

tests/NRedisStack.Tests/Search/SearchTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ public void TestFieldsCommandBuilder()
18061806
"vec",
18071807
"VECTOR",
18081808
"FLAT",
1809-
"1",
1809+
"2",
18101810
"dim",
18111811
"10"
18121812
};
@@ -1876,6 +1876,40 @@ public async Task Test_ListAsync()
18761876
Assert.Equal(await ft._ListAsync(), new RedisResult[] { });
18771877
}
18781878

1879+
[Fact]
1880+
public async Task TestVectorCount_Issue70()
1881+
{
1882+
var schema = new Schema().AddVectorField("fieldTest", Schema.VectorField.VectorAlgo.HNSW, new Dictionary<string, object>()
1883+
{
1884+
["TYPE"] = "FLOAT32",
1885+
["DIM"] = "128",
1886+
["DISTANCE_METRIC"] = "COSINE"
1887+
});
1888+
1889+
var actual = SearchCommandBuilder.Create("test", new FTCreateParams(), schema);
1890+
var expected = new List<object>()
1891+
{
1892+
"test",
1893+
"SCHEMA",
1894+
"fieldTest",
1895+
"VECTOR",
1896+
"HNSW",
1897+
"6",
1898+
"TYPE",
1899+
"FLOAT32",
1900+
"DIM",
1901+
"128",
1902+
"DISTANCE_METRIC",
1903+
"COSINE"
1904+
};
1905+
Assert.Equal("FT.CREATE", actual.Command);
1906+
for (int i = 0; i < actual.Args.Length; i++)
1907+
{
1908+
Assert.Equal(expected[i].ToString(), actual.Args[i].ToString());
1909+
}
1910+
Assert.Equal(expected.Count(), actual.Args.Length);
1911+
}
1912+
18791913
[Fact]
18801914
public void TestModulePrefixs1()
18811915
{

0 commit comments

Comments
 (0)