Candil.Embeddings (Candil v3.0.0)

Copy Markdown View Source

Embedding generation abstraction over multiple providers.

Provides a unified embed/2 that dispatches to the correct provider (ollama, local llama.cpp, OpenAI-compatible API). Used as a lower-level embedding backend independent from Candil.Llm — this module accepts raw provider parameters (URL, model, api_key) rather than Candil structs.

All HTTP requests are routed through Candil.HTTP.post_json/4 which provides circuit breaker, retry, and rate limiting.

Summary

Types

Embedding vector

Functions

Generates an embedding vector for a single text string.

Generates embeddings for multiple texts in batched requests.

Types

embedding()

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

Embedding vector

Functions

embed(text, opts \\ [])

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

Generates an embedding vector for a single text string.

Options

  • :provider — provider type (default: "local")
  • :url — base URL
  • :model — model name
  • :api_key — API key for authenticated providers
  • :timeout — request timeout in ms (default: 30_000)

embed_batch(texts, opts \\ [])

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

Generates embeddings for multiple texts in batched requests.

Texts are grouped into chunks of :batch_size (default 32) and each chunk is sent as one request to providers that support batch input (ollama, openai-compat).

Options

  • :provider — provider type (default: "local")
  • :batch_size — max texts per request (default: 32)
  • :url, :model, :api_key, :timeout — forwarded to the provider