API reference · Kjarni 0.2.7

Class Embedder

Namespace: Kjarni
Assembly: Kjarni.dll

Text embedding model.

public class Embedder : IDisposable

Inheritance

object ← Embedder

Implements

IDisposable

Constructors

Embedder(string?, string, string?, bool, bool)

Create a new Embedder.

public Embedder(string? model = null, string device = "cpu", string? cacheDir = null, bool normalize = true, bool quiet = false)

Parameters

model string?

Model name (e.g., "minilm-l6-v2")

device string

"cpu" or "gpu"

cacheDir string?

Directory to cache models

normalize bool

L2-normalize embeddings

quiet bool

Suppress progress output

Properties

Dim

Get the embedding dimension.

public int Dim { get; }

Property Value

int

Methods

CosineSimilarity(float[], float[])

Cosine similarity of two vectors of the same length, from -1 to 1.

public static float CosineSimilarity(float[] a, float[] b)

Parameters

a float[]

b float[]

Returns

float

Exceptions

ArgumentException

The vectors have different lengths.

Dispose()

Releases the native model. The object cannot be used afterwards.

public void Dispose()

Encode(string)

Encode a single text to an embedding vector.

public float[] Encode(string text)

Parameters

text string

Returns

float[]

EncodeBatch(string[])

Encode multiple texts to embedding vectors.

public float[][] EncodeBatch(string[] texts)

Parameters

texts string[]

Returns

float[][]

~Embedder()

Releases the native model if was not called.

protected ~Embedder()

Similarity(string, string)

Compute cosine similarity between two texts.

public float Similarity(string text1, string text2)

Parameters

text1 string

text2 string

Returns

float

Kjarni runs the same engine on every platform: