Nous.Memory.Embedding behaviour (nous v0.17.1)

Copy Markdown View Source

Behaviour for embedding providers.

Implement this behaviour to use any embedding provider with the memory system. If no embedding provider is configured, the memory system falls back to keyword-only search.

Summary

Functions

Get the embedding dimension for a provider.

Embed a single text using the given provider module and options. Returns {:ok, embedding} or {:error, reason}.

Embed a batch of texts. Falls back to sequential embed/2 calls if embed_batch/2 is not implemented.

Callbacks

dimension()

@callback dimension() :: pos_integer()

embed(text, opts)

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

embed_batch(texts, opts)

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

Functions

dimension(provider)

@spec dimension(module()) :: pos_integer()

Get the embedding dimension for a provider.

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

@spec embed(module(), String.t(), keyword()) :: {:ok, [float()]} | {:error, term()}

Embed a single text using the given provider module and options. Returns {:ok, embedding} or {:error, reason}.

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

@spec embed_batch(module(), [String.t()], keyword()) ::
  {:ok, [[float()]]} | {:error, term()}

Embed a batch of texts. Falls back to sequential embed/2 calls if embed_batch/2 is not implemented.