[docs]classMlflowEmbeddings(Embeddings,BaseModel):"""Embedding LLMs in MLflow. To use, you should have the `mlflow[genai]` python package installed. For more information, see https://mlflow.org/docs/latest/llms/deployments. Example: .. code-block:: python from langchain_community.embeddings import MlflowEmbeddings embeddings = MlflowEmbeddings( target_uri="http://localhost:5000", endpoint="embeddings", ) """endpoint:str"""The endpoint to use."""target_uri:str"""The target URI to use."""_client:Any=PrivateAttr()"""The parameters to use for queries."""query_params:Dict[str,str]={}"""The parameters to use for documents."""documents_params:Dict[str,str]={}def__init__(self,**kwargs:Any):super().__init__(**kwargs)self._validate_uri()try:frommlflow.deploymentsimportget_deploy_clientself._client=get_deploy_client(self.target_uri)exceptImportErrorase:raiseImportError("Failed to create the client. "f"Please run `pip install mlflow{self._mlflow_extras}` to install ""required dependencies.")frome@propertydef_mlflow_extras(self)->str:return"[genai]"def_validate_uri(self)->None:ifself.target_uri=="databricks":returnallowed=["http","https","databricks"]ifurlparse(self.target_uri).schemenotinallowed:raiseValueError(f"Invalid target URI: {self.target_uri}. "f"The scheme must be one of {allowed}.")
[docs]classMlflowCohereEmbeddings(MlflowEmbeddings):"""Cohere embedding LLMs in MLflow."""query_params:Dict[str,str]={"input_type":"search_query"}documents_params:Dict[str,str]={"input_type":"search_document"}