E5Embedding.Net 3.0.0

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

E5Embedding.Net

High-performance .NET library for generating text embeddings using E5 models with ONNX Runtime, supporting CUDA, DirectML, and automatic CPU fallback.

E5Embedding.Net provides a simple and production-ready API for integrating modern embedding models into .NET applications.

Designed for:

  • Semantic Search
  • Retrieval Augmented Generation (RAG)
  • Vector Databases
  • Document Similarity
  • Recommendation Systems
  • AI-powered Search

Features

🚀 High Performance

  • Optimized ONNX Runtime inference
  • Efficient batch processing
  • Async embedding generation

🎯 E5 Model Support

  • Built specifically for E5 embedding models
  • Supports retrieval-style embeddings (query: / passage:)

💻 GPU Acceleration

  • NVIDIA CUDA support
  • Windows DirectML support
  • Automatic CPU fallback

🔧 Flexible Tokenization

  • SentencePiece tokenizer support
  • BERT WordPiece tokenizer support

📦 Easy Integration

  • Simple API
  • Dependency Injection support
  • Microsoft.Extensions.Logging integration

🛡️ Production Ready

  • Resource management
  • Validation
  • Error handling
  • Logging support

Installation

Install via .NET CLI:

dotnet add package E5Embedding.Net

Or via Package Manager Console:

Install-Package E5Embedding.Net

Architecture

The processing flow of the pipeline:

Text Input
    |
    v
Tokenizer
    |
    v
Token IDs + Attention Mask
    |
    v
ONNX Runtime
    |
    v
Embedding Vector

Quick Start

using E5Embedding.Net;

var config = new E5EmbeddingConfiguration
{
    OnnxModelPath = "./E5/model.onnx",
    SentencePieceModelFile = "./E5/sentencepiece.bpe.model",
    TokenizerConfigFile = "./E5/tokenizer_config.json",
    TokenizerJsonFile = "./E5/tokenizer.json",

    MaxSequenceLength = 512,
    Dimension = 1024,
    BatchSize = 16
};

using var embeddingService = new OnnxEmbeddingService(config);

var embedding = await embeddingService.EmbedAsync("This is a sample text.");

Console.WriteLine($"Embedding size: {embedding.Length}");

Batch Embeddings

For multiple documents, use batch processing:

var documents = new[]
{
    "Document one",
    "Document two",
    "Document three"
};

var embeddings = await embeddingService.EmbedBatchAsync(documents);

Note: Batch processing improves throughput by reducing inference overhead.


Retrieval Example

E5 models are optimized for retrieval scenarios using prefixes:

  • Query: query: <your search query>
  • Passage: passage: <your document content>
var queryEmbedding = await service.EmbedAsync(
    "query: What is machine learning?"
);

var passageEmbedding = await service.EmbedAsync(
    "passage: Machine learning is a branch of AI..."
);

Dependency Injection

Example registration:

services.AddSingleton<E5EmbeddingConfiguration>(sp =>
{
    return new E5EmbeddingConfiguration
    {
        OnnxModelPath = "./model.onnx",
        MaxSequenceLength = 512,
        Dimension = 1024,
        BatchSize = 16
    };
});

services.AddSingleton<IEmbeddingService>(sp =>
{
    var config = sp.GetRequiredService<E5EmbeddingConfiguration>();
    var logger = sp.GetService<ILogger<OnnxEmbeddingService>>();

    return new OnnxEmbeddingService(config, logger);
});

Configuration

E5EmbeddingConfiguration

Property Type Description Default
OnnxModelPath string ONNX model location Required
SentencePieceModelFile string SentencePiece model file sentencepiece.bpe.model
TokenizerConfigFile string Tokenizer configuration tokenizer_config.json
TokenizerJsonFile string Tokenizer metadata tokenizer.json
MaxSequenceLength int Maximum tokens Required
Dimension int Embedding dimension 1024
BatchSize int Batch processing size 16

GPU Acceleration

E5Embedding.Net automatically selects the best available execution provider in the following order:

  1. CUDA
  2. DirectML
  3. CPU

No additional configuration is required. The selected provider is reported through logging.


Tokenizers

SentencePieceTokenizer

Recommended for E5 models.

var tokenizer = new SentencePieceTokenizer(
    "sentencepiece.bpe.model",
    "tokenizer_config.json",
    "tokenizer.json",
    512
);

var encoding = tokenizer.Encode("Hello world");

BertTokenizer

Supports BERT-style WordPiece tokenization.

var tokenizer = new BertTokenizer(
    "tokenizer_config.json",
    "tokenizer.json",
    512
);

var result = tokenizer.Encode("Example text");

Supported Models

Currently tested with intfloat/multilingual-e5-large.

Supported ONNX variants:

  • model.onnx
  • model.onnx_data
  • model_O4.onnx
  • model_qint8_avx512_vnni.onnx

Model Files

Required files:

  • model.onnx
  • model.onnx_data
  • sentencepiece.bpe.model
  • tokenizer.json
  • tokenizer_config.json

Requirements

  • .NET 8.0+
  • ONNX Runtime
  • E5 ONNX model files & Tokenizer files

Supported Platforms:

  • Windows / Linux
  • GPU: NVIDIA CUDA / DirectML compatible GPUs

Performance Tips

  1. Reuse the Service: Create one instance and reuse it as a singleton. The ONNX session is expensive to initialize.
    services.AddSingleton<IEmbeddingService, OnnxEmbeddingService>();
    
  2. Use Batch Processing: Prefer EmbedBatchAsync() for multiple texts.
  3. Dispose Resources: Always dispose of the service when finished:
    using var service = new OnnxEmbeddingService(config);
    

Error Handling

Common exceptions:

Exception Description
ArgumentNullException Missing required arguments
FileNotFoundException Model or tokenizer files missing
InvalidOperationException Invalid configuration
AggregateException GPU and CPU initialization failure

Roadmap

  • More E5 model variants
  • Native AOT support
  • Memory pooling optimization
  • Additional quantized models
  • Streaming embedding API
  • Built-in similarity utilities

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.


License

MIT License. See LICENSE for details.


Support

For issues, discussions, and contributions, visit the GitHub Repository.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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
3.0.0 135 8/3/2026
2.0.2 142 5/25/2026
2.0.1 112 5/25/2026
2.0.0 129 5/25/2026
1.0.2 170 2/1/2026
1.0.1 142 12/30/2025
1.0.0 137 12/30/2025

Initial stable release of E5Embedding.Net with E5 ONNX embedding support,
GPU acceleration and tokenizer support.