Skip to content

Commit

Permalink
Bugfix/vector hash idx creation (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 committed Dec 6, 2023
1 parent cf41ed7 commit c58713a
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
lfs: true
- name: fetch-models
run: sh fetch-models.sh
- name: execute
run: docker-compose -f ./docker/docker-compose.yaml run dotnet
9 changes: 9 additions & 0 deletions fetch-models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

curl -o ./src/Redis.OM.Vectorizers.AllMiniLML6V2/Resources/model.onnx https://storage.googleapis.com/slorello/model.onnx

curl -o ./src/Redis.OM.Vectorizers.AllMiniLML6V2/Resources/vocab.txt https://storage.googleapis.com/slorello/vocab.txt

curl -o ./src/Redis.OM.Vectorizers.Resnet18/Resources/ResNet18Onnx/ResNet18.onnx https://storage.googleapis.com/slorello/ResNet18.onnx

curl -o ./src/Redis.OM.Vectorizers.Resnet18/Resources/ResNetPrepOnnx/ResNetPreprocess.onnx https://storage.googleapis.com/slorello/ResNetPreprocess.onnx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Redis.OM.Vectorizers.AllMiniLML6V2</RootNamespace>
<PackageVersion>0.6.0</PackageVersion>
<Version>0.6.0</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.0</PackageReleaseNotes>
<PackageVersion>0.6.1</PackageVersion>
<Version>0.6.1</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.1</PackageReleaseNotes>
<Description>Sentence Vectorizer for Redis OM .NET using all-MiniLM-L6-v2</Description>
<Title>Redis OM all-MiniLM-L6-v2 Vectorizers</Title>
<Authors>Steve Lorello</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Redis.OM.Vectorizers.Resnet18</RootNamespace>
<PackageVersion>0.6.0</PackageVersion>
<Version>0.6.0</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.0</PackageReleaseNotes>
<PackageVersion>0.6.1</PackageVersion>
<Version>0.6.1</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.1</PackageReleaseNotes>
<Description>Resnet 18 Vectorizers for Redis OM .NET.</Description>
<Title>Redis OM Resnet 18 Vectorizers</Title>
<Authors>Steve Lorello</Authors>
Expand Down
6 changes: 3 additions & 3 deletions src/Redis.OM.Vectorizers/Redis.OM.Vectorizers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Redis.OM</RootNamespace>
<PackageVersion>0.6.0</PackageVersion>
<Version>0.6.0</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.0</PackageReleaseNotes>
<PackageVersion>0.6.1</PackageVersion>
<Version>0.6.1</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.1</PackageReleaseNotes>
<Description>Core Vectorizers for Redis OM .NET.</Description>
<Title>Redis OM Vectorizers</Title>
<Authors>Steve Lorello</Authors>
Expand Down
8 changes: 7 additions & 1 deletion src/Redis.OM/Modeling/RedisSchemaField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ internal static string[] SerializeArgs(this PropertyInfo info)
}
}

var ret = new List<string> { !string.IsNullOrEmpty(attr.PropertyName) ? $"attr.PropertyName{suffix}" : $"{info.Name}{suffix}" };
var ret = new List<string> { !string.IsNullOrEmpty(attr.PropertyName) ? $"{attr.PropertyName}{suffix}" : $"{info.Name}{suffix}" };
if (!string.IsNullOrEmpty(suffix))
{
ret.Add("AS");
ret.Add(!string.IsNullOrEmpty(attr.PropertyName) ? attr.PropertyName : info.Name);
}

var innerType = Nullable.GetUnderlyingType(info.PropertyType);
ret.AddRange(CommonSerialization(attr, innerType ?? info.PropertyType, info));
return ret.ToArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Redis.OM/Redis.OM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<RootNamespace>Redis.OM</RootNamespace>
<Nullable>enable</Nullable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PackageVersion>0.6.0</PackageVersion>
<Version>0.6.0</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.0</PackageReleaseNotes>
<PackageVersion>0.6.1</PackageVersion>
<Version>0.6.1</Version>
<PackageReleaseNotes>https://github.com/redis/redis-om-dotnet/releases/tag/v0.6.1</PackageReleaseNotes>
<Description>Object Mapping and More for Redis</Description>
<Title>Redis OM</Title>
<Authors>Steve Lorello</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/Redis.OM/RedisObjectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ private static string SendToJson(IDictionary<string, RedisReply> hash, Type t)
}

var valueStr = $"[{arrString}]";
ret += $"\"Vector\":{valueStr}}}";
ret += $"\"Vector\":{valueStr}}},";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Redis.OM.Unit.Tests;

[Document(StorageType = StorageType.Json)]
[Document]
public class HuggingFaceVectors
{
[RedisIdField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ public void ScoresOnHash()
Assert.Equal(0, res.VectorScores.NearestNeighborsScore);
}

[Fact]
public void ScoresOnHashVectorizer()
{
_connection.DropIndexAndAssociatedRecords(typeof(ObjectWithVectorHash));
_connection.CreateIndex(typeof(ObjectWithVectorHash));
var simpleHnswVector = Vector.Of(Enumerable.Range(0, 10).Select(x => (double)x).ToArray());
var simpleVectorizedVector = Vector.Of("foo");
var obj = new ObjectWithVectorHash
{
Id = "helloWorld",
SimpleHnswVector = simpleHnswVector,
SimpleVectorizedVector = simpleVectorizedVector,
};
var collection = new RedisCollection<ObjectWithVectorHash>(_connection);
collection.Insert(obj);
var res = collection.NearestNeighbors(x => x.SimpleVectorizedVector, 5, "foo").First();

Assert.Equal(0, res.VectorScores.NearestNeighborsScore);
}

[Fact]
public void HybridQueryTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void CreateIndexWithVector()
"Name", "TAG", "SEPARATOR", "|",
"Num", "NUMERIC",
"SimpleHnswVector", "VECTOR", "HNSW", "6", "TYPE", "FLOAT64", "DIM", "10", "DISTANCE_METRIC", "L2",
"SimpleVectorizedVector.Vector", "VECTOR", "FLAT", "6", "TYPE", "FLOAT32", "DIM", "30", "DISTANCE_METRIC", "L2"
"SimpleVectorizedVector.Vector", "AS", "SimpleVectorizedVector", "VECTOR", "FLAT", "6", "TYPE", "FLOAT32", "DIM", "30", "DISTANCE_METRIC", "L2"
);
}

Expand Down

0 comments on commit c58713a

Please sign in to comment.