-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ai21[patch]: AI21 Labs Batch Support in Embeddings (#18633)
Description: Added support for batching when using AI21 Embeddings model Twitter handle: https://github.com/AI21Labs --------- Co-authored-by: Asaf Gardin <[email protected]> Co-authored-by: Erick Friis <[email protected]>
- Loading branch information
1 parent
321db89
commit 4d7f6fa
Showing
7 changed files
with
147 additions
and
23 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
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
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
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,29 @@ | ||
from typing import List | ||
|
||
import pytest | ||
|
||
from langchain_ai21.embeddings import _split_texts_into_batches | ||
|
||
|
||
@pytest.mark.parametrize( | ||
ids=[ | ||
"when_chunk_size_is_2__should_return_3_chunks", | ||
"when_texts_is_empty__should_return_empty_list", | ||
"when_chunk_size_is_1__should_return_10_chunks", | ||
], | ||
argnames=["input_texts", "chunk_size", "expected_output"], | ||
argvalues=[ | ||
(["a", "b", "c", "d", "e"], 2, [["a", "b"], ["c", "d"], ["e"]]), | ||
([], 3, []), | ||
( | ||
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], | ||
1, | ||
[["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"]], | ||
), | ||
], | ||
) | ||
def test_chunked_text_generator( | ||
input_texts: List[str], chunk_size: int, expected_output: List[List[str]] | ||
) -> None: | ||
result = list(_split_texts_into_batches(input_texts, chunk_size)) | ||
assert result == expected_output |