Module: RubyLLM::Providers::Voyage::Embeddings Private
- Defined in:
- lib/ruby_llm/providers/voyage/embeddings.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Voyage embeddings request and response mapping.
Instance Method Summary collapse
-
#embedding_url ⇒ String
private
Returns the embeddings endpoint relative to the configured API base.
-
#parse_embedding_response(response, model:, text:, output_dtype: nil) ⇒ RubyLLM::Embedding
private
Converts a Voyage response into a RubyLLM embedding result.
-
#render_embedding_payload(text, model:, dimensions: nil, input_type: RubyLLM::Voyage::UNSET, truncation: RubyLLM::Voyage::UNSET, output_dtype: RubyLLM::Voyage::UNSET, encoding_format: RubyLLM::Voyage::UNSET) ⇒ Hash
private
Converts RubyLLM embedding arguments to a Voyage request body.
Instance Method Details
#embedding_url ⇒ String
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.
Returns the embeddings endpoint relative to the configured API base.
12 13 14 |
# File 'lib/ruby_llm/providers/voyage/embeddings.rb', line 12 def (...) 'embeddings' end |
#parse_embedding_response(response, model:, text:, output_dtype: nil) ⇒ 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.
Converts a Voyage response into a RubyLLM embedding result.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_llm/providers/voyage/embeddings.rb', line 51 def (response, model:, text:, output_dtype: nil) data = response.body vectors = data.fetch('data').map { |item| item.fetch('embedding') } if vectors.first.is_a?(String) vectors.map! do |vector| RubyLLM::Voyage::VectorDecoder.decode(vector, output_dtype) end end vectors = vectors.first if vectors.length == 1 && !text.is_a?(Array) Embedding.new( vectors: vectors, model: data['model'] || model, input_tokens: data.dig('usage', 'total_tokens') || 0 ) end |
#render_embedding_payload(text, model:, dimensions: nil, input_type: RubyLLM::Voyage::UNSET, truncation: RubyLLM::Voyage::UNSET, output_dtype: RubyLLM::Voyage::UNSET, encoding_format: RubyLLM::Voyage::UNSET) ⇒ Hash
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.
Converts RubyLLM embedding arguments to a Voyage request body.
A nil dimensions argument falls back to the configured
voyage_default_output_dimension.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_llm/providers/voyage/embeddings.rb', line 28 def (text, model:, dimensions: nil, input_type: RubyLLM::Voyage::UNSET, truncation: RubyLLM::Voyage::UNSET, output_dtype: RubyLLM::Voyage::UNSET, encoding_format: RubyLLM::Voyage::UNSET) { model: model, input: text, input_type: enum_option(input_type, :voyage_default_input_type), truncation: configured_option(truncation, :voyage_default_truncation), output_dimension: dimensions || @config.voyage_default_output_dimension, output_dtype: enum_option(output_dtype, :voyage_default_output_dtype), encoding_format: enum_option(encoding_format, :voyage_default_encoding_format) }.compact end |