Recollect.EmbeddingProvider behaviour (recollect v0.5.1)

Copy Markdown View Source

Behaviour for embedding providers.

Implementations generate vector embeddings for text. The host app configures which provider to use and provides credentials via a :credentials_fn callback.

Summary

Callbacks

Number of dimensions in the embedding vectors.

Generate a single embedding for a text string.

Generate embeddings for a list of texts.

Identifier for the model that will produce embeddings under the given opts. Used by the pipeline to record provenance alongside each vector. Returns nil when the provider can't (or doesn't want to) declare a stable id.

Functions

Generate embedding for a single text using the configured provider.

Generate embeddings for multiple texts using the configured provider.

Resolve the model id of the currently configured provider, or nil if the provider doesn't implement model_id/1.

Callbacks

dimensions(opts)

@callback dimensions(opts :: keyword()) :: pos_integer()

Number of dimensions in the embedding vectors.

embed(text, opts)

(optional)
@callback embed(text :: String.t(), opts :: keyword()) ::
  {:ok, [float()]} | {:error, term()}

Generate a single embedding for a text string.

Convenience wrapper — delegates to generate/2 by default.

generate(texts, opts)

@callback generate(texts :: [String.t()], opts :: keyword()) ::
  {:ok, [[float()]]} | {:error, term()}

Generate embeddings for a list of texts.

Returns {:ok, [[float()]]} where each inner list is a vector, or {:error, reason}.

model_id(opts)

(optional)
@callback model_id(opts :: keyword()) :: String.t() | nil

Identifier for the model that will produce embeddings under the given opts. Used by the pipeline to record provenance alongside each vector. Returns nil when the provider can't (or doesn't want to) declare a stable id.

Functions

embed(text, opts \\ [])

Generate embedding for a single text using the configured provider.

generate(texts, opts \\ [])

Generate embeddings for multiple texts using the configured provider.

model_id(opts \\ [])

Resolve the model id of the currently configured provider, or nil if the provider doesn't implement model_id/1.