embed

suspend fun embed(text: String, normalize: Boolean = true): FloatArray(source)

Computes the embedding of text on a dedicated embedding context (created on first use, separate from the generation session, so embeddings never disturb it). The vector is pooled with LlamaContextConfig.embeddingPooling (for causal LMs usually the last token's hidden state).

Parameters

normalize

L2-normalize the vector (unit length), e.g. for cosine similarity.

Throws