o
    Zh_	                     @   sF   d dl mZmZ d dlmZ d dlmZmZ dZG dd deeZ	dS )    )AnyList)
Embeddings)	BaseModel
ConfigDictzBhttps://tfhub.dev/google/universal-sentence-encoder-multilingual/3c                       s   e Zd ZU dZdZeed< eZe	ed< 	 def fddZ
edd	d
Zdee	 deee  fddZde	dee fddZ  ZS )TensorflowHubEmbeddingsa  TensorflowHub embedding models.

    To use, you should have the ``tensorflow_text`` python package installed.

    Example:
        .. code-block:: python

            from langchain_community.embeddings import TensorflowHubEmbeddings
            url = "https://tfhub.dev/google/universal-sentence-encoder-multilingual/3"
            tf = TensorflowHubEmbeddings(model_url=url)
    Nembed	model_urlkwargsc                    sl   t  jdi | zddl}W n ty   tdw zddl}W n ty,   tdw || j| _dS )z2Initialize the tensorflow_hub and tensorflow_text.r   NzeCould not import tensorflow-hub python package. Please install it with `pip install tensorflow-hub``.zgCould not import tensorflow_text python package. Please install it with `pip install tensorflow_text``. )super__init__tensorflow_hubImportErrortensorflow_textloadr	   r   )selfr
   r   r   	__class__r   d/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/tensorflow_hub.pyr      s    z TensorflowHubEmbeddings.__init__Zforbidr   )extraZprotected_namespacestextsreturnc                 C   s(   t tdd |}| | }| S )zCompute doc embeddings using a TensorflowHub embedding model.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        c                 S   s   |  ddS )N
 )replace)xr   r   r   <lambda><   s    z9TensorflowHubEmbeddings.embed_documents.<locals>.<lambda>)listmapr   numpytolist)r   r   Z
embeddingsr   r   r   embed_documents3   s   	z'TensorflowHubEmbeddings.embed_documentstextc                 C   s(   | dd}| |g d }| S )zCompute query embeddings using a TensorflowHub embedding model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   r   r   )r   r   r    r!   )r   r#   Z	embeddingr   r   r   embed_query@   s   	z#TensorflowHubEmbeddings.embed_query)__name__
__module____qualname____doc__r   r   __annotations__DEFAULT_MODEL_URLr	   strr   r   Zmodel_configr   floatr"   r$   __classcell__r   r   r   r   r   	   s   
 r   N)
typingr   r   Zlangchain_core.embeddingsr   Zpydanticr   r   r*   r   r   r   r   r   <module>   s
    