Skip to content

vertexai: fix handling of single string in add_texts #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ykoh42
Copy link
Contributor

@ykoh42 ykoh42 commented Apr 15, 2025

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, so list(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)

  • Added type checking in add_texts to detect single strings and wrap them in a list
  • Added unit test to verify the fix works as expected

Testing(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.

@lkuligin
Copy link
Collaborator

Since the signature is texts: Iterable[str],, I'm not sure a user should even pass a single string :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants