Onnx onnxtextembedder - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Onnx is 0.1.0 — read its documentation.

HomeOnnxONNX inference

OnnxTextEmbedder

Runs an ONNX sentence-transformer and returns one vector per text.

public sealed class OnnxTextEmbedder : IDisposable

Constructor — takes the path to an ONNX model. Constructing it loads that model, which is why this type is the one place in Lodestar that needs a file you supply.

PropertiesDimension is the width of the vectors the model produces. MaxSequenceLength is the longest input, in tokens, the model accepts; longer inputs are truncated by the encoder rather than refused here.

Example — the shape of a call. It is not executed: see below.

using Lodestar.Onnx;

using var embedder = new OnnxTextEmbedder("model.onnx");

float[][] vectors = embedder.EmbedBatch(["a first sentence", "a second one"]);
int width = embedder.Dimension;

Remarksevery fence on this page and its members is docs-run: skip, and that is not an oversight. A running example would need a model of tens of megabytes, and weights are never committed to this repository — decisions/0002 is the rule, and the packaging sample declares the same exclusion for the same reason. The fences are still compiled against the packed package, so a renamed member still fails CI; only the values are unchecked, which is why none of them carries a // =>.

ONNX Runtime is referenced by this package and nowhere else in Lodestar, and this type is the only one in it. A consumer who tokenizes, pools or searches without inferring never restores a native runtime — that is what Lodestar.Onnx exists to make true, rather than nearly true.

It is IDisposable and holds native resources: the model session outlives garbage collection, so Dispose is not optional.

Applies to — net10.0, netstandard2.0.

See alsoBatchEncoder, the ONNX inference guide, the semantic search guide, the Python equivalence table.

Members

Member What it does
OnnxTextEmbedder.Dispose Release the native model session.
OnnxTextEmbedder.Embed One vector, from token ids you already have.
OnnxTextEmbedder.EmbedBatch A vector per text, in one session run.