.NET library for local embedding generation using ONNX and Microsoft.Extensions.AI
C#
40
248 commits
updated Sep 28, 2026
A .NET library for generating text embeddings locally using ONNX Runtime and Microsoft.Extensions.AI abstractions β no external API calls required.
New to local embeddings? Watch this 5-minute video explaining the main goal of the library.
Want to build RAG applications? Read this blog post about 3 RAG approaches in .NET with local embeddings and zero cloud calls.
Interested in image embeddings? Check out the YouTube video and blog post about local image embeddings with CLIP and ONNX.
IEmbeddingGenerator<string, Embedding<float>>ElBruno.LocalEmbeddings.HarrierElBruno.LocalEmbeddings.KernelMemory provides a native ITextEmbeddingGenerator adapter for Microsoft Kernel MemoryElBruno.LocalEmbeddings.VectorData adds DI helpers for Microsoft.Extensions.VectorData (VectorStore and typed collections)ElBruno.LocalEmbeddings.BlazorComponents provides 9 ready-to-use Razor components: model gallery, similarity meter, semantic search box, embedding explorer, dimension viewer, health badge, and metrics panelElBruno.LocalEmbeddings.VectorData includes InMemoryVectorStore (no Semantic Kernel connector dependency required)IServiceCollection integrationGenerateAsync("text") and GenerateEmbeddingAsync("text") β no array wrapping neededSimilarity(...) matrix, and one-line FindClosestAsync(...) semantic searchThe last 5 notable additions to the library. Updated with each NuGet release.
| Version | Date | Highlight |
|---|---|---|
| v1.6.3 | 2026-09-28 | Uncased BERT/MiniLM tokenization β normalizes accents so accented words map to their expected tokens |
| v1.5.9 | 2026-08-02 | ElBruno.LocalEmbeddings.BlazorComponents β full test coverage (77 xUnit + bUnit tests for all 9 components), EmbeddingDimensionViewer PCA demo added to BlazorDemo, sample README, fixed auto-release β NuGet publish pipeline |
| v1.5.7 | 2026-08-02 | New package: ElBruno.LocalEmbeddings.BlazorComponents β 9 ready-to-use Razor components: EmbeddingModelGallery, SimilarityMeter, SemanticSearchBox, EmbeddingExplorer, EmbeddingDimensionViewer (PCA 2-D), EmbeddingModelSelector, EmbeddingHealthBadge, EmbeddingMetricsPanel, EmbeddingModelStatusCard |
| v1.5.3 | 2026-08-02 | ElBruno.LocalEmbeddings.OpenTelemetry β OpenTelemetry instrumentation with Activity tracing, metrics (tokens/sec, latency), and configurable exporters for embedding pipelines |
| v1.4.x | 2026 | NPU hardware acceleration β ElBruno.LocalEmbeddings.Npu.Intel (Intel Core Ultra via OpenVINO) and ElBruno.LocalEmbeddings.Npu.Qualcomm (Snapdragon X via QNN) for on-device NPU inference |
| Package | Version | Downloads | Description |
|---|---|---|---|
| ElBruno.LocalEmbeddings | Core library β ONNX Runtime + Microsoft.Extensions.AI | ||
| ElBruno.LocalEmbeddings.Harrier | Microsoft Harrier-OSS-v1 (270M, 640-dim, 94+ languages) | ||
| ElBruno.LocalEmbeddings.ImageEmbeddings | CLIP-based image embeddings for multimodal search | ||
| ElBruno.LocalEmbeddings.ImageEmbeddings.Downloader | Model downloader for image embeddings | ||
| ElBruno.LocalEmbeddings.KernelMemory | Microsoft Kernel Memory adapter | ||
| ElBruno.LocalEmbeddings.VectorData | Microsoft.Extensions.VectorData + InMemoryVectorStore | ||
| ElBruno.LocalEmbeddings.Npu | NPU-accelerated embeddings via DirectML | ||
| ElBruno.LocalEmbeddings.Npu.Intel | Intel Core Ultra NPU via OpenVINO | ||
| ElBruno.LocalEmbeddings.Npu.Qualcomm | Qualcomm Snapdragon X NPU via QNN | ||
| ElBruno.LocalEmbeddings.BlazorComponents | Blazor UI components β model gallery, similarity meter, semantic search, embedding explorer |
dotnet add package ElBruno.LocalEmbeddings
For Harrier model support, install the companion package:
dotnet add package ElBruno.LocalEmbeddings.Harrier
For Kernel Memory integration, also install:
dotnet add package ElBruno.LocalEmbeddings.KernelMemory
For VectorData integration, install:
dotnet add package ElBruno.LocalEmbeddings.VectorData
using ElBruno.LocalEmbeddings;
await using var generator = await LocalEmbeddingGenerator.CreateAsync();
var embedding = await generator.GenerateEmbeddingAsync("Hello, world!");
Console.WriteLine(embedding.Vector.Length); // 384
var inputs = new[] { "first text", "second text", "third text" };
var embeddings = await generator.GenerateAsync(inputs);
Console.WriteLine(embeddings.Count); // 3
using ElBruno.LocalEmbeddings.Extensions;
var pair = await generator.GenerateAsync(["I love coding", "I enjoy programming"]);
var score = pair[0].CosineSimilarity(pair[1]);
Console.WriteLine(score);
var corpus = new[]
{
"Python for data science",
"JavaScript for web apps",
"Swift for iOS development"
};
var corpusEmbeddings = await generator.GenerateAsync(corpus);
var results = await generator.FindClosestAsync(
"best language for websites",
corpus,
corpusEmbeddings,
topK: 2,
minScore: 0.2f);
foreach (var result in results)
Console.WriteLine($"{result.Score:F3} - {result.Text}");
using ElBruno.LocalEmbeddings.Harrier;
var generator = await HarrierEmbeddingGenerator.CreateAsync();
var embedding = await generator.GenerateEmbeddingAsync("Hello, world!");
Console.WriteLine($"Dimensions: {embedding.Vector.Length}"); // 640
For custom models and runtime behavior, use the options-based constructor:
new LocalEmbeddingGenerator(new LocalEmbeddingsOptions { ... }).
Note: The synchronous constructor remains available for backward compatibility, but performs blocking initialization when downloads are needed.
Want to go further? Read the Getting Started guide and the other docs in this repo for DI, configuration, VectorData, Kernel Memory, and full RAG examples.
Prefer a containerized dev environment? See the Dev Container section in the Contributing guide.
All sample applications are located in src/Samples/. See the samples README for prerequisites and run instructions.
| Sample | What It Shows |
|---|---|
| HelloWorldAltModel | Minimal hello world with sentence-transformers/all-MiniLM-L12-v2 |
| ConsoleApp | All the basics: single/batch embeddings, similarity, semantic search, DI |
| HarrierConsoleApp | Harrier embedding model usage and similarity search |
| RagChat | Embedding-only semantic search Q&A using shared VectorData InMemoryVectorStore (no LLM needed) |
| RagOllama | Full RAG with Ollama + phi4-mini + Kernel Memory |
| RagFoundryLocal | Full RAG with Foundry Local + phi4-mini |
| ImageRagSimple | Minimal image RAG: index images β search by text |
| ImageRagChat | Interactive image RAG chat with text and image-to-image search |
var options = new LocalEmbeddingsOptions
{
ModelName = "sentence-transformers/all-MiniLM-L6-v2", // HuggingFace model
MaxSequenceLength = 512, // Max tokens
CacheDirectory = null, // Auto-detect per platform
EnsureModelDownloaded = true, // Download if missing
NormalizeEmbeddings = false // L2 normalize vectors
};
See Configuration docs for supported models, local model paths, and cache locations.
Estimated download sizes below are approximate and can vary by ONNX variant (fp32/int8) and tokenizer assets.
sentence-transformers/all-MiniLM-L6-v2 (default, ~90β100 MB)sentence-transformers/all-MiniLM-L12-v2 (~130β140 MB)sentence-transformers/paraphrase-MiniLM-L6-v2 (~90β100 MB)BAAI/bge-large-en-v1.5 (large, ~1.3 GB)intfloat/e5-large-v2 (large, ~1.3 GB)| Topic | Description |
|---|---|
| Getting Started | Step-by-step guide from hello world to RAG |
| API Reference | Classes, methods, and extension methods |
| Configuration | Options, supported models, cache locations |
| Alternative Models | Non-default free models, local download workflow, and license notes |
| Dependency Injection | All DI overloads and IConfiguration binding |
| Harrier Integration | Microsoft Harrier-OSS-v1 local embedding model |
| Kernel Memory Integration | Using local embeddings with Microsoft Kernel Memory |
| VectorData Integration | Using local embeddings with Microsoft.Extensions.VectorData abstractions |
| Blazor Components | 9 ready-to-use Blazor components for embedding-powered web apps |
| Contributing | Build from source, repo structure, guidelines |
| Roadmap | Planned and completed features/samples with priorities |
| Publishing | NuGet publishing with GitHub Actions + Trusted Publishing |
| Changelog | Versioned summary of notable changes |
Have an idea for a new feature or sample? Please open an issue and share your suggestion.
git clone https://github.com/elbruno/elbruno.localembeddings.git
cd elbruno.localembeddings
dotnet build
dotnet test
Hi! I'm ElBruno π§‘, a passionate developer and content creator exploring AI, .NET, and modern development practices.
Made with β€οΈ by ElBruno
If you like this project, consider following my work across platforms:
This project is licensed under the MIT License β see the LICENSE file for details.
C#
94.0%
HTML
2.7%
JavaScript
1.2%
.NET library for local embedding generation using ONNX and Microsoft.Extensions.AI
C#
40
248 commits
updated Sep 28, 2026
A .NET library for generating text embeddings locally using ONNX Runtime and Microsoft.Extensions.AI abstractions β no external API calls required.
New to local embeddings? Watch this 5-minute video explaining the main goal of the library.
Want to build RAG applications? Read this blog post about 3 RAG approaches in .NET with local embeddings and zero cloud calls.
Interested in image embeddings? Check out the YouTube video and blog post about local image embeddings with CLIP and ONNX.
IEmbeddingGenerator<string, Embedding<float>>ElBruno.LocalEmbeddings.HarrierElBruno.LocalEmbeddings.KernelMemory provides a native ITextEmbeddingGenerator adapter for Microsoft Kernel MemoryElBruno.LocalEmbeddings.VectorData adds DI helpers for Microsoft.Extensions.VectorData (VectorStore and typed collections)ElBruno.LocalEmbeddings.BlazorComponents provides 9 ready-to-use Razor components: model gallery, similarity meter, semantic search box, embedding explorer, dimension viewer, health badge, and metrics panelElBruno.LocalEmbeddings.VectorData includes InMemoryVectorStore (no Semantic Kernel connector dependency required)IServiceCollection integrationGenerateAsync("text") and GenerateEmbeddingAsync("text") β no array wrapping neededSimilarity(...) matrix, and one-line FindClosestAsync(...) semantic searchThe last 5 notable additions to the library. Updated with each NuGet release.
| Version | Date | Highlight |
|---|---|---|
| v1.6.3 | 2026-09-28 | Uncased BERT/MiniLM tokenization β normalizes accents so accented words map to their expected tokens |
| v1.5.9 | 2026-08-02 | ElBruno.LocalEmbeddings.BlazorComponents β full test coverage (77 xUnit + bUnit tests for all 9 components), EmbeddingDimensionViewer PCA demo added to BlazorDemo, sample README, fixed auto-release β NuGet publish pipeline |
| v1.5.7 | 2026-08-02 | New package: ElBruno.LocalEmbeddings.BlazorComponents β 9 ready-to-use Razor components: EmbeddingModelGallery, SimilarityMeter, SemanticSearchBox, EmbeddingExplorer, EmbeddingDimensionViewer (PCA 2-D), EmbeddingModelSelector, EmbeddingHealthBadge, EmbeddingMetricsPanel, EmbeddingModelStatusCard |
| v1.5.3 | 2026-08-02 | ElBruno.LocalEmbeddings.OpenTelemetry β OpenTelemetry instrumentation with Activity tracing, metrics (tokens/sec, latency), and configurable exporters for embedding pipelines |
| v1.4.x | 2026 | NPU hardware acceleration β ElBruno.LocalEmbeddings.Npu.Intel (Intel Core Ultra via OpenVINO) and ElBruno.LocalEmbeddings.Npu.Qualcomm (Snapdragon X via QNN) for on-device NPU inference |
| Package | Version | Downloads | Description |
|---|---|---|---|
| ElBruno.LocalEmbeddings | Core library β ONNX Runtime + Microsoft.Extensions.AI | ||
| ElBruno.LocalEmbeddings.Harrier | Microsoft Harrier-OSS-v1 (270M, 640-dim, 94+ languages) | ||
| ElBruno.LocalEmbeddings.ImageEmbeddings | CLIP-based image embeddings for multimodal search | ||
| ElBruno.LocalEmbeddings.ImageEmbeddings.Downloader | Model downloader for image embeddings | ||
| ElBruno.LocalEmbeddings.KernelMemory | Microsoft Kernel Memory adapter | ||
| ElBruno.LocalEmbeddings.VectorData | Microsoft.Extensions.VectorData + InMemoryVectorStore | ||
| ElBruno.LocalEmbeddings.Npu | NPU-accelerated embeddings via DirectML | ||
| ElBruno.LocalEmbeddings.Npu.Intel | Intel Core Ultra NPU via OpenVINO | ||
| ElBruno.LocalEmbeddings.Npu.Qualcomm | Qualcomm Snapdragon X NPU via QNN | ||
| ElBruno.LocalEmbeddings.BlazorComponents | Blazor UI components β model gallery, similarity meter, semantic search, embedding explorer |
dotnet add package ElBruno.LocalEmbeddings
For Harrier model support, install the companion package:
dotnet add package ElBruno.LocalEmbeddings.Harrier
For Kernel Memory integration, also install:
dotnet add package ElBruno.LocalEmbeddings.KernelMemory
For VectorData integration, install:
dotnet add package ElBruno.LocalEmbeddings.VectorData
using ElBruno.LocalEmbeddings;
await using var generator = await LocalEmbeddingGenerator.CreateAsync();
var embedding = await generator.GenerateEmbeddingAsync("Hello, world!");
Console.WriteLine(embedding.Vector.Length); // 384
var inputs = new[] { "first text", "second text", "third text" };
var embeddings = await generator.GenerateAsync(inputs);
Console.WriteLine(embeddings.Count); // 3
using ElBruno.LocalEmbeddings.Extensions;
var pair = await generator.GenerateAsync(["I love coding", "I enjoy programming"]);
var score = pair[0].CosineSimilarity(pair[1]);
Console.WriteLine(score);
var corpus = new[]
{
"Python for data science",
"JavaScript for web apps",
"Swift for iOS development"
};
var corpusEmbeddings = await generator.GenerateAsync(corpus);
var results = await generator.FindClosestAsync(
"best language for websites",
corpus,
corpusEmbeddings,
topK: 2,
minScore: 0.2f);
foreach (var result in results)
Console.WriteLine($"{result.Score:F3} - {result.Text}");
using ElBruno.LocalEmbeddings.Harrier;
var generator = await HarrierEmbeddingGenerator.CreateAsync();
var embedding = await generator.GenerateEmbeddingAsync("Hello, world!");
Console.WriteLine($"Dimensions: {embedding.Vector.Length}"); // 640
For custom models and runtime behavior, use the options-based constructor:
new LocalEmbeddingGenerator(new LocalEmbeddingsOptions { ... }).
Note: The synchronous constructor remains available for backward compatibility, but performs blocking initialization when downloads are needed.
Want to go further? Read the Getting Started guide and the other docs in this repo for DI, configuration, VectorData, Kernel Memory, and full RAG examples.
Prefer a containerized dev environment? See the Dev Container section in the Contributing guide.
All sample applications are located in src/Samples/. See the samples README for prerequisites and run instructions.
| Sample | What It Shows |
|---|---|
| HelloWorldAltModel | Minimal hello world with sentence-transformers/all-MiniLM-L12-v2 |
| ConsoleApp | All the basics: single/batch embeddings, similarity, semantic search, DI |
| HarrierConsoleApp | Harrier embedding model usage and similarity search |
| RagChat | Embedding-only semantic search Q&A using shared VectorData InMemoryVectorStore (no LLM needed) |
| RagOllama | Full RAG with Ollama + phi4-mini + Kernel Memory |
| RagFoundryLocal | Full RAG with Foundry Local + phi4-mini |
| ImageRagSimple | Minimal image RAG: index images β search by text |
| ImageRagChat | Interactive image RAG chat with text and image-to-image search |
var options = new LocalEmbeddingsOptions
{
ModelName = "sentence-transformers/all-MiniLM-L6-v2", // HuggingFace model
MaxSequenceLength = 512, // Max tokens
CacheDirectory = null, // Auto-detect per platform
EnsureModelDownloaded = true, // Download if missing
NormalizeEmbeddings = false // L2 normalize vectors
};
See Configuration docs for supported models, local model paths, and cache locations.
Estimated download sizes below are approximate and can vary by ONNX variant (fp32/int8) and tokenizer assets.
sentence-transformers/all-MiniLM-L6-v2 (default, ~90β100 MB)sentence-transformers/all-MiniLM-L12-v2 (~130β140 MB)sentence-transformers/paraphrase-MiniLM-L6-v2 (~90β100 MB)BAAI/bge-large-en-v1.5 (large, ~1.3 GB)intfloat/e5-large-v2 (large, ~1.3 GB)| Topic | Description |
|---|---|
| Getting Started | Step-by-step guide from hello world to RAG |
| API Reference | Classes, methods, and extension methods |
| Configuration | Options, supported models, cache locations |
| Alternative Models | Non-default free models, local download workflow, and license notes |
| Dependency Injection | All DI overloads and IConfiguration binding |
| Harrier Integration | Microsoft Harrier-OSS-v1 local embedding model |
| Kernel Memory Integration | Using local embeddings with Microsoft Kernel Memory |
| VectorData Integration | Using local embeddings with Microsoft.Extensions.VectorData abstractions |
| Blazor Components | 9 ready-to-use Blazor components for embedding-powered web apps |
| Contributing | Build from source, repo structure, guidelines |
| Roadmap | Planned and completed features/samples with priorities |
| Publishing | NuGet publishing with GitHub Actions + Trusted Publishing |
| Changelog | Versioned summary of notable changes |
Have an idea for a new feature or sample? Please open an issue and share your suggestion.
git clone https://github.com/elbruno/elbruno.localembeddings.git
cd elbruno.localembeddings
dotnet build
dotnet test
Hi! I'm ElBruno π§‘, a passionate developer and content creator exploring AI, .NET, and modern development practices.
Made with β€οΈ by ElBruno
If you like this project, consider following my work across platforms:
This project is licensed under the MIT License β see the LICENSE file for details.
C#
94.0%
HTML
2.7%
JavaScript
1.2%