Skip to main content
net8.0net10.0

Microsoft.Extensions.VectorData integration for ElBruno.LocalEmbeddings

Published
Feb 14, 2026
8mo ago
Total Downloads
3.6K
3,618

Install

dotnet add package ElBruno.LocalEmbeddings.VectorData --version 1.0.9-preview
ProductVersions
.NET
net10.0net8.0

README

LocalEmbeddings

NuGet License: MIT

A .NET library for generating text embeddings locally using ONNX Runtime and Microsoft.Extensions.AI abstractions β€” no external API calls required.

Features

  • Local Embedding Generation β€” Run inference entirely on your machine using ONNX Runtime
  • Microsoft.Extensions.AI Integration β€” Implements IEmbeddingGenerator<string, Embedding<float>>
  • Kernel Memory Integration β€” Companion package ElBruno.LocalEmbeddings.KernelMemory provides a native ITextEmbeddingGenerator adapter for Microsoft Kernel Memory
  • VectorData Integration β€” Companion package ElBruno.LocalEmbeddings.VectorData adds DI helpers for Microsoft.Extensions.VectorData (VectorStore and typed collections)
  • HuggingFace Model Support β€” Use popular sentence transformer models from HuggingFace Hub
  • Automatic Model Caching β€” Models are downloaded once and cached locally
  • Dependency Injection Support β€” First-class IServiceCollection integration
  • Single-String Convenience API β€” GenerateAsync("text") and GenerateEmbeddingAsync("text") β€” no array wrapping needed
  • Similarity Helpers β€” Cosine similarity, all-pairs Similarity(...) matrix, and FindClosest(...) for semantic search
  • Thread-Safe & Batched β€” Concurrent generation and efficient multi-text processing

Installation

dotnet add package ElBruno.LocalEmbeddings

For Kernel Memory integration, also install the companion package:

dotnet add package ElBruno.LocalEmbeddings.KernelMemory

For VectorData integration, install:

dotnet add package ElBruno.LocalEmbeddings.VectorData

Quick Start

using ElBruno.LocalEmbeddings;

// Create the generator (downloads model automatically on first run)
using var generator = new LocalEmbeddingGenerator();

// Generate a single embedding β€” no array wrapping needed
var embedding = await generator.GenerateEmbeddingAsync("Hello, world!");
Console.WriteLine($"Dimensions: {embedding.Vector.Length}"); // 384

// Or get the full result collection
var result = await generator.GenerateAsync("Hello, world!");
Console.WriteLine($"Embedding: [{string.Join(", ", result[0].Vector.ToArray().Take(3))}...]");

For custom models and runtime behavior, use the options-based constructor: new LocalEmbeddingGenerator(new LocalEmbeddingsOptions { ... }).

Want to go further? See the Getting Started guide for a step-by-step walkthrough β€” from cosine similarity to semantic search, dependency injection, and full RAG with a local LLM.

Prefer a containerized dev environment? See the Dev Container section in the Contributing guide.

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
RagChat Embedding-only semantic search Q&A (no LLM needed)
RagOllama Full RAG with Ollama + phi4-mini + Kernel Memory
RagFoundryLocal Full RAG with Foundry Local + phi4-mini

Configuration

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.

Documentation

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
Kernel Memory Integration Using local embeddings with Microsoft Kernel Memory
VectorData Integration Using local embeddings with Microsoft.Extensions.VectorData abstractions
Contributing Build from source, repo structure, guidelines
Roadmap Planned and completed features/samples with priorities
Publishing NuGet publishing with GitHub Actions + Trusted Publishing

Have an idea for a new feature or sample? Please open an issue and share your suggestion.

Building from Source

git clone https://github.com/elbruno/elbruno.localembeddings.git
cd elbruno.localembeddings
dotnet build
dotnet test

Requirements

  • .NET 10.0 SDK or later
  • ONNX Runtime compatible platform (Windows, Linux, macOS)

License

This project is licensed under the MIT License β€” see the LICENSE file for details.

Changes from Previous Version

No structural changes between v1.0.1 and v1.0.9-preview.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.