LlamaCppEx.Embedding (LlamaCppEx v0.7.0)

Copy Markdown View Source

Generate embeddings from text using an embedding model.

Summary

Functions

Computes an embedding for a single text.

Computes embeddings for multiple texts.

Types

t()

@type t() :: [float()]

Functions

embed(model, text, opts \\ [])

@spec embed(LlamaCppEx.Model.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, String.t()}

Computes an embedding for a single text.

Options

  • :n_ctx - Context size. Defaults to 2048.
  • :pooling_type - Pooling type. Defaults to :unspecified (model's default). Values: :unspecified, :none, :mean, :cls, :last.
  • :normalize - Normalization mode. 2 = L2 (default), 0 = max-abs, -1 = none.

embed_batch(model, texts, opts \\ [])

@spec embed_batch(LlamaCppEx.Model.t(), [String.t()], keyword()) ::
  {:ok, [t()]} | {:error, String.t()}

Computes embeddings for multiple texts.

Uses a fresh context for each text. Accepts the same options as embed/3.