Commit f33e5d8
Fix embedding return format inconsistency for single-string arrays (#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 #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 #254
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Carmine Paolino <carmine@paolino.me>1 parent 78482e5 commit f33e5d8
File tree
6 files changed
+2479
-6
lines changed- lib/ruby_llm
- providers
- gemini
- openai
- spec
- fixtures/vcr_cassettes
- ruby_llm
6 files changed
+2479
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
0 commit comments