EmbeddingBatch
langbatch.EmbeddingBatch.EmbeddingBatch
Bases: Batch
EmbeddingBatch is a base class for embedding batch classes. Utilizes OpenAI Embedding API format as the standard request format.
Source code in langbatch\EmbeddingBatch.py
__init__
create
classmethod
create(data: List[str], request_kwargs: Dict = {}, batch_kwargs: Dict = {}) -> EmbeddingBatch
Create an embedding batch when given a list of texts.
Parameters:
-
data
(List[str]
) โA list of texts to be embedded.
-
request_kwargs
(Dict
, default:{}
) โAdditional keyword arguments for the API call. Ex. model, encoding_format, etc.
-
batch_kwargs
(Dict
, default:{}
) โAdditional keyword arguments for the batch class.
Returns:
-
EmbeddingBatch
โAn instance of the EmbeddingBatch class.
Raises:
-
BatchInitializationError
โIf the input data is invalid.
Usage:
batch = OpenAIEmbeddingBatch.create([
"Hello world",
"Hello LangBatch"
],
request_kwargs={"model": "text-embedding-3-small"})
Source code in langbatch\EmbeddingBatch.py
get_results
Retrieve the results of the embedding batch.
Returns:
-
Tuple[List[Dict[str, Any]], List[Dict[str, Any]]] | Tuple[None, None]
โA tuple containing successful and unsuccessful results. Successful results: A list of dictionaries with "embedding" and "custom_id" keys. Unsuccessful results: A list of dictionaries with "error" and "custom_id" keys.
Usage:
successful_results, unsuccessful_results = batch.get_results()
for result in successful_results:
print(result["embedding"])