vertexai: fix handling of single string in add_texts #860
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.
PR Description
Fix an issue where passing a single string to
add_texts
would split it into individual characters instead of treating it as a single document. This happens because Python strings are iterable, solist(texts)
would convert a string like "hello" into["h", "e", "l", "l", "o"]
. Added a check to automatically wrap a single string in a list.Relevant issues
Type
🐛 Bug Fix
✅ Test
Changes(optional)
add_texts
to detect single strings and wrap them in a listTesting(optional)
Added a new unit test
test_add_texts_with_single_string
that verifies a single string gets properly wrapped in a list before being processed.Note(optional)
This bug would cause quiet failures where users passing a single string would get unexpected results - the string would be split into individual characters and each character would be embedded as a separate document. The fix ensures a more intuitive API behavior where strings are handled as single documents.