Class: AgentHarness::Embeddings

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_harness/embeddings.rb

Overview

Provider-neutral embedding execution backed by RubyLLM.

Constant Summary collapse

DEFAULT_TIMEOUT =
300
DEFAULT_MAX_ATTEMPTS =
3
RETRY_BASE_DELAY =
0.25
RETRY_MAX_DELAY =
2.0
CANCELLATION_POLL_INTERVAL =
0.05
TRANSIENT_ERRORS =
[RateLimitError, TimeoutError].freeze

Instance Method Summary collapse

Constructor Details

#initialize(model:, credentials:, endpoint: nil, headers: {}, timeout: DEFAULT_TIMEOUT, max_attempts: DEFAULT_MAX_ATTEMPTS, cancellation: nil, observer: nil, request_id: nil) ⇒ Embeddings

Returns a new instance of Embeddings.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/agent_harness/embeddings.rb', line 17

def initialize(model:, credentials:, endpoint: nil, headers: {}, timeout: DEFAULT_TIMEOUT,
  max_attempts: DEFAULT_MAX_ATTEMPTS, cancellation: nil, observer: nil, request_id: nil)
  @model = model
  @api_key = credential(credentials, :api_key)
  @endpoint = endpoint
  @headers = headers.to_h.transform_keys(&:to_s).freeze
  @timeout = timeout
  @max_attempts = max_attempts
  @cancellation = cancellation
  @observer = observer
  @request_id = request_id || SecureRandom.uuid
  validate!
end

Instance Method Details

#call(inputs:, dimensions: nil) ⇒ Object



31
32
33
34
35
36
# File 'lib/agent_harness/embeddings.rb', line 31

def call(inputs:, dimensions: nil)
  inputs = Array(inputs)
  return EmbeddingResult.new(vectors: [], model: @model) if inputs.empty?

  execute(inputs, dimensions)
end