Class: Geminize::Models::EmbeddingRequest
- Inherits:
-
Object
- Object
- Geminize::Models::EmbeddingRequest
- Defined in:
- lib/geminize/models/embedding_request.rb
Overview
Represents a request for embedding generation from the Gemini API
Constant Summary collapse
- TASK_TYPE_UNSPECIFIED =
Task type constants
"TASK_TYPE_UNSPECIFIED"- RETRIEVAL_QUERY =
"RETRIEVAL_QUERY"- RETRIEVAL_DOCUMENT =
"RETRIEVAL_DOCUMENT"- SEMANTIC_SIMILARITY =
"SEMANTIC_SIMILARITY"- CLASSIFICATION =
"CLASSIFICATION"- CLUSTERING =
"CLUSTERING"- QUESTION_ANSWERING =
"QUESTION_ANSWERING"- FACT_VERIFICATION =
"FACT_VERIFICATION"- CODE_RETRIEVAL_QUERY =
"CODE_RETRIEVAL_QUERY"- TASK_TYPES =
Supported task types for embeddings
[ TASK_TYPE_UNSPECIFIED, # Default unspecified type RETRIEVAL_QUERY, # For embedding queries for retrieval RETRIEVAL_DOCUMENT, # For embedding documents for retrieval SEMANTIC_SIMILARITY, # For embeddings that will be compared for similarity CLASSIFICATION, # For embeddings that will be used for classification CLUSTERING, # For embeddings that will be clustered QUESTION_ANSWERING, # For embeddings used in question answering FACT_VERIFICATION, # For embeddings used in fact verification CODE_RETRIEVAL_QUERY # For embeddings used in code retrieval ].freeze
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#task_type ⇒ Object
readonly
Returns the value of attribute task_type.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#batch? ⇒ Boolean
(also: #multiple?)
Check if this request contains multiple texts.
-
#initialize(text = nil, model_name = nil, **options) ⇒ EmbeddingRequest
constructor
Initialize a new embedding request.
-
#single_request_hash(text_input) ⇒ Hash
Create a single request hash for the given text.
-
#to_h ⇒ Object
Alias for to_hash.
-
#to_hash ⇒ Hash
Get the request as a hash.
Constructor Details
#initialize(text = nil, model_name = nil, **options) ⇒ EmbeddingRequest
Initialize a new embedding request
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/geminize/models/embedding_request.rb', line 40 def initialize(text = nil, model_name = nil, **) # Support both old positional params and new named params if text.nil? && model_name.nil? # New named parameters style @model_name = .delete(:model_name) @text = .delete(:text) else # Old positional parameters style @text = text @model_name = model_name end @task_type = [:task_type] || RETRIEVAL_DOCUMENT @dimensions = [:dimensions] @title = [:title] validate! end |
Instance Attribute Details
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
7 8 9 |
# File 'lib/geminize/models/embedding_request.rb', line 7 def dimensions @dimensions end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
7 8 9 |
# File 'lib/geminize/models/embedding_request.rb', line 7 def model_name @model_name end |
#task_type ⇒ Object (readonly)
Returns the value of attribute task_type.
7 8 9 |
# File 'lib/geminize/models/embedding_request.rb', line 7 def task_type @task_type end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/geminize/models/embedding_request.rb', line 7 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/geminize/models/embedding_request.rb', line 7 def title @title end |
Instance Method Details
#batch? ⇒ Boolean Also known as: multiple?
Check if this request contains multiple texts
76 77 78 |
# File 'lib/geminize/models/embedding_request.rb', line 76 def batch? @text.is_a?(Array) end |
#single_request_hash(text_input) ⇒ Hash
Create a single request hash for the given text
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/geminize/models/embedding_request.rb', line 86 def single_request_hash(text_input) request = { model: @model_name, content: { parts: [ { text: text_input.to_s } ] }, taskType: @task_type } # Add title if provided request[:content][:title] = @title if @title # Add optional parameters if they exist request[:dimensions] = @dimensions if @dimensions request end |
#to_h ⇒ Object
Alias for to_hash
70 71 72 |
# File 'lib/geminize/models/embedding_request.rb', line 70 def to_h to_hash end |
#to_hash ⇒ Hash
Get the request as a hash
61 62 63 64 65 66 67 |
# File 'lib/geminize/models/embedding_request.rb', line 61 def to_hash if batch? build_batch_request else build_single_request end end |