fix: prevent N×M reply explosion in HuggingFaceLocalGenerator with multiple stop_words#11413
Conversation
…ltiple stop_words The list comprehension [reply.replace(stop_word, "").rstrip() for reply in replies for stop_word in self.stop_words] creates a cross-product: N replies × M stop_words produces N×M outputs. Half of the extra replies still contain the stop word, and downstream code receives an unexpected number of replies. Replace the comprehension with an explicit outer loop over stop_words so that each stop_word is stripped from every reply sequentially, preserving the invariant N replies → N replies out. Fixes deepset-ai#11409 Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
|
Someone is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
NIK-TIGER-BILL seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
@NIK-TIGER-BILL Thank you for opening this pull request. Would you please agree to our CLA? Otherwise we can't merge this pull request. #11413 (comment) |
Done! |
|
@NIK-TIGER-BILL Your commit in this pull request appears not to be linked to your user account. Could you please fix that? Here are instructions: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/troubleshooting-commits/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user |
|
@julian-risch The commit author is already set to |
Related Issues
Proposed Changes:
The list comprehension in
HuggingFaceLocalGenerator.run()used twoforclauses to remove stop words from replies:This creates a cross-product: with N replies and M stop words the output contains N×M replies instead of N. Half of the extra replies still contain the stop word, and downstream components receive an unexpected number of replies.
The fix replaces the comprehension with an explicit outer loop over
stop_words, matching the already-correct implementation inHuggingFaceChatLocalGenerator(chat/hugging_face_local.py, line 654):How did you test it?
test_run_multiple_stop_words_removalthat mocks a pipeline returning 2 replies with 2 stop words configured.Notes for the reviewer
This is a minimal, surgical change. The sibling chat generator already uses the same sequential approach, so this only brings the non-chat generator in line with the existing pattern.
Checklist
fix: ....This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.