API reference · Kjarni 0.2.7

Class KjarniEmbeddingGenerator

Namespace: Kjarni.Extensions.AI
Assembly: Kjarni.Extensions.AI.dll

A backed by a local Kjarni . The model is loaded into your process and runs there, so text never leaves the machine and no network call is made after the first download.

public sealed class KjarniEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>>, IEmbeddingGenerator, IDisposable

Inheritance

object ← KjarniEmbeddingGenerator

Implements

IEmbeddingGenerator<string, Embedding<float>>, IEmbeddingGenerator, IDisposable

Remarks

Because inference is local and CPU/GPU bound rather than I/O bound, generation runs synchronously on the calling thread and returns an already-completed task. There is no thread-pool hop, so callers see the cost directly rather than through a hidden queue.

The underlying native embedder is not re-entrant, so concurrent calls to are serialized internally. A single instance is safe to register as a singleton and share across requests.

Constructors

KjarniEmbeddingGenerator(string, string, string?, bool, bool)

Creates a generator that owns its own .

public KjarniEmbeddingGenerator(string model = "minilm-l6-v2", string device = "cpu", string? cacheDir = null, bool normalize = true, bool quiet = true)

Parameters

model string

Kjarni model name, e.g. minilm-l6-v2.

device string

"cpu" or "gpu".

cacheDir string?

Model cache directory, or null for the default.

normalize bool

L2-normalize the returned vectors.

quiet bool

Suppress model download/progress output.

KjarniEmbeddingGenerator(Embedder, string?, bool)

Wraps an existing .

public KjarniEmbeddingGenerator(Embedder embedder, string? modelId = null, bool ownsEmbedder = false)

Parameters

embedder Embedder

The embedder to delegate to.

modelId string?

Model identifier reported through metadata.

ownsEmbedder bool

When true, disposing this generator also disposes embedder.

Properties

Dimensions

The embedding dimension produced by the underlying model.

public int Dimensions { get; }

Property Value

int

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GenerateAsync(IEnumerable<string>, EmbeddingGenerationOptions?, CancellationToken)

Generates embeddings for each of the supplied values.

public Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)

Parameters

values IEnumerable<string>

The sequence of values for which to generate embeddings.

options EmbeddingGenerationOptions?

The embedding generation options with which to configure the request.

cancellationToken CancellationToken

The to monitor for cancellation requests. The default is .

Returns

Task<GeneratedEmbeddings<Embedding<float>>>

The generated embeddings.

Exceptions

ArgumentNullException

values is null.

GetService(Type, object?)

Asks the for an object of the specified type serviceType.

public object? GetService(Type serviceType, object? serviceKey = null)

Parameters

serviceType Type

The type of object being requested.

serviceKey object?

An optional key that can be used to help identify the target service.

Returns

object?

The found object, otherwise null.

Remarks

The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the , including itself or any services it might be wrapping. For example, to access the for the instance, may be used to request it.

Exceptions

ArgumentNullException

serviceType is null.

Kjarni runs the same engine on every platform: