Class: RubyLLM::EmbeddingRequest
- Inherits:
-
Object
- Object
- RubyLLM::EmbeddingRequest
- Includes:
- Support::Inspectable
- Defined in:
- lib/ruby_llm/embedding_request.rb
Overview
An EmbeddingRequest is an embedding awaiting a provider-side batch. RubyLLM.embed_later stages one; submit an array of them with RubyLLM.batch, and once the batch completes, collecting the results fills in #result:
requests = texts.map { |text| RubyLLM.(text) }
batch = RubyLLM.batch(requests)
# later, once batch.refresh.complete?
batch.results
requests.first.result.vectors
Constant Summary
Constants included from Support::Inspectable
Support::Inspectable::TRUNCATE_AT
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
readonly
The requested vector size, or
nilfor the model's default. -
#model ⇒ Object
readonly
The Model of the embedding model the request targets.
-
#provider ⇒ Object
readonly
The Provider the request will be submitted through.
-
#result ⇒ Object
The Embedding, once the batch has completed and its results have been collected.
-
#text ⇒ Object
readonly
The text staged for embedding.
Instance Method Summary collapse
-
#initialize(text, model: nil, provider: nil, dimensions: nil, context: nil) ⇒ EmbeddingRequest
constructor
:nodoc:.
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#render ⇒ Object
Returns the request payload this embedding request would send to the provider, in the provider's wire format.
Methods included from Support::Inspectable
#full_inspect, #inspect, #pretty_print
Constructor Details
#initialize(text, model: nil, provider: nil, dimensions: nil, context: nil) ⇒ EmbeddingRequest
:nodoc:
35 36 37 38 39 40 41 |
# File 'lib/ruby_llm/embedding_request.rb', line 35 def initialize(text, model: nil, provider: nil, dimensions: nil, context: nil) # :nodoc: config = context&.config || RubyLLM.config model ||= config. @model, @provider = Models.resolve(model, provider:, config:) @text = text @dimensions = dimensions end |
Instance Attribute Details
#dimensions ⇒ Object (readonly)
The requested vector size, or nil for the model's default.
25 26 27 |
# File 'lib/ruby_llm/embedding_request.rb', line 25 def dimensions @dimensions end |
#model ⇒ Object (readonly)
The Model of the embedding model the request targets.
22 23 24 |
# File 'lib/ruby_llm/embedding_request.rb', line 22 def model @model end |
#provider ⇒ Object (readonly)
The Provider the request will be submitted through.
28 29 30 |
# File 'lib/ruby_llm/embedding_request.rb', line 28 def provider @provider end |
#result ⇒ Object
The Embedding, once the batch has completed and its results have
been collected. nil until then, and for requests that failed.
Batch result collection writes it.
33 34 35 |
# File 'lib/ruby_llm/embedding_request.rb', line 33 def result @result end |
#text ⇒ Object (readonly)
The text staged for embedding.
19 20 21 |
# File 'lib/ruby_llm/embedding_request.rb', line 19 def text @text end |
Instance Method Details
#inspect_attributes ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/ruby_llm/embedding_request.rb', line 49 def inspect_attributes # :nodoc: { text: text, model: model.id, dimensions: dimensions, result: result } end |
#render ⇒ Object
Returns the request payload this embedding request would send to the provider, in the provider's wire format.
45 46 47 |
# File 'lib/ruby_llm/embedding_request.rb', line 45 def render @provider.(text, model: @model, dimensions: @dimensions) end |