Contoso.AI.TextEmbedder.MiniLML6 0.1.6-beta

This is a prerelease version of Contoso.AI.TextEmbedder.MiniLML6.
dotnet add package Contoso.AI.TextEmbedder.MiniLML6 --version 0.1.6-beta
                    
NuGet\Install-Package Contoso.AI.TextEmbedder.MiniLML6 -Version 0.1.6-beta
                    
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="Contoso.AI.TextEmbedder.MiniLML6" Version="0.1.6-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Contoso.AI.TextEmbedder.MiniLML6" Version="0.1.6-beta" />
                    
Directory.Packages.props
<PackageReference Include="Contoso.AI.TextEmbedder.MiniLML6" />
                    
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 Contoso.AI.TextEmbedder.MiniLML6 --version 0.1.6-beta
                    
#r "nuget: Contoso.AI.TextEmbedder.MiniLML6, 0.1.6-beta"
                    
#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 Contoso.AI.TextEmbedder.MiniLML6@0.1.6-beta
                    
#: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=Contoso.AI.TextEmbedder.MiniLML6&version=0.1.6-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Contoso.AI.TextEmbedder.MiniLML6&version=0.1.6-beta&prerelease
                    
Install as a Cake Tool

Contoso.AI.TextEmbedder.MiniLML6

NuGet License: MIT

AI-powered text embedding library using the all-MiniLM-L6-v2 ONNX model from sentence-transformers. Converts text into 384-dimensional embeddings for semantic search, similarity tasks, clustering, and more.

โœจ Features

  • 384-Dimensional Embeddings - Rich semantic representations for text
  • Automatic Model Download - Model downloads automatically at build time
  • GPU Acceleration - Leverages DirectML for faster inference when available
  • Easy-to-Use API - Simple async factory pattern with CreateAsync()
  • Cosine Similarity - Built-in similarity calculation between embeddings
  • Semantic Search - Find semantically similar texts
  • NuGet Package - Easy integration into any .NET project

๐Ÿ“‹ Requirements

  • Windows 10 SDK 19041 or later
  • .NET 8.0 or later
  • GPU (optional) - DirectML-compatible GPU for hardware acceleration
  • Falls back to CPU execution if GPU is not available

๐Ÿš€ Quick Start

Installation

dotnet add package Contoso.AI.TextEmbedder.MiniLML6

Or via Package Manager Console:

Install-Package Contoso.AI.TextEmbedder.MiniLML6

Basic Usage

using Contoso.AI;

// Check if the feature is ready
var readyState = TextEmbedderMiniLML6.GetReadyState();

if (readyState != AIFeatureReadyState.Ready)
{
    // Prepare the feature (downloads model if needed)
    var readyResult = await TextEmbedderMiniLML6.EnsureReadyAsync();
    if (readyResult.Status != AIFeatureReadyResultState.Success)
    {
        Console.WriteLine($"Failed to initialize: {readyResult.ExtendedError?.Message}");
        return;
    }
}

// Create embedder instance (returns ITextEmbedder interface)
using ITextEmbedder embedder = await TextEmbedderMiniLML6.CreateAsync();

// Generate embeddings
var texts = new[]
{
    "The quick brown fox jumps over the lazy dog",
    "Machine learning is transforming technology"
};

var embeddings = embedder.GenerateEmbeddings(texts);

// Calculate similarity
var similarity = embeddings[0].CosineSimilarity(embeddings[1]);
Console.WriteLine($"Similarity: {similarity:F3}");

Semantic Search Example

using Contoso.AI;

using ITextEmbedder embedder = await TextEmbedderMiniLML6.CreateAsync();

// Index some documents
var documents = new[]
{
    "Python is a programming language",
    "Cats make great pets",
    "Machine learning uses neural networks",
    "Dogs are loyal companions"
};

var docEmbeddings = embedder.GenerateEmbeddings(documents);

// Search with a query
var query = "Domestic animals";
var queryEmbedding = embedder.GenerateEmbeddings(query)[0];

// Find most similar documents
var results = docEmbeddings
    .Select((emb, idx) => new { 
        Document = documents[idx], 
        Score = queryEmbedding.CosineSimilarity(emb) 
    })
    .OrderByDescending(x => x.Score)
    .ToList();

foreach (var result in results)
{
    Console.WriteLine($"{result.Score:F3} - {result.Document}");
}

๐Ÿ“– API Reference

TextEmbedderMiniLML6 Class

Method Description
GetReadyState() Static. Returns AIFeatureReadyState indicating if the feature can be used
EnsureReadyAsync() Static. Checks for required dependencies
CreateAsync() Static factory. Creates and initializes a new ITextEmbedder instance

ITextEmbedder Interface

Method Description
GenerateEmbeddings(params string[]) Synchronously generates embeddings for texts
GenerateEmbeddingsAsync(IEnumerable<string>, CancellationToken) Asynchronously generates embeddings for texts

Embedding Class

Property/Method Description
Vector Gets the embedding as a float array
Dimensions Gets the dimensionality (384 for MiniLM-L6-v2)
CosineSimilarity(Embedding) Calculates cosine similarity with another embedding (returns -1 to 1)

๐Ÿ—๏ธ Development

Building from Source

# Clone the repository
git clone https://github.com/contoso/Contoso.AI.git
cd Contoso.AI/TextEmbedder

# Restore and build (model downloads automatically)
dotnet restore
dotnet build

# Run the console test
dotnet run --project Contoso.AI.TextEmbedder.MiniLML6.ConsoleTest

Model Information

This project uses the all-MiniLM-L6-v2 model from sentence-transformers:

The model is automatically downloaded during the first build and cached in the obj/Models directory.

๐Ÿงช Use Cases

  • Semantic Search - Find documents similar to a query
  • Text Clustering - Group similar texts together
  • Duplicate Detection - Identify similar or duplicate content
  • Recommendation Systems - Recommend similar items based on text descriptions
  • Question Answering - Find answers similar to questions
  • Content Classification - Classify text by similarity to categories

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments


Made with โค๏ธ by Contoso

Product Compatible and additional computed target framework versions.
.NET net8.0-windows10.0.19041 is compatible.  net9.0-windows was computed.  net10.0-windows 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
0.1.6-beta 34 2/19/2026