The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Update ascend.py (#30060)
cold-eye7c175e3fdaed
diff --git a/libs/community/langchain_community/embeddings/ascend.py b/libs/community/langchain_community/embeddings/ascend.pyindex c8cb059177..940b84bbfc 100644--- a/libs/community/langchain_community/embeddings/ascend.py+++ b/libs/community/langchain_community/embeddings/ascend.py@@ -30,6 +30,7 @@ class AscendEmbeddings(Embeddings, BaseModel):document_instruction: str = ""use_fp16: bool = Truepooling_method: Optional[str] = "cls"+ batch_size: int = 32model: Anytokenizer: Any@@ -119,7 +120,18 @@ class AscendEmbeddings(Embeddings, BaseModel):)def embed_documents(self, texts: List[str]) -> List[List[float]]:- return self.encode([self.document_instruction + text for text in texts])+ try:+ import numpy as np+ except ImportError as e:+ raise ImportError(+ "Unable to import numpy, please install with `pip install -U numpy`."+ ) from e+ embedding_list = []+ for i in range(0, len(texts), self.batch_size):+ texts_ = texts[i : i + self.batch_size]+ emb = self.encode([self.document_instruction + text for text in texts_])+ embedding_list.append(emb)+ return np.concatenate(embedding_list)def embed_query(self, text: str) -> List[float]:return self.encode([self.query_instruction + text])[0]