Dhara.AI.LocalEmbeddings 0.2.0

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

Dhara.AI.LocalEmbeddings

Local text embeddings for .NET, built on Microsoft.Extensions.AI and ONNX.

Dhara.AI.LocalEmbeddings exposes a local embedding generator through IEmbeddingGenerator<string, Embedding<float>> while also providing compact embedding formats and ranking helpers inspired by SmartComponents.

Install

dotnet add package Dhara.AI.LocalEmbeddings

Quick Start

using Dhara.AI.LocalEmbeddings;

using var generator = LocalEmbeddingGenerator.Create();

var query = await generator.EmbedAsync<EmbeddingF32>(
    "semantic search for Obsidian notes");

var candidates = await generator.EmbedRangeAsync<EmbeddingF32>(
[
    "Smart Connections stores note and block embeddings.",
    "Native AOT publishes a self-contained executable.",
    "ONNX Runtime can run local transformer models."
]);

var closest = EmbeddingSearch.FindClosestWithScore(query, candidates, maxResults: 2);

Microsoft.Extensions.AI

The primary contract is:

IEmbeddingGenerator<string, Embedding<float>>

That means the generator fits modern .NET AI patterns, dependency injection, and code that already targets Microsoft.Extensions.AI.

services.AddLocalEmbeddings(options =>
{
    options.ModelName = "default";
    options.MaxTokens = 512;
});

Model Acquisition

The package includes an MSBuild target that downloads the default SmartComponents bge-micro-v2 ONNX model and vocabulary during build, then copies them into the consuming app output under:

LocalEmbeddingsModel/<model-name>/model.onnx
LocalEmbeddingsModel/<model-name>/vocab.txt

The model files are not embedded into the NuGet package. This keeps the package small and lets applications choose their own model source.

Useful MSBuild properties:

  • LocalEmbeddingsModelName
  • LocalEmbeddingsModelUrl
  • LocalEmbeddingsVocabUrl
  • LocalEmbeddingsModelCacheDir
  • LocalEmbeddingsModelPath
  • LocalEmbeddingsVocabPath

Embedding Formats

EmbeddingF32 stores the raw model output as one 32-bit floating-point value per dimension. A 384-dimensional vector uses 1,536 bytes, and a 768-dimensional vector uses 3,072 bytes. Use this for highest quality, debugging, evaluation, and final reranking.

EmbeddingI8 stores a scalar-quantized signed 8-bit representation plus the vector magnitude. A 384-dimensional vector uses 388 bytes, and a 768-dimensional vector uses 772 bytes. Use this when local indexes need to be much smaller while preserving useful ranking quality.

EmbeddingI1 stores only the sign bit of each dimension plus a dimension header. A 384-dimensional vector uses 52 bytes, and a 768-dimensional vector uses 100 bytes. Use this for very large indexes, coarse filtering, or shortlist-then-rescore retrieval.

Model Compatibility

The default model produces 384-dimensional embeddings, but the library is not limited to that size. It sizes buffers from the vector returned by the ONNX model, so 768-dimensional sentence-transformer exports such as sentence-transformers/multi-qa-distilbert-cos-v1 can be used when exported to a compatible ONNX shape.

Mean pooling and normalization are enabled by default because they match common sentence-transformer semantic-search models. Both can be configured through LocalEmbeddingGeneratorOptions.

Native AOT

The package is marked as AOT-compatible. Publish a consuming app with Native AOT to validate the complete application:

dotnet publish samples\Dhara.AI.LocalEmbeddings.Sample -c Release -r win-x64 --self-contained true

Dhara.AI.Inference contains the lower-level ONNX Runtime and tokenizer layer used by this package.

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.2.0 144 5/12/2026