Class: Woods::Resilience::RetryableProvider
- Inherits:
-
Object
- Object
- Woods::Resilience::RetryableProvider
- Includes:
- Embedding::Provider::Interface
- Defined in:
- lib/woods/resilience/retryable_provider.rb
Overview
Wraps an embedding provider with retry logic and optional circuit breaker.
Transparently retries transient failures with exponential backoff. When a circuit breaker is provided, all calls are routed through it, and CircuitOpenError is never retried.
Constant Summary collapse
- MAX_BACKOFF_SECONDS =
Maximum backoff delay in seconds. Without a cap, attempts 8+ sleep longer than most service-level timeouts (>25s) and compound retry storms across correlated workers.
30.0- BACKOFF_BASE =
Base multiplier for exponential backoff. Delay is roughly ‘BACKOFF_BASE * 2**attempt` with full jitter applied on top.
0.1
Instance Method Summary collapse
-
#dimensions ⇒ Integer
Return the dimensionality of the embedding vectors.
-
#embed(text) ⇒ Array<Float>
Embed a single text string with retry logic.
-
#embed_batch(texts) ⇒ Array<Array<Float>>
Embed multiple texts with retry logic.
-
#initialize(provider:, max_retries: 3, circuit_breaker: nil) ⇒ RetryableProvider
constructor
A new instance of RetryableProvider.
-
#max_input_tokens ⇒ Integer?
Delegate the per-provider input cap.
-
#model_name ⇒ String
Return the name of the embedding model.
Constructor Details
#initialize(provider:, max_retries: 3, circuit_breaker: nil) ⇒ RetryableProvider
Returns a new instance of RetryableProvider.
32 33 34 35 36 |
# File 'lib/woods/resilience/retryable_provider.rb', line 32 def initialize(provider:, max_retries: 3, circuit_breaker: nil) @provider = provider @max_retries = max_retries @circuit_breaker = circuit_breaker end |
Instance Method Details
#dimensions ⇒ Integer
Return the dimensionality of the embedding vectors.
61 62 63 |
# File 'lib/woods/resilience/retryable_provider.rb', line 61 def dimensions @provider.dimensions end |
#embed(text) ⇒ Array<Float>
Embed a single text string with retry logic.
44 45 46 |
# File 'lib/woods/resilience/retryable_provider.rb', line 44 def (text) with_retries { call_provider { @provider.(text) } } end |
#embed_batch(texts) ⇒ Array<Array<Float>>
Embed multiple texts with retry logic.
54 55 56 |
# File 'lib/woods/resilience/retryable_provider.rb', line 54 def (texts) with_retries { call_provider { @provider.(texts) } } end |
#max_input_tokens ⇒ Integer?
Delegate the per-provider input cap. The retry wrapper does not change the provider’s budget, so just hand through whatever the inner provider reports. Without this, ‘respond_to?` returns true via Interface but the call raises NotImplementedError.
78 79 80 81 82 |
# File 'lib/woods/resilience/retryable_provider.rb', line 78 def max_input_tokens return @provider.max_input_tokens if @provider.respond_to?(:max_input_tokens) nil end |
#model_name ⇒ String
Return the name of the embedding model.
68 69 70 |
# File 'lib/woods/resilience/retryable_provider.rb', line 68 def model_name @provider.model_name end |