Skip to content

Embeddings 0.4.0 onnxtextembedder dispose

github-actions[bot] edited this page Aug 21, 2026 · 1 revision

Lodestar.Embeddings 0.4.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

OnnxTextEmbedder.Dispose

Release the native model session.

public void Dispose()

Exampleusing is the whole of it.

using Lodestar.Embeddings.Onnx;

using var embedder = new OnnxTextEmbedder("model.onnx");
float[] vector = embedder.Embed([101, 2054, 102], [1, 1, 1]);
// Dispose runs at the end of the scope.

Remarks — the session is native memory, not managed, so it is not reclaimed by a garbage collection and a forgotten embedder holds the model until the process ends. Loading several models in a long-running service without disposing is how that becomes visible.

Disposing twice is safe. Calling Embed or EmbedBatch afterwards is not, and throws.

Applies to — net10.0, netstandard2.0.

See alsoOnnxTextEmbedder.

Lodestar

Project

Clone this wiki locally