Skip to content

Commit

Permalink
fix: When using AllMiniLML6V2 vectorizer, inference sessions would be… (
Browse files Browse the repository at this point in the history
#485)

* fix: When using AllMiniLML6V2 vectorizer, inference sessions would be created for each call to Vectorize as the field was an expression bodied member, resulting in a new creation of a Lazy instance each time.

* fix(ci): docker-compose should now be docker compose (v2)

---------

Co-authored-by: James Abbott <james.abbott@crispthinking.com>
  • Loading branch information
abbottdev and James Abbott committed Sep 25, 2024
1 parent 7a35e47 commit ef7135e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: fetch-models
run: sh fetch-models.sh
- name: execute
run: docker-compose -f ./docker/docker-compose.yaml run dotnet
run: docker compose -f ./docker/docker-compose.yaml run dotnet
6 changes: 3 additions & 3 deletions src/Redis.OM.Vectorizers.AllMiniLML6V2/SentenceVectorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class SentenceVectorizer : IVectorizer<string>

/// <inheritdoc />
public int Dim => 384;
private static Lazy<TokenizerBase> Tokenizer => new Lazy<TokenizerBase>(AllMiniLML6V2Tokenizer.Create);
private static Lazy<InferenceSession> InferenceSession => new Lazy<InferenceSession>(LoadInferenceSession);
private static readonly Lazy<TokenizerBase> Tokenizer = new(AllMiniLML6V2Tokenizer.Create);
private static readonly Lazy<InferenceSession> InferenceSession = new(LoadInferenceSession);

private static InferenceSession LoadInferenceSession()
{
Expand All @@ -40,7 +40,7 @@ public byte[] Vectorize(string obj)
return Vectorize(new[] { obj })[0].SelectMany(BitConverter.GetBytes).ToArray();
}

private static Lazy<string[]> OutputNames => new (() => InferenceSession.Value.OutputMetadata.Keys.ToArray());
private static readonly Lazy<string[]> OutputNames = new (() => InferenceSession.Value.OutputMetadata.Keys.ToArray());

/// <summary>
/// Vectorizers an array of sentences (which are vectorized individually).
Expand Down

0 comments on commit ef7135e

Please sign in to comment.