Module: RubyLLM::Voyage::VectorDecoder
- Defined in:
- lib/ruby_llm/voyage/vector_decoder.rb
Overview
Decodes Voyage Base64 vector representations.
The gem decodes API responses automatically; use this directly when parsing embeddings out of Voyage batch result files, which contain the same Base64 encoding.
Class Method Summary collapse
-
.decode(vector, output_dtype) ⇒ Array<Float>, Array<Integer>
Decodes a Base64 vector for the requested Voyage output type.
Class Method Details
.decode(vector, output_dtype) ⇒ Array<Float>, Array<Integer>
Decodes a Base64 vector for the requested Voyage output type.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_llm/voyage/vector_decoder.rb', line 24 def decode(vector, output_dtype) # unpack1('m0') is strict Base64: it raises ArgumentError on invalid # input, matching Base64.strict_decode64 without requiring the # base64 gem (no longer a default gem as of Ruby 3.5). bytes = vector.unpack1('m0') case (output_dtype || 'float').to_s when 'float' then bytes.unpack('e*') when 'int8', 'binary' then bytes.unpack('c*') when 'uint8', 'ubinary' then bytes.unpack('C*') else raise ArgumentError, "Unsupported Voyage output dtype: #{output_dtype.inspect}" end end |