-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Missing Nvidia embedding truncate mode (#1043)
* fix: Add NONE option to EmbeddingTruncateMode * refactor: Validate input with _missing_ method * test: Add EmbeddingTruncateMode test * refactor: Revert "refactor: Validate input with _missing_ method" This reverts commit 8334a50. * Update integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/truncate.py --------- Co-authored-by: Madeesh Kannan <[email protected]>
- Loading branch information
1 parent
18bb61d
commit 129ba54
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from haystack_integrations.components.embedders.nvidia import EmbeddingTruncateMode | ||
|
||
|
||
class TestEmbeddingTruncateMode: | ||
@pytest.mark.parametrize( | ||
"mode, expected", | ||
[ | ||
("START", EmbeddingTruncateMode.START), | ||
("END", EmbeddingTruncateMode.END), | ||
("NONE", EmbeddingTruncateMode.NONE), | ||
(EmbeddingTruncateMode.START, EmbeddingTruncateMode.START), | ||
(EmbeddingTruncateMode.END, EmbeddingTruncateMode.END), | ||
(EmbeddingTruncateMode.NONE, EmbeddingTruncateMode.NONE), | ||
], | ||
) | ||
def test_init_with_valid_mode(self, mode, expected): | ||
assert EmbeddingTruncateMode(mode) == expected | ||
|
||
def test_init_with_invalid_mode_raises_value_error(self): | ||
with pytest.raises(ValueError): | ||
invalid_mode = "INVALID" | ||
EmbeddingTruncateMode(invalid_mode) | ||
|
||
@pytest.mark.parametrize( | ||
"mode, expected", | ||
[ | ||
("START", EmbeddingTruncateMode.START), | ||
("END", EmbeddingTruncateMode.END), | ||
("NONE", EmbeddingTruncateMode.NONE), | ||
], | ||
) | ||
def test_from_str_with_valid_mode(self, mode, expected): | ||
assert EmbeddingTruncateMode.from_str(mode) == expected | ||
|
||
def test_from_str_with_invalid_mode_raises_value_error(self): | ||
with pytest.raises(ValueError): | ||
invalid_mode = "INVALID" | ||
EmbeddingTruncateMode.from_str(invalid_mode) |