LocalAI.Embedder 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package LocalAI.Embedder --version 0.4.0
                    
NuGet\Install-Package LocalAI.Embedder -Version 0.4.0
                    
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="LocalAI.Embedder" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LocalAI.Embedder" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="LocalAI.Embedder" />
                    
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 LocalAI.Embedder --version 0.4.0
                    
#r "nuget: LocalAI.Embedder, 0.4.0"
                    
#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 LocalAI.Embedder@0.4.0
                    
#: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=LocalAI.Embedder&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=LocalAI.Embedder&version=0.4.0
                    
Install as a Cake Tool

LocalAI

CI NuGet NuGet License: MIT

.NET libraries for on-device AI inference with zero external API dependencies. Run embeddings, reranking, and more entirely on your local machine with automatic GPU acceleration.

Features

  • Zero Configuration: Works out of the box with sensible defaults
  • Automatic GPU Acceleration: Detects and uses CUDA, DirectML, or CoreML automatically
  • HuggingFace Compatible: Downloads models from HuggingFace Hub with standard caching
  • Cross-Platform: Windows, Linux, macOS support
  • Production Ready: Thread-safe, async-first, IAsyncDisposable support

Packages

Package Description NuGet
LocalAI.Embedder Text embeddings with sentence-transformers models NuGet
LocalAI.Reranker Semantic reranking with cross-encoder models NuGet

Quick Start

Text Embeddings

using LocalAI.Embedder;

// Load a model (downloads automatically on first use)
await using var model = await LocalEmbedder.LoadAsync("default");

// Generate embeddings
float[] embedding = await model.EmbedAsync("Hello, world!");

// Batch processing
float[][] embeddings = await model.EmbedBatchAsync(new[]
{
    "First document",
    "Second document",
    "Third document"
});

// Calculate similarity
float similarity = model.CosineSimilarity(embeddings[0], embeddings[1]);

Semantic Reranking

using LocalAI.Reranker;

// Load a reranker model
await using var reranker = await LocalReranker.LoadAsync("default");

// Rerank documents by relevance to a query
var results = await reranker.RerankAsync(
    query: "What is machine learning?",
    documents: new[]
    {
        "Machine learning is a subset of artificial intelligence...",
        "The weather today is sunny and warm...",
        "Deep learning uses neural networks..."
    },
    topK: 2
);

foreach (var result in results)
{
    Console.WriteLine($"[{result.Score:F4}] {result.Document}");
}

Available Models

Embedder Models

Alias Model Dimensions Size
default all-MiniLM-L6-v2 384 ~90MB
large all-mpnet-base-v2 768 ~420MB
multilingual paraphrase-multilingual-MiniLM-L12-v2 384 ~470MB

Reranker Models

Alias Model Max Tokens Size
default ms-marco-MiniLM-L-6-v2 512 ~90MB
quality ms-marco-MiniLM-L-12-v2 512 ~134MB
fast ms-marco-TinyBERT-L-2-v2 512 ~18MB
multilingual bge-reranker-v2-m3 8192 ~1.1GB

GPU Acceleration

GPU acceleration is automatic when available:

// Auto-detect best provider (default)
var options = new EmbedderOptions { Provider = ExecutionProvider.Auto };

// Force specific provider
var options = new EmbedderOptions { Provider = ExecutionProvider.Cuda };
var options = new EmbedderOptions { Provider = ExecutionProvider.DirectML }; // Windows
var options = new EmbedderOptions { Provider = ExecutionProvider.CoreML };   // macOS
var options = new EmbedderOptions { Provider = ExecutionProvider.Cpu };

For GPU support, install the appropriate ONNX Runtime package:

# NVIDIA CUDA
dotnet add package Microsoft.ML.OnnxRuntime.Gpu

# Windows DirectML (AMD, Intel, NVIDIA)
dotnet add package Microsoft.ML.OnnxRuntime.DirectML

# macOS CoreML
dotnet add package Microsoft.ML.OnnxRuntime.CoreML

Model Caching

Models are cached following HuggingFace Hub standard:

  • Default: ~/.cache/huggingface/hub
  • Override with HF_HUB_CACHE, HF_HOME, or XDG_CACHE_HOME environment variables
  • Or specify directly: new EmbedderOptions { CacheDirectory = "/path/to/cache" }

Requirements

  • .NET 8.0 or later
  • Windows, Linux, or macOS

Documentation

License

MIT License - see LICENSE for details.

Contributing

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

Release Process

Releases are automated via GitHub Actions when Directory.Build.props is updated:

  1. Update the <Version> in Directory.Build.props
  2. Commit and push to main
  3. CI automatically publishes all packages to NuGet and creates a GitHub release

Requires NUGET_API_KEY secret configured in GitHub repository settings.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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.7.2 160 12/15/2025
0.7.1 90 12/15/2025
0.7.0 152 12/14/2025
0.6.0 102 12/13/2025
0.5.0 96 12/13/2025
0.4.0 104 12/13/2025