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

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)

Get the embedding dimension for a provider.

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

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

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

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