Skip to content

Commit f0083c3

Browse files
committed
Update Cohere embeddings implementation for updates made in #267
1 parent 209ae93 commit f0083c3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/ruby_llm/providers/cohere/embeddings.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ def render_embedding_payload(input, model:, dimensions: nil)
2424
}
2525
end
2626

27-
def parse_embedding_response(response, model:)
27+
def parse_embedding_response(response, model:, text:)
2828
data = response.body
2929
raise Error.new(response, data['message']) if data['message'] && response.status != 200
3030

3131
vectors = data.dig('embeddings', 'float') || []
3232
input_tokens = data.dig('meta', 'billed_units', 'input_tokens') || 0
3333

34-
# If we only got one embedding, return it as a single vector
35-
vectors = vectors.first if vectors.length == 1
34+
# If we only got one embedding AND the input was a single string (not an array),
35+
# return it as a single vector
36+
vectors = vectors.first if vectors.length == 1 && !text.is_a?(Array)
3637

3738
Embedding.new(vectors:, model:, input_tokens:)
3839
end

0 commit comments

Comments
 (0)