API reference · Kjarni 0.2.7
Class KjarniEmbeddingGenerator
Namespace: Kjarni.Extensions.AI
Assembly: Kjarni.Extensions.AI.dll
A
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
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
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
Returns
Task<GeneratedEmbeddings<Embedding<float>>>
The generated embeddings.
Exceptions
values is null.
GetService(Type, object?)
Asks the 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
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
Exceptions
serviceType is null.
Kjarni runs the same engine on every platform: