[docs]classVoyageAIEmbeddings(BaseModel,Embeddings):"""VoyageAIEmbeddings embedding model. Example: .. code-block:: python from langchain_voyageai import VoyageAIEmbeddings model = VoyageAIEmbeddings() """_client:voyageai.Client=Field(exclude=True)_aclient:voyageai.client_async.AsyncClient=Field(exclude=True)model:strbatch_size:intshow_progress_bar:bool=Falsetruncation:Optional[bool]=Nonevoyage_api_key:SecretStr=Field(alias="api_key",default_factory=secret_from_env("VOYAGE_API_KEY",error_message="Must set `VOYAGE_API_KEY` environment variable or ""pass `api_key` to VoyageAIEmbeddings constructor.",),)classConfig:extra="forbid"allow_population_by_field_name=True@root_validator(pre=True)defdefault_values(cls,values:dict)->dict:"""Set default batch size based on model"""model=values.get("model")batch_size=values.get("batch_size")ifbatch_sizeisNone:values["batch_size"]=72ifmodelin["voyage-2","voyage-02"]else7returnvalues@root_validator(pre=False,skip_on_failure=True)defvalidate_environment(cls,values:dict)->dict:"""Validate that VoyageAI credentials exist in environment."""api_key_str=values["voyage_api_key"].get_secret_value()values["_client"]=voyageai.Client(api_key=api_key_str)values["_aclient"]=voyageai.client_async.AsyncClient(api_key=api_key_str)returnvaluesdef_get_batch_iterator(self,texts:List[str])->Iterable:ifself.show_progress_bar:try:fromtqdm.autoimporttqdm# type: ignoreexceptImportErrorase:raiseImportError("Must have tqdm installed if `show_progress_bar` is set to True. ""Please install with `pip install tqdm`.")frome_iter=tqdm(range(0,len(texts),self.batch_size))else:_iter=range(0,len(texts),self.batch_size)# type: ignorereturn_iter