
    NgA                     d    d dl Zd dlmZmZmZmZ d dlmZ d dl	m
Z
mZmZ  G d de
e          ZdS )    N)AnyDictListOptional)
Embeddings)	BaseModel
ConfigDictmodel_validatorc                   :   e Zd ZU dZdZeed<   dZee	         ed<    e
dd          Z ed	
          edede	fd                        Zdee         deee                  fdZdedee         fdZdee         deee                  fdZdedee         fdZdS )SpacyEmbeddingsa  Embeddings by spaCy models.

    Attributes:
        model_name (str): Name of a spaCy model.
        nlp (Any): The spaCy model loaded into memory.

    Methods:
        embed_documents(texts: List[str]) -> List[List[float]]:
            Generates embeddings for a list of documents.
        embed_query(text: str) -> List[float]:
            Generates an embedding for a single piece of text.
    en_core_web_sm
model_nameNnlpforbid )extraprotected_namespacesbefore)modevaluesreturnc                 D   |                     d          d|d<   |                     d          }t          j                            d          t	          d          	 ddl}|                    |          |d<   n$# t          $ r t	          d| d	| d
          w xY w|S )aE  
        Validates that the spaCy package and the model are installed.

        Args:
            values (Dict): The values provided to the class constructor.

        Returns:
            The validated values.

        Raises:
            ValueError: If the spaCy package or the
            model are not installed.
        r   Nr   spacyzDSpaCy package not found. Please install it with `pip install spacy`.r   r   zSpaCy model 'z>' not found. Please install it with `python -m spacy download z%`or provide a valid spaCy model name.)get	importlibutil	find_spec
ValueErrorr   loadOSError)clsr   r   r   s       k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/spacy_embeddings.pyvalidate_environmentz$SpacyEmbeddings.validate_environment   s      ::l##+#3F< ZZ--
 >##G,,4>  	LLL!JJz22F5MM 	 	 	7
 7 7.87 7 7  	 s   A< <!Btextsc                        fd|D             S )z
        Generates embeddings for a list of documents.

        Args:
            texts (List[str]): The documents to generate embeddings for.

        Returns:
            A list of embeddings, one for each document.
        c                 h    g | ].}                     |          j                                        /S r   r   vectortolist).0textselfs     r"   
<listcomp>z3SpacyEmbeddings.embed_documents.<locals>.<listcomp>O   s2    AAA4%,,..AAA    r   r,   r$   s   ` r"   embed_documentszSpacyEmbeddings.embed_documentsE   s      BAAA5AAAAr.   r+   c                 Z    |                      |          j                                        S )z
        Generates an embedding for a single piece of text.

        Args:
            text (str): The text to generate an embedding for.

        Returns:
            The embedding for the text.
        r'   r,   r+   s     r"   embed_queryzSpacyEmbeddings.embed_queryQ   s#     xx~~$++---r.   c                 $   K   t          d          )aA  
        Asynchronously generates embeddings for a list of documents.
        This method is not implemented and raises a NotImplementedError.

        Args:
            texts (List[str]): The documents to generate embeddings for.

        Raises:
            NotImplementedError: This method is not implemented.
        3Asynchronous embedding generation is not supported.NotImplementedErrorr/   s     r"   aembed_documentsz SpacyEmbeddings.aembed_documents]          ""WXXXr.   c                 $   K   t          d          )a<  
        Asynchronously generates an embedding for a single piece of text.
        This method is not implemented and raises a NotImplementedError.

        Args:
            text (str): The text to generate an embedding for.

        Raises:
            NotImplementedError: This method is not implemented.
        r5   r6   r2   s     r"   aembed_queryzSpacyEmbeddings.aembed_queryj   r9   r.   )__name__
__module____qualname____doc__r   str__annotations__r   r   r   r	   model_configr
   classmethodr   r#   r   floatr0   r3   r8   r;   r   r.   r"   r   r      s]          'J&&&C#:H2FFFL_(###&$ &3 & & & [ $#&P
BT#Y 
B4U3D 
B 
B 
B 
B
. 
.U 
. 
. 
. 
.YDI Y$tE{:K Y Y Y YYs YtE{ Y Y Y Y Y Yr.   r   )importlib.utilr   typingr   r   r   r   langchain_core.embeddingsr   pydanticr   r	   r
   r   r   r.   r"   <module>rI      s        , , , , , , , , , , , , 0 0 0 0 0 0 ; ; ; ; ; ; ; ; ; ;mY mY mY mY mYi mY mY mY mY mYr.   