API reference · Kjarni 0.2.7

Class KjarniEmbeddingGeneratorExtensions

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

Extension methods for exposing a Kjarni as an .

public static class KjarniEmbeddingGeneratorExtensions

Inheritance

object ← KjarniEmbeddingGeneratorExtensions

Methods

AddKjarniEmbeddingGenerator(IServiceCollection, string, string, string?, bool, bool)

Registers a local Kjarni embedding generator as a singleton .

public static IServiceCollection AddKjarniEmbeddingGenerator(this IServiceCollection services, string model = "minilm-l6-v2", string device = "cpu", string? cacheDir = null, bool normalize = true, bool quiet = true)

Parameters

services IServiceCollection

The service collection.

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.

Returns

IServiceCollection

Remarks

Registered as a singleton because model weights are loaded once and are expensive to re-initialize. The generator serializes concurrent calls internally, so sharing one instance across requests is safe.

AsEmbeddingGenerator(Embedder, string?, bool)

Wraps this in an .

public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(this Embedder embedder, string? modelId = null, bool ownsEmbedder = false)

Parameters

embedder Embedder

The embedder to wrap.

modelId string?

Model identifier reported through metadata.

ownsEmbedder bool

When true, disposing the returned generator also disposes embedder. Defaults to false so the caller keeps ownership of an embedder it created.

Returns

IEmbeddingGenerator<string, Embedding<float>>

Kjarni runs the same engine on every platform: