Exception: Parse::Embeddings::Voyage::BadRequestError
- Defined in:
- lib/parse/embeddings/voyage.rb
Overview
A 4xx the provider refused outright. Carries the HTTP status and the provider's own error text (bounded and terminal-sanitized) so callers can tell a request that was merely too large from one that is malformed.
Constant Summary collapse
- REQUEST_TOO_LARGE_PATTERNS =
Phrases that positively identify a request rejected for its SIZE (too many inputs or too many tokens summed across the batch). Matched case-insensitively against the provider's error text. Kept deliberately narrow: an unrelated 400 (bad parameter, invalid JSON) must never be mistaken for a size error, because the response to a size error is to split and resend.
Voyage documents these 400 causes as "Batch size is too large" and "Total number of tokens in the batch exceeds the limit"; its messages read like "The max allowed tokens per submitted batch is 120000" and "The batch size limit is 128".
[ /batch size is too large/i, /batch size limit/i, /total number of tokens in the batch exceeds/i, /max(?:imum)? allowed tokens per (?:submitted )?batch/i, ].freeze
- INPUT_TOO_LONG_PATTERNS =
Phrases identifying ONE input that is longer than the model's context window ("Number of tokens in an example exceeds the context length"). Splitting the batch cannot fix this.
[ /tokens in an example exceeds the context length/i, ].freeze
Instance Attribute Summary collapse
-
#detail ⇒ String?
readonly
The provider's error text, truncated and sanitized for terminals and logs.
-
#status ⇒ Integer?
readonly
The HTTP status the provider returned.
Instance Method Summary collapse
-
#initialize(message = nil, status: nil, detail: nil) ⇒ BadRequestError
constructor
A new instance of BadRequestError.
-
#input_too_long? ⇒ Boolean
True when a single input exceeds the model's context length.
-
#request_too_large? ⇒ Boolean
True when the provider rejected the request because the batch (input count or summed tokens) is too large, so resending it in smaller pieces can succeed.
Constructor Details
#initialize(message = nil, status: nil, detail: nil) ⇒ BadRequestError
Returns a new instance of BadRequestError.
155 156 157 158 159 |
# File 'lib/parse/embeddings/voyage.rb', line 155 def initialize( = nil, status: nil, detail: nil) super() @status = status @detail = detail end |
Instance Attribute Details
#detail ⇒ String? (readonly)
Returns the provider's error text, truncated and sanitized for terminals and logs.
153 154 155 |
# File 'lib/parse/embeddings/voyage.rb', line 153 def detail @detail end |
#status ⇒ Integer? (readonly)
Returns the HTTP status the provider returned.
150 151 152 |
# File 'lib/parse/embeddings/voyage.rb', line 150 def status @status end |
Instance Method Details
#input_too_long? ⇒ Boolean
Returns true when a single input exceeds the model's context length.
172 173 174 175 |
# File 'lib/parse/embeddings/voyage.rb', line 172 def input_too_long? return false if @detail.nil? INPUT_TOO_LONG_PATTERNS.any? { |re| re.match?(@detail) } end |
#request_too_large? ⇒ Boolean
Returns true when the provider rejected the request because the batch (input count or summed tokens) is too large, so resending it in smaller pieces can succeed.
164 165 166 167 168 |
# File 'lib/parse/embeddings/voyage.rb', line 164 def request_too_large? return true if @status == 413 return false if @detail.nil? || input_too_long? REQUEST_TOO_LARGE_PATTERNS.any? { |re| re.match?(@detail) } end |