Skip to content

Commit ebc1163

Browse files
authored
Verify library support for float16 and bfloat15 types in vector fields (#317)
* adding tests for bfloat16 * disable profile tests for 7.3.240 * remove interop
1 parent 9b05acd commit ebc1163

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

tests/NRedisStack.Tests/Search/IndexCreationTests.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using NRedisStack.Search;
33
using NRedisStack.RedisStackCommands;
44
using Xunit;
5-
using NRedisStack.Search.Literals;
65
using NetTopologySuite.Geometries;
76

87
namespace NRedisStack.Tests.Search;
@@ -123,4 +122,45 @@ public void TestEmptyFields()
123122
Assert.Equal("hashWithEmptyFields", result.Documents[0].Id);
124123

125124
}
126-
}
125+
126+
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.3.240")]
127+
public void TestCreateFloat16VectorField()
128+
{
129+
IDatabase db = redisFixture.Redis.GetDatabase();
130+
db.Execute("FLUSHALL");
131+
var ft = db.FT(2);
132+
var schema = new Schema().AddVectorField("v", Schema.VectorField.VectorAlgo.FLAT, new Dictionary<string, object>()
133+
{
134+
["TYPE"] = "FLOAT16",
135+
["DIM"] = "5",
136+
["DISTANCE_METRIC"] = "L2",
137+
}).AddVectorField("v2", Schema.VectorField.VectorAlgo.FLAT, new Dictionary<string, object>()
138+
{
139+
["TYPE"] = "BFLOAT16",
140+
["DIM"] = "4",
141+
["DISTANCE_METRIC"] = "L2",
142+
});
143+
Assert.True(ft.Create("idx", new FTCreateParams(), schema));
144+
145+
short[] vec1 = new short[] { 2, 1, 2, 2, 2 };
146+
byte[] vec1ToBytes = new byte[vec1.Length * sizeof(short)];
147+
Buffer.BlockCopy(vec1, 0, vec1ToBytes, 0, vec1ToBytes.Length);
148+
149+
short[] vec2 = new short[] { 1, 2, 2, 2 };
150+
byte[] vec2ToBytes = new byte[vec2.Length * sizeof(short)];
151+
Buffer.BlockCopy(vec2, 0, vec2ToBytes, 0, vec2ToBytes.Length);
152+
153+
var entries = new HashEntry[] { new HashEntry("v", vec1ToBytes), new HashEntry("v2", vec2ToBytes) };
154+
db.HashSet("a", entries);
155+
db.HashSet("b", entries);
156+
db.HashSet("c", entries);
157+
158+
var q = new Query("*=>[KNN 2 @v $vec]").ReturnFields("__v_score");
159+
var res = ft.Search("idx", q.AddParam("vec", vec1ToBytes));
160+
Assert.Equal(2, res.TotalResults);
161+
162+
q = new Query("*=>[KNN 2 @v2 $vec]").ReturnFields("__v_score");
163+
res = ft.Search("idx", q.AddParam("vec", vec2ToBytes));
164+
Assert.Equal(2, res.TotalResults);
165+
}
166+
}

tests/NRedisStack.Tests/Search/SearchTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,7 +2619,7 @@ public async Task getSuggestionLengthAndDeleteSuggestionAsync()
26192619
Assert.Equal(2L, await ft.SugLenAsync(key));
26202620
}
26212621

2622-
[SkipIfRedis(Is.Enterprise)]
2622+
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
26232623
public void TestProfileSearch()
26242624
{
26252625
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -2643,7 +2643,7 @@ public void TestProfileSearch()
26432643
Assert.Equal("1", iteratorsProfile["Size"].ToString());
26442644
}
26452645

2646-
[SkipIfRedis(Is.Enterprise)]
2646+
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
26472647
public async Task TestProfileSearchAsync()
26482648
{
26492649
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -2727,7 +2727,7 @@ public async Task TestProfileAsync()
27272727
Assert.Equal(2, aggregateRes.TotalResults);
27282728
}
27292729

2730-
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
2730+
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.242")]
27312731
public void TestProfileIssue306()
27322732
{
27332733
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -2757,7 +2757,7 @@ public void TestProfileIssue306()
27572757
Assert.Equal(2, aggregateRes.TotalResults);
27582758
}
27592759

2760-
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
2760+
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.242")]
27612761
public async Task TestProfileAsyncIssue306()
27622762
{
27632763
IDatabase db = redisFixture.Redis.GetDatabase();

0 commit comments

Comments
 (0)