Module: RubyLLM::Voyage
- Defined in:
- lib/ruby_llm/voyage.rb,
lib/ruby_llm/voyage/results.rb,
lib/ruby_llm/voyage/version.rb,
lib/ruby_llm/voyage/vector_decoder.rb
Overview
Voyage retrieval integration for RubyLLM.
Use Voyage.embed_query and Voyage.embed_documents for the two sides of retrieval,
Voyage.embed for request-level Voyage options, or the conventional
RubyLLM.embed(..., provider: :voyage) interface.
Defined Under Namespace
Modules: VectorDecoder Classes: ContextualizedChunk, ContextualizedEmbedding, ContextualizedResult, FileDeletion, Page, RerankResult, Reranking, VoyageFile
Constant Summary collapse
- VERSION =
Current gem version.
'0.1.0'- UNSET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal sentinel used to distinguish an omitted option from an explicit
nilvalue. Object.new.freeze
Class Method Summary collapse
-
.contextualized_embed(inputs, model: 'voyage-context-4', input_type: UNSET, dimensions: nil, output_dtype: UNSET, encoding_format: UNSET, auto_chunk: nil, chunk_size: nil, chunk_overlap: nil, provider_options: {}, context: nil) ⇒ RubyLLM::Voyage::ContextualizedEmbedding
Generates context-aware embeddings for grouped document chunks.
-
.delete_files(file_ids, context: nil) ⇒ RubyLLM::Voyage::FileDeletion
Deletes one or more Voyage files atomically.
-
.embed(text, model: nil, dimensions: nil, input_type: UNSET, truncation: UNSET, output_dtype: UNSET, encoding_format: UNSET, provider_options: {}, context: nil) ⇒ RubyLLM::Embedding
Generates embeddings with a Voyage text embedding model.
-
.embed_documents(texts, **options) ⇒ RubyLLM::Embedding
Embeds content for the document side of retrieval.
-
.embed_query(text, **options) ⇒ RubyLLM::Embedding
Embeds search text for the query side of retrieval.
-
.file_content(file_id, context: nil) ⇒ String
(also: download_file)
Downloads a Voyage file's raw contents.
-
.list_files(purpose: nil, limit: nil, order: nil, after: nil, context: nil) ⇒ RubyLLM::Voyage::Page
Lists Voyage files with cursor pagination.
-
.rerank(query:, documents:, model: 'rerank-2.5-lite', top_k: nil, return_documents: UNSET, truncation: UNSET, provider_options: {}, context: nil) ⇒ RubyLLM::Voyage::Reranking
Reranks documents for a query with a Voyage reranker.
-
.retrieve_file(file_id, context: nil) ⇒ RubyLLM::Voyage::VoyageFile
(also: find_file)
Retrieves metadata for one Voyage file.
-
.upload_file(path, purpose: 'batch', context: nil) ⇒ RubyLLM::Voyage::VoyageFile
Uploads a JSONL file to Voyage.
Class Method Details
.contextualized_embed(inputs, model: 'voyage-context-4', input_type: UNSET, dimensions: nil, output_dtype: UNSET, encoding_format: UNSET, auto_chunk: nil, chunk_size: nil, chunk_overlap: nil, provider_options: {}, context: nil) ⇒ RubyLLM::Voyage::ContextualizedEmbedding
Generates context-aware embeddings for grouped document chunks.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ruby_llm/voyage.rb', line 156 def self.(inputs, model: 'voyage-context-4', input_type: UNSET, dimensions: nil, output_dtype: UNSET, encoding_format: UNSET, auto_chunk: nil, chunk_size: nil, chunk_overlap: nil, provider_options: {}, context: nil) validate_input!(:inputs, inputs) config = context&.config || RubyLLM.config provider = Providers::Voyage.new(config) payload = { model: model, input_count: inputs.length, input_type: input_type, auto_chunk: auto_chunk } .reject { |_key, value| value.equal?(UNSET) } RubyLLM.instrument('contextualized_embedding.voyage', payload, config:) do |event| result = provider.( inputs, model:, input_type:, dimensions:, output_dtype:, encoding_format:, auto_chunk:, chunk_size:, chunk_overlap:, provider_options: ) event[:result] = result event[:response_model] = result.model event[:input_tokens] = result.input_tokens result end end |
.delete_files(file_ids, context: nil) ⇒ RubyLLM::Voyage::FileDeletion
Deletes one or more Voyage files atomically.
216 217 218 |
# File 'lib/ruby_llm/voyage.rb', line 216 def self.delete_files(file_ids, context: nil) provider_for(context).delete_files(file_ids) end |
.embed(text, model: nil, dimensions: nil, input_type: UNSET, truncation: UNSET, output_dtype: UNSET, encoding_format: UNSET, provider_options: {}, context: nil) ⇒ RubyLLM::Embedding
Generates embeddings with a Voyage text embedding model.
This facade exposes Voyage-specific options that are not first-class
keywords on RubyLLM.embed in RubyLLM 1.x. It returns the same
Embedding result type and emits the same instrumentation event.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_llm/voyage.rb', line 45 def self.(text, model: nil, dimensions: nil, input_type: UNSET, truncation: UNSET, output_dtype: UNSET, encoding_format: UNSET, provider_options: {}, context: nil) validate_input!(:text, text) config = context&.config || RubyLLM.config model ||= config. provider = Providers::Voyage.new(config) payload = { provider: provider.slug, model: model, input: text, dimensions: dimensions, input_type: input_type, truncation: truncation, output_dtype: output_dtype, encoding_format: encoding_format }.reject { |_key, value| value.equal?(UNSET) } RubyLLM.instrument('embedding.ruby_llm', payload, config:) do |event| result = provider.( text, model:, dimensions:, input_type:, truncation:, output_dtype:, encoding_format:, provider_options: ) event[:result] = result event[:response_model] = result.model event[:input_tokens] = result.input_tokens result end end |
.embed_documents(texts, **options) ⇒ RubyLLM::Embedding
Embeds content for the document side of retrieval.
Equivalent to embed with input_type: 'document'. Accepts one text
or a batch of up to 1,000.
110 111 112 |
# File 'lib/ruby_llm/voyage.rb', line 110 def self.(texts, **) (texts, 'document', __method__, ) end |
.embed_query(text, **options) ⇒ RubyLLM::Embedding
Embeds search text for the query side of retrieval.
Equivalent to embed with input_type: 'query'. Pair with
embed_documents so Voyage optimizes both sides of retrieval, and
configure default_embedding_model and voyage_default_output_dimension once
to keep call sites small.
94 95 96 |
# File 'lib/ruby_llm/voyage.rb', line 94 def self.(text, **) (text, 'query', __method__, ) end |
.file_content(file_id, context: nil) ⇒ String Also known as: download_file
Downloads a Voyage file's raw contents.
208 209 210 |
# File 'lib/ruby_llm/voyage.rb', line 208 def self.file_content(file_id, context: nil) provider_for(context).file_content(file_id) end |
.list_files(purpose: nil, limit: nil, order: nil, after: nil, context: nil) ⇒ RubyLLM::Voyage::Page
Lists Voyage files with cursor pagination.
200 201 202 |
# File 'lib/ruby_llm/voyage.rb', line 200 def self.list_files(purpose: nil, limit: nil, order: nil, after: nil, context: nil) provider_for(context).list_files(purpose:, limit:, order: order&.to_s, after:) end |
.rerank(query:, documents:, model: 'rerank-2.5-lite', top_k: nil, return_documents: UNSET, truncation: UNSET, provider_options: {}, context: nil) ⇒ RubyLLM::Voyage::Reranking
Reranks documents for a query with a Voyage reranker.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ruby_llm/voyage.rb', line 124 def self.rerank(query:, documents:, model: 'rerank-2.5-lite', top_k: nil, return_documents: UNSET, truncation: UNSET, provider_options: {}, context: nil) validate_input!(:query, query) validate_input!(:documents, documents) config = context&.config || RubyLLM.config provider = Providers::Voyage.new(config) payload = { model: model, query: query, document_count: documents.length } RubyLLM.instrument('rerank.voyage', payload, config:) do |event| result = provider.rerank( query:, documents:, model:, top_k:, return_documents:, truncation:, provider_options: ) event[:result] = result event[:response_model] = result.model event[:input_tokens] = result.input_tokens result end end |
.retrieve_file(file_id, context: nil) ⇒ RubyLLM::Voyage::VoyageFile Also known as: find_file
Retrieves metadata for one Voyage file.
189 190 191 |
# File 'lib/ruby_llm/voyage.rb', line 189 def self.retrieve_file(file_id, context: nil) provider_for(context).retrieve_file(file_id) end |
.upload_file(path, purpose: 'batch', context: nil) ⇒ RubyLLM::Voyage::VoyageFile
Uploads a JSONL file to Voyage.
181 182 183 |
# File 'lib/ruby_llm/voyage.rb', line 181 def self.upload_file(path, purpose: 'batch', context: nil) provider_for(context).upload_file(path, purpose:) end |