Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify library support for float16 and bfloat15 types in vector fields #317

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions tests/NRedisStack.Tests/Search/IndexCreationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NRedisStack.Search;
using NRedisStack.RedisStackCommands;
using Xunit;
using NRedisStack.Search.Literals;
using NetTopologySuite.Geometries;

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

}
}

[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.3.240")]
public void TestCreateFloat16VectorField()
{
IDatabase db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");
var ft = db.FT(2);
var schema = new Schema().AddVectorField("v", Schema.VectorField.VectorAlgo.FLAT, new Dictionary<string, object>()
{
["TYPE"] = "FLOAT16",
["DIM"] = "5",
["DISTANCE_METRIC"] = "L2",
}).AddVectorField("v2", Schema.VectorField.VectorAlgo.FLAT, new Dictionary<string, object>()
{
["TYPE"] = "BFLOAT16",
["DIM"] = "4",
["DISTANCE_METRIC"] = "L2",
});
Assert.True(ft.Create("idx", new FTCreateParams(), schema));

short[] vec1 = new short[] { 2, 1, 2, 2, 2 };
byte[] vec1ToBytes = new byte[vec1.Length * sizeof(short)];
Buffer.BlockCopy(vec1, 0, vec1ToBytes, 0, vec1ToBytes.Length);

short[] vec2 = new short[] { 1, 2, 2, 2 };
byte[] vec2ToBytes = new byte[vec2.Length * sizeof(short)];
Buffer.BlockCopy(vec2, 0, vec2ToBytes, 0, vec2ToBytes.Length);

var entries = new HashEntry[] { new HashEntry("v", vec1ToBytes), new HashEntry("v2", vec2ToBytes) };
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", vec1ToBytes));
Assert.Equal(2, res.TotalResults);

q = new Query("*=>[KNN 2 @v2 $vec]").ReturnFields("__v_score");
res = ft.Search("idx", q.AddParam("vec", vec2ToBytes));
Assert.Equal(2, res.TotalResults);
}
}
8 changes: 4 additions & 4 deletions tests/NRedisStack.Tests/Search/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ public async Task getSuggestionLengthAndDeleteSuggestionAsync()
Assert.Equal(2L, await ft.SugLenAsync(key));
}

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

[SkipIfRedis(Is.Enterprise)]
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
public async Task TestProfileSearchAsync()
{
IDatabase db = redisFixture.Redis.GetDatabase();
Expand Down Expand Up @@ -2727,7 +2727,7 @@ public async Task TestProfileAsync()
Assert.Equal(2, aggregateRes.TotalResults);
}

[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.242")]
public void TestProfileIssue306()
{
IDatabase db = redisFixture.Redis.GetDatabase();
Expand Down Expand Up @@ -2757,7 +2757,7 @@ public void TestProfileIssue306()
Assert.Equal(2, aggregateRes.TotalResults);
}

[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.242")]
public async Task TestProfileAsyncIssue306()
{
IDatabase db = redisFixture.Redis.GetDatabase();
Expand Down
Loading