Starlings.Models.EmbeddingGemma2.Extensions.AI
0.1.0-preview.6
See the version list below for details.
dotnet add package Starlings.Models.EmbeddingGemma2.Extensions.AI --version 0.1.0-preview.6
NuGet\Install-Package Starlings.Models.EmbeddingGemma2.Extensions.AI -Version 0.1.0-preview.6
<PackageReference Include="Starlings.Models.EmbeddingGemma2.Extensions.AI" Version="0.1.0-preview.6" />
<PackageVersion Include="Starlings.Models.EmbeddingGemma2.Extensions.AI" Version="0.1.0-preview.6" />
<PackageReference Include="Starlings.Models.EmbeddingGemma2.Extensions.AI" />
paket add Starlings.Models.EmbeddingGemma2.Extensions.AI --version 0.1.0-preview.6
#r "nuget: Starlings.Models.EmbeddingGemma2.Extensions.AI, 0.1.0-preview.6"
#:package Starlings.Models.EmbeddingGemma2.Extensions.AI@0.1.0-preview.6
#addin nuget:?package=Starlings.Models.EmbeddingGemma2.Extensions.AI&version=0.1.0-preview.6&prerelease
#tool nuget:?package=Starlings.Models.EmbeddingGemma2.Extensions.AI&version=0.1.0-preview.6&prerelease
Starlings.Models.EmbeddingGemma2.Extensions.AI
Preview. Experimental. Microsoft.Extensions.AI IEmbeddingGenerator<string, Embedding<float>> over the EmbeddingGemma 2 text embedder (and generators for images and videos, below) in Starlings.Models.EmbeddingGemma2: the same tokenizer, encoder and numbers, usable with Microsoft.Extensions.AI middleware and dependency injection. The API may still change.
Install
dotnet add package Starlings.Models.EmbeddingGemma2.Extensions.AI --prerelease
dotnet add package Microsoft.ML.OnnxRuntime --version 1.30.0 # or Microsoft.ML.OnnxRuntime.Gpu.Linux; exactly one
Use
using Starlings.Models.EmbeddingGemma2;
using Starlings.Models.EmbeddingGemma2.Extensions.AI;
using Microsoft.Extensions.AI;
EmbeddingGemma2ModelFiles files = EmbeddingGemma2ModelAssets.OpenLocal(); // offline, verified
// The pinned graph plus the owned tokenizer (Starlings.Tokenizers, profile gemma-bpe-embeddinggemma2).
using IEmbeddingGenerator<string, Embedding<float>> generator = EmbeddingGemma2EmbeddingGenerator.Create(files,
new EmbeddingGemma2EmbeddingGeneratorOptions { Prompt = EmbeddingGemma2Prompt.Query }); // the default adds nothing
var embeddings = await generator.GenerateAsync(["how much protein should a female eat"],
new EmbeddingGenerationOptions { Dimensions = 256 }); // 768, 512, 256 or 128
- Or with DI:
services.AddEmbeddingGemma2EmbeddingGenerator(files). - Prompts are explicit:
Promptper generator, or per request withAdditionalProperties["embeddinggemma2_prompt"](anEmbeddingGemma2Prompt,"none", or one of the 20 names in the model'sconfig_sentence_transformers.json, case-sensitive). Dimensionsmaps to the Matryoshka sizes 768, 512, 256 and 128 (truncate, then normalize again); other values fail withNotSupportedException.- Inputs above 8,192 tokens fail with
EmbeddingGemma2InputTooLongException; nothing is truncated. GenerateAsyncruns synchronously on the calling thread and returns a completed task.- Unsupported options (another
ModelId,RawRepresentationFactory, unknown additional properties) fail withNotSupportedExceptioninstead of being ignored.
Status: Linux x64 CPU experimental (fixture texts with and without prompts within the binding bound); over a CUDA session untested.
Images and videos
EmbeddingGemma2MultimodalEmbeddingGenerator (over EmbeddingGemma2MultimodalEmbedder, experimental) implements IEmbeddingGenerator<DataContent, Embedding<float>> (one image or video per value) and IEmbeddingGenerator<IEnumerable<AIContent>, Embedding<float>> (text, image and video parts in order). DataContent holds encoded bytes, so decoding is a hook: ImageDecoder for image/* (for example Starlings.Models.EmbeddingGemma2.Imaging.SkiaSharp) and VideoDecoder for video/* (for example Starlings.Models.EmbeddingGemma2.Video.FFmpeg on your own FFmpeg 8.x):
var decoder = new EmbeddingGemma2VideoDecoder(new EmbeddingGemma2FFmpegOptions { LibraryDirectory = "/opt/ffmpeg-8/lib" });
using var media = new EmbeddingGemma2MultimodalEmbeddingGenerator(embedder, new EmbeddingGemma2MultimodalEmbeddingGeneratorOptions
{
ImageDecoder = (bytes, _) => EmbeddingGemma2ImageDecoder.Decode(bytes.Span),
VideoDecoder = (bytes, _) => decoder.Decode(bytes).Video, // upstream's sampling: 1 fps, at most 32 frames
});
Values with no matching decoder, other media types (audio, documents), UriContent and other content types fail with NotSupportedException; text containing media placeholders fails with ArgumentException; decoded frames without timing fail with EmbeddingGemma2VideoTimingRequiredException unless the embedder allows them. Usage counts every media token.
License and usage policy
The package is MIT OR Apache-2.0. The model weights and Starling's ONNX graph derived from them are Apache-2.0 (Google DeepMind). The model card states:
Deployments must adhere to the Gemma Prohibited Use Policy.
| 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
- Microsoft.Extensions.AI.Abstractions (>= 10.10.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Starlings.Models.EmbeddingGemma2 (= 0.1.0-preview.6)
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.5.0 | 112 | 11/3/2026 |
| 0.4.0 | 88 | 11/3/2026 |
| 0.3.0 | 128 | 10/19/2026 |
| 0.2.0 | 146 | 10/17/2026 |
| 0.1.0-preview.6 | 103 | 10/14/2026 |