WeaviateEx.Batch.BatchRetry (WeaviateEx v0.7.4)

View Source

Retry logic for batch operations with rate limit detection.

Provides exponential backoff and automatic retry for transient failures, especially rate limit errors from vectorizer APIs (OpenAI, Cohere, etc.).

Examples

if BatchRetry.should_retry?(error_message, retry_count) do
  Process.sleep(BatchRetry.calculate_backoff(retry_count))
  retry_operation()
end

Summary

Functions

Calculate the backoff delay in milliseconds for a given retry attempt.

Get the maximum number of retry attempts.

Check if an error message indicates a rate limit error.

Determine if an operation should be retried based on the error and attempt count.

Execute a function with automatic retry on rate limit errors.

Functions

calculate_backoff(attempt)

@spec calculate_backoff(non_neg_integer()) :: non_neg_integer()

Calculate the backoff delay in milliseconds for a given retry attempt.

Uses exponential backoff: 2^attempt * 1000 ms, capped at max_backoff.

max_retries()

@spec max_retries() :: non_neg_integer()

Get the maximum number of retry attempts.

rate_limit_error?(message)

@spec rate_limit_error?(String.t() | nil) :: boolean()

Check if an error message indicates a rate limit error.

Detects rate limit errors from various vectorizer APIs including OpenAI, Cohere, and others.

should_retry?(error_message, retry_count)

@spec should_retry?(String.t() | nil, non_neg_integer()) :: boolean()

Determine if an operation should be retried based on the error and attempt count.

Only rate limit errors are eligible for retry, and only up to max_retries.

with_retry(fun, opts \\ [])

@spec with_retry(
  (-> {:ok, term()} | {:error, term()}),
  keyword()
) :: {:ok, term()} | {:error, term()}

Execute a function with automatic retry on rate limit errors.

Options

  • :max_retries - Maximum retry attempts (default: 5)
  • :on_retry - Callback function called before each retry with (attempt, error)
  • :sleep - Function used to sleep between retries (default: &Process.sleep/1)

Examples

BatchRetry.with_retry(fn ->
  send_batch(objects)
end)