Fix embedding return format inconsistency for single-string arrays#267
Merged
crmne merged 2 commits intocrmne:mainfrom Jul 16, 2025
Merged
Fix embedding return format inconsistency for single-string arrays#267crmne merged 2 commits intocrmne:mainfrom
crmne merged 2 commits intocrmne:mainfrom
Conversation
When passing an array with a single string to the embed method, it was returning a flat array of floats instead of an array containing one array of floats. This broke the expected consistent behavior where arrays always return arrays of arrays. Fixed by: - Passing the original text parameter through to parse_embedding_response - Checking if input was an array before unwrapping single embeddings - Ensuring RubyLLM.embed([string]) returns [[vector]] not [vector] Fixes crmne#254 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Jun 30, 2025
crmne
approved these changes
Jul 16, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #267 +/- ##
=======================================
Coverage 89.72% 89.72%
=======================================
Files 75 75
Lines 2812 2812
Branches 555 555
=======================================
Hits 2523 2523
Misses 289 289 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
infinityrobot
added a commit
to infinityrobot/ruby_llm
that referenced
this pull request
Jul 18, 2025
17 tasks
parruda
pushed a commit
to parruda/ruby_llm
that referenced
this pull request
Nov 18, 2025
…rmne#267) ## Summary - Fixes inconsistent return format when passing an array with a single string to the embed method - Ensures `RubyLLM.embed([string])` returns `[[vector]]` instead of `[vector]` - Maintains backward compatibility for single string inputs ## Problem As reported in crmne#254, the embedding API had inconsistent behavior: ```ruby RubyLLM.embed(string) -> [vector] ✓ RubyLLM.embed([string, string]) -> [[vector], [vector]] ✓ RubyLLM.embed([string]) -> [vector] ✗ (should be [[vector]]) ``` ## Solution - Modified the base Provider class to pass the original `text` parameter to `parse_embedding_response` - Updated OpenAI and Gemini providers to check if input was an array before unwrapping single embeddings - Added comprehensive test coverage for this edge case ## Test plan - [x] Added new test case specifically for single-string arrays - [x] All existing tests pass - [x] Verified fix works for both OpenAI and Gemini providers Fixes crmne#254 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Carmine Paolino <carmine@paolino.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RubyLLM.embed([string])returns[[vector]]instead of[vector]Problem
As reported in #254, the embedding API had inconsistent behavior:
Solution
textparameter toparse_embedding_responseTest plan
Fixes #254
🤖 Generated with Claude Code