The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: add VoyageEmbeddings truncation (#17638)
Bagatura058c8812d0c
diff --git a/libs/community/langchain_community/embeddings/voyageai.py b/libs/community/langchain_community/embeddings/voyageai.pyindex 93109d45c6..f8b1a4059e 100644--- a/libs/community/langchain_community/embeddings/voyageai.py+++ b/libs/community/langchain_community/embeddings/voyageai.py@@ -86,6 +86,15 @@ class VoyageEmbeddings(BaseModel, Embeddings):show_progress_bar: bool = False"""Whether to show a progress bar when embedding. Must have tqdm installed if setto True."""+ truncation: Optional[bool] = None+ """Whether to truncate the input texts to fit within the context length.++ If True, over-length input texts will be truncated to fit within the context+ length, before vectorized by the embedding model. If False, an error will be+ raised if any given text exceeds the context length. If not specified+ (defaults to None), we will truncate the input text before sending it to the+ embedding model if it slightly exceeds the context window length. If it+ significantly exceeds the context window length, an error will be raised."""class Config:"""Configuration for this pydantic object."""@@ -104,12 +113,14 @@ class VoyageEmbeddings(BaseModel, Embeddings):self, input: List[str], input_type: Optional[str] = None) -> Dict:api_key = cast(SecretStr, self.voyage_api_key).get_secret_value()- params = {+ params: Dict = {"url": self.voyage_api_base,"headers": {"Authorization": f"Bearer {api_key}"},"json": {"model": self.model, "input": input, "input_type": input_type},"timeout": self.request_timeout,}+ if self.truncation is not None:+ params["json"]["truncation"] = self.truncationreturn paramsdef _get_embeddings(