U
    ™ÀÂh<	  ã                   @   sF   d Z ddlmZmZmZ ddlmZ ddlmZ G dd„ deeƒZ	dS )z)Wrapper around text2vec embedding models.é    )ÚAnyÚListÚOptional)Ú
Embeddings)Ú	BaseModelc                       s¬   e Zd ZU dZdZee ed< dZe	ed< dZ
eed< dZee ed< dZe	ed	< ddd
œe	ee e	dœ‡ fdd„Zee eee  dœdd„Zeee dœdd„Z‡  ZS )ÚText2vecEmbeddingsa–  text2vec embedding models.

    Install text2vec first, run 'pip install -U text2vec'.
    The gitbub repository for text2vec is : https://github.com/shibing624/text2vec

    Example:
        .. code-block:: python

            from langchain_community.embeddings.text2vec import Text2vecEmbeddings

            embedding = Text2vecEmbeddings()
            embedding.embed_documents([
                "This is a CoSENT(Cosine Sentence) model.",
                "It maps sentences to a 768 dimensional dense vector space.",
            ])
            embedding.embed_query(
                "It can be used for text matching or semantic search."
            )
    NÚmodel_name_or_pathZMEANÚencoder_typeé   Úmax_seq_lengthÚdeviceÚmodel©r   r   )r   r   Úkwargsc             
      s€   zddl m} W n, tk
r< } ztdƒ|‚W 5 d }~X Y nX i }|d k	rR||d< |pb|f ||—Ž}tƒ jf ||dœ|—Ž d S )Nr   )ÚSentenceModelzIUnable to import text2vec, please install with `pip install -U text2vec`.r   r   )Ztext2vecr   ÚImportErrorÚsuperÚ__init__)Úselfr   r   r   r   ÚeZmodel_kwargs©Ú	__class__© úK/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/embeddings/text2vec.pyr   $   s    ÿýzText2vecEmbeddings.__init__)ÚtextsÚreturnc                 C   s   | j  |¡S )zÀEmbed documents using the text2vec embeddings model.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        ©r   Úencode)r   r   r   r   r   Úembed_documents9   s    
z"Text2vecEmbeddings.embed_documents)Útextr   c                 C   s   | j  |¡S )z¦Embed a query using the text2vec embeddings model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r   r   r   r   r   Úembed_queryE   s    
zText2vecEmbeddings.embed_query)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚstrÚ__annotations__r	   r   r   Úintr   r   r   r   Úfloatr   r    Ú__classcell__r   r   r   r   r   	   s   
üûr   N)
r$   Útypingr   r   r   Zlangchain_core.embeddingsr   Zlangchain_core.pydantic_v1r   r   r   r   r   r   Ú<module>   s   