a
    bgA                     @   sV   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 de
eZdS )    N)AnyDictListOptional)
Embeddings)	BaseModel
ConfigDictmodel_validatorc                   @   s   e Zd ZU dZdZeed< dZee	 ed< e
dddZed	d
eee	dddZee eee  dddZeee dddZee eee  dddZeee dd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nlpZforbid )extraZprotected_namespacesbefore)mode)valuesreturnc              	   C   s   | ddu rd|d< | d}tjddu r8tdzddl}|||d< W n( tyz   td| d	| d
Y n0 |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   r   r   }/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/embeddings/spacy_embeddings.pyvalidate_environment   s"    

z$SpacyEmbeddings.validate_environment)textsr   c                    s    fd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                    s   g | ]}  |j qS r   r   Zvectortolist).0textselfr   r   
<listcomp>O       z3SpacyEmbeddings.embed_documents.<locals>.<listcomp>r   r%   r   r   r$   r   embed_documentsE   s    
zSpacyEmbeddings.embed_documents)r#   r   c                 C   s   |  |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#   r   r   r   embed_queryQ   s    
zSpacyEmbeddings.embed_queryc                    s   t ddS )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.NNotImplementedErrorr(   r   r   r   aembed_documents]   s    z SpacyEmbeddings.aembed_documentsc                    s   t ddS )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.
        r,   Nr-   r*   r   r   r   aembed_queryj   s    zSpacyEmbeddings.aembed_query)__name__
__module____qualname____doc__r   str__annotations__r   r   r   r   Zmodel_configr	   classmethodr   r   r   floatr)   r+   r/   r0   r   r   r   r   r
      s   
(r
   )importlib.utilr   typingr   r   r   r   Zlangchain_core.embeddingsr   Zpydanticr   r   r	   r
   r   r   r   r   <module>   s   