Skip to content

Commit fec8fea

Browse files
Fix: avoid ambiguous truth value for empty numpy array in HuggingfaceEmbeddings (fixes #2080) (#2308)
Title: Fix ambiguous truth value for empty NumPy arrays in HuggingfaceEmbeddings (fixes #2080) Description: This PR resolves an issue where HuggingfaceEmbeddings would raise a ValueError when evaluating an empty NumPy array in a boolean context. Problem: Directly checking a NumPy array with if array: is ambiguous when the array is empty or multidimensional, leading to errors like: ValueError: The truth value of an array with more than one element is ambiguous. This could occur when users try to generate embeddings with empty inputs. Solution: Added an explicit check for empty arrays before any boolean evaluation. Ensures that the embedding function handles empty inputs safely without errors. Testing: Verified embeddings for non-empty inputs work as expected. Confirmed empty inputs no longer raise errors. Monorepo CI pipeline passes successfully (lint, formatting, and tests). Related Issue: Fixes #2080Title: Fix ambiguous truth value for empty NumPy arrays in HuggingfaceEmbeddings (fixes #2080)
1 parent bf6c82e commit fec8fea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/ragas/embeddings/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ def __post_init__(self):
475475
np.intersect1d(
476476
list(MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES.values()),
477477
config.architectures or [],
478-
)
478+
).size
479+
!= 0
479480
)
480481

481482
if self.is_cross_encoder:

0 commit comments

Comments
 (0)