Class: RubyLLM::Embedding
- Inherits:
-
Object
- Object
- RubyLLM::Embedding
- Defined in:
- lib/ruby_llm/embedding.rb
Overview
Core embedding interface.
Instance Attribute Summary collapse
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#vectors ⇒ Object
readonly
Returns the value of attribute vectors.
Class Method Summary collapse
-
.embed(text, model: nil, provider: nil, assume_model_exists: false, context: nil, dimensions: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
-
#initialize(vectors:, model:, input_tokens: 0) ⇒ Embedding
constructor
A new instance of Embedding.
Constructor Details
#initialize(vectors:, model:, input_tokens: 0) ⇒ Embedding
Returns a new instance of Embedding.
8 9 10 11 12 |
# File 'lib/ruby_llm/embedding.rb', line 8 def initialize(vectors:, model:, input_tokens: 0) @vectors = vectors @model = model @input_tokens = input_tokens end |
Instance Attribute Details
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
6 7 8 |
# File 'lib/ruby_llm/embedding.rb', line 6 def input_tokens @input_tokens end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/ruby_llm/embedding.rb', line 6 def model @model end |
#vectors ⇒ Object (readonly)
Returns the value of attribute vectors.
6 7 8 |
# File 'lib/ruby_llm/embedding.rb', line 6 def vectors @vectors end |
Class Method Details
.embed(text, model: nil, provider: nil, assume_model_exists: false, context: nil, dimensions: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_llm/embedding.rb', line 14 def self.(text, # rubocop:disable Metrics/ParameterLists model: nil, provider: nil, assume_model_exists: false, context: nil, dimensions: nil) config = context&.config || RubyLLM.config model ||= config. model, provider_instance = Models.resolve(model, provider: provider, assume_exists: assume_model_exists, config: config) model_id = model.id provider_instance.(text, model: model_id, dimensions:) end |