SentenceTransformersCSharp 1.0.2

dotnet add package SentenceTransformersCSharp --version 1.0.2
                    
NuGet\Install-Package SentenceTransformersCSharp -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SentenceTransformersCSharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SentenceTransformersCSharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="SentenceTransformersCSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SentenceTransformersCSharp --version 1.0.2
                    
#r "nuget: SentenceTransformersCSharp, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SentenceTransformersCSharp@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SentenceTransformersCSharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=SentenceTransformersCSharp&version=1.0.2
                    
Install as a Cake Tool

SentenceTransformersCSharp

A .NET Framework 4.6.1 compatible implementation of Sentence Transformers All-MiniLM-L6-v2, supporting .NET Framework 4.6.1+, .NET Standard 2.0, and .NET Standard 2.1.

About This Project

This library provides a C# implementation of the All-MiniLM-L6-v2 sentence transformer model with full support for legacy .NET Framework environments. It includes comprehensive helper utilities and documentation for resolving common ONNX Runtime issues in .NET Framework 4.6.1+ applications.

Inspiration

This project is inspired by the original AllMiniLML6v2Sharp by ksanman, but has been completely rewritten and enhanced for .NET Framework 4.6.1 compatibility while maintaining API compatibility.

Key Features

  • ✅ Full .NET Framework 4.6.1 compatibility
  • ✅ .NET Standard 2.0 and 2.1 support
  • ✅ Includes tokenizer and ONNX model
  • ✅ ONNX Runtime initialization helpers for legacy environments
  • ✅ Comprehensive documentation for resolving common issues
  • ✅ Backward compatible with original API

Target Frameworks

  • .NET Framework 4.6.1+
  • .NET Standard 2.0
  • .NET Standard 2.1
  • .NET Core 2.0+
  • .NET 5.0+

NuGet Package

Package: SentenceTransformersCSharp
Original Package: AllMiniLML6v2Sharp

The Nuget does not include the onnx model or the vocab.txt. These can be found on Hugging Face (See tested models below). The Embedder looks for the default model.onnx and vocab.txt files in the .\model folder. You may use a custom onnx model or custom vocab as well.

How to use

  • Single Sentence
var sentence = "This is an example sentence";
using var embedder = new AllMiniLmL6V2Embedder();
var embedding = embedder.GenerateEmbedding(sentence);
  • Multiple Sentences
string[] sentences = ["This is an example sentence", "Here is another"];
using var embedder = new AllMiniLmL6V2Embedder();
var embeddings = model.GenerateEmbeddings(sentences);
  • Custom All-MiniLM-L6-v2 onnx model
var sentence = "This is an example sentence";
using var embedder = new AllMiniLmL6V2Embedder(modelPath: "path/to/model.onnx");
var embedding = embedder.GenerateEmbedding(sentence);
  • Custom vocab
var sentence = "This is an example sentence";
BertTokenizer tokenizer = new("path/to/vocab.txt");
using var embedder = new AllMiniLmL6V2Embedder(tokenizer: tokenizer);
var embedding = embedder.GenerateEmbedding(sentence);
  • Custom Tokenizer
var sentence = "This is an example sentence";
ITokenizer tokenizer = new CustomTokenizer();
using var embedder = new AllMiniLmL6V2Embedder(tokenizer: tokenizer);
var embedding = embedder.GenerateEmbedding(sentence);

Tested Models

.NET Framework 4.6.1 Specific Information

ONNX Runtime Initialization

For .NET Framework 4.6.1 projects, you may encounter ONNX Runtime initialization issues. This library includes helper classes to resolve these:

// Option 1: Use SafeAllMiniLmL6V2Embedder (recommended)
using (var embedder = new SafeAllMiniLmL6V2Embedder())
{
    var embedding = embedder.GenerateEmbedding("Your text");
}

// Option 2: Manual initialization
OnnxRuntimeInitializer.EnsureInitialized();
using (var embedder = new AllMiniLmL6V2Embedder())
{
    var embedding = embedder.GenerateEmbedding("Your text");
}

Troubleshooting

If you encounter issues with .NET Framework 4.6.1:

  1. GPU Conflicts: Run the included FIX_GPU_CONFLICT.ps1 PowerShell script
  2. ONNX Runtime Issues: See INITIALIZE_ONNX_RUNTIME.md for detailed solutions
  3. Package Conflicts: Refer to ONNX_RUNTIME_FIX.md for resolution steps

License

This project maintains the original MIT License. See LICENSE file for details.

Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 26 9/16/2025
1.0.1 28 9/16/2025
1.0.0 24 9/16/2025

Version 1.0.2 - Updated library namespace to match package name. Changes include: Renamed namespace from AllMiniLmL6V2Sharp to SentenceTransformersCSharp, updated assembly name to SentenceTransformersCSharp, updated all source files to use the new namespace, and improved consistency between package name and library name. This is a breaking change for existing code - update your using statements from 'using AllMiniLmL6V2Sharp' to 'using SentenceTransformersCSharp'.