Class: RubyLLM::Providers::Voyage

Inherits:
Provider
  • Object
show all
Includes:
Voyage::ContextualizedEmbeddings, Voyage::Embeddings, Voyage::Files, Voyage::Reranking
Defined in:
lib/ruby_llm/providers/voyage.rb,
lib/ruby_llm/providers/voyage/files.rb,
lib/ruby_llm/providers/voyage/reranking.rb,
lib/ruby_llm/providers/voyage/embeddings.rb,
lib/ruby_llm/providers/voyage/contextualized_embeddings.rb

Overview

Voyage retrieval API provider for RubyLLM.

Most applications should use RubyLLM.embed or Voyage.embed instead of instantiating this class directly.

Defined Under Namespace

Modules: ContextualizedEmbeddings, Embeddings, Files, Reranking

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assume_models_exist?Boolean

Indicates that Voyage model IDs can be used without registry entries.

Returns:

  • (Boolean)


74
75
76
# File 'lib/ruby_llm/providers/voyage.rb', line 74

def assume_models_exist?
  true
end

.configuration_optionsArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lists configuration keys registered for the Voyage provider.

Returns:

  • (Array<Symbol>)


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby_llm/providers/voyage.rb', line 53

def configuration_options
  %i[
    voyage_api_key
    voyage_api_base
    voyage_default_input_type
    voyage_default_truncation
    voyage_default_output_dimension
    voyage_default_output_dtype
    voyage_default_encoding_format
  ]
end

.configuration_requirementsArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lists configuration keys required to use the Voyage provider.

Returns:

  • (Array<Symbol>)


68
69
70
# File 'lib/ruby_llm/providers/voyage.rb', line 68

def configuration_requirements
  %i[voyage_api_key]
end

Instance Method Details

#api_baseString

Returns the configured Voyage API base URL.

Returns:

  • (String)


23
24
25
# File 'lib/ruby_llm/providers/voyage.rb', line 23

def api_base
  @config.voyage_api_base || 'https://api.voyageai.com/v1'
end

#embed(text, model:, dimensions: nil, provider_options: {}, **options) ⇒ RubyLLM::Embedding

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

RubyLLM 1.x does not expose per-request provider options for embeddings, so the extension's facade calls this richer provider method directly.

Parameters:

  • text (String, Array<String>)
  • model (String)
  • dimensions (Integer, nil) (defaults to: nil)
  • provider_options (Hash) (defaults to: {})

Returns:

  • (RubyLLM::Embedding)


42
43
44
45
46
47
# File 'lib/ruby_llm/providers/voyage.rb', line 42

def embed(text, model:, dimensions: nil, provider_options: {}, **options)
  payload = render_embedding_payload(text, model:, dimensions:, **options)
            .merge(provider_options.transform_keys(&:to_sym))
  response = @connection.post(embedding_url(model:), payload)
  parse_embedding_response(response, model:, text:, output_dtype: payload[:output_dtype])
end

#headersHash{String => String}

Returns authentication headers for Voyage requests.

Returns:

  • (Hash{String => String})


29
30
31
# File 'lib/ruby_llm/providers/voyage.rb', line 29

def headers
  { 'Authorization' => "Bearer #{@config.voyage_api_key}" }
end