LocalAI.Embedder
0.4.0
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
<PackageReference Include="LocalAI.Embedder" Version="0.4.0" />
<PackageVersion Include="LocalAI.Embedder" Version="0.4.0" />
<PackageReference Include="LocalAI.Embedder" />
paket add LocalAI.Embedder --version 0.4.0
#r "nuget: LocalAI.Embedder, 0.4.0"
#:package LocalAI.Embedder@0.4.0
#addin nuget:?package=LocalAI.Embedder&version=0.4.0
#tool nuget:?package=LocalAI.Embedder&version=0.4.0
LocalAI
.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 | |
| LocalAI.Reranker | Semantic reranking with cross-encoder models |
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, orXDG_CACHE_HOMEenvironment 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:
- Update the
<Version>inDirectory.Build.props - Commit and push to main
- CI automatically publishes all packages to NuGet and creates a GitHub release
Requires NUGET_API_KEY secret configured in GitHub repository settings.
| Product | Versions 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. |
-
net10.0
- LocalAI.Core (>= 0.4.0)
- System.Numerics.Tensors (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.