
    7|h.                     \    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y)    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y)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                    |j                  d      d|d<   |j                  d      }t        j                  j                  d      t	        d      	 ddl}|j                  |      |d<   |S # t        $ r t	        d| d	| d
      w xY w)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       n/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/spacy_embeddings.pyvalidate_environmentz$SpacyEmbeddings.validate_environment   s      ::l#+#3F< ZZ-
 >>##G,4V 	!JJz2F5M   	
| ,..8\ :77 	s   A- -B	textsc                 z    |D cg c]+  }| j                  |      j                  j                         - c}S c c}w )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.
        r   vectortolist)selfr$   texts      r"   embed_documentszSpacyEmbeddings.embed_documentsD   s0     <AA4%%,,.AAAs   08r*   c                 T    | j                  |      j                  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_queryP   s!     xx~$$++--    c                     K   t        d      w)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.NotImplementedError)r)   r$   s     r"   aembed_documentsz SpacyEmbeddings.aembed_documents\         ""WXX   c                     K   t        d      w)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.
        r1   r2   r-   s     r"   aembed_queryzSpacyEmbeddings.aembed_queryi   r5   r6   )__name__
__module____qualname____doc__r   str__annotations__r   r   r   r	   model_configr
   classmethodr   r#   r   floatr+   r.   r4   r8   r   r/   r"   r   r      s     'J&C#H2FL(#%$ %3 %  $%N
BT#Y 
B4U3D 
B
. 
.U 
.YDI Y$tE{:K YYs YtE{ Yr/   r   )importlib.utilr   typingr   r   r   r   langchain_core.embeddingsr   pydanticr   r	   r
   r   r   r/   r"   <module>rF      s)     , , 0 ; ;lYi lYr/   