Skip to content

Embeddings tokenizerjsonloader loadbpeasync

github-actions[bot] edited this page Aug 26, 2026 · 24 revisions

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

TokenizerJsonLoader.LoadBpeAsync

Reads the BPE model a tokenizer.json declares, asynchronously.

public static Task<BpeVocabulary> LoadBpeAsync(Stream source, ArtifactLoadOptions options = null, CancellationToken cancellationToken = default)

Parameterssource is a readable stream, never disposed here; path is the file to read. options bounds what will be accepted and defaults to ArtifactLoadOptions's own defaults. cancellationToken cancels the read.

ReturnsTask<BpeVocabulary>, completing with the loaded vocabulary.

ExceptionsArgumentNullException for a null source or path. InvalidDataException when the file declares a different model, declares a pipeline this package does not reproduce, or exceeds a bound in options — the message names what was refused and why. OperationCanceledException when cancellationToken is signalled.

Example — the same load, awaited.

using Lodestar.Embeddings.Persistence;
using Lodestar.Embeddings.Tokenization;

static async Task<BpeVocabulary> LoadAsync() =>
    await TokenizerJsonLoader.LoadBpeAsync(File.OpenRead("tokenizer.json"));

BpeVocabulary vocab = LoadAsync().GetAwaiter().GetResult();

Remarks — Same file, same reads and the same refusals as LoadBpe, byte_fallback included; only the I/O is asynchronous.

Applies to — net10.0, netstandard2.0.

See alsoTokenizerJsonLoader.LoadBpe, TokenizerJsonLoader, the persistence index.

Lodestar

Project

Clone this wiki locally