
    Ng                     `    d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	  G d dee          Z
dS )    N)AnyList)
Embeddings)	BaseModel
ConfigDictc                        e Zd ZU dZdZeed<   	 	 ddededef fdZ e	d	          Z
d
ee         deee                  fdZdedee         fdZ xZS )JohnSnowLabsEmbeddingsay  JohnSnowLabs embedding models

    To use, you should have the ``johnsnowlabs`` python package installed.
    Example:
        .. code-block:: python

            from langchain_community.embeddings.johnsnowlabs import JohnSnowLabsEmbeddings

            embedding = JohnSnowLabsEmbeddings(model='embed_sentence.bert')
            output = embedding.embed_query("foo bar")
    embed_sentence.bertmodelcpuhardware_targetkwargsc                     t                      j        di | 	 ddlm} ddlm} n"# t          $ r}t          d          |d}~ww xY w	 t          j        t          j
        d<   t          j        t          j
        d<   |                    |           n"# t          $ r}t          d	          |d}~ww xY w	 t          |t                    r|                    |          | _        dS t          ||          r	|| _        dS |                    |          | _        dS # t          $ r}t          d
          |d}~ww xY w)z"Initialize the johnsnowlabs model.r   )nlp)NLUPipelinez`Could not import johnsnowlabs python package. Please install it with `pip install johnsnowlabs`.NPYSPARK_PYTHONPYSPARK_DRIVER_PYTHON)r   zFailure starting Spark SessionzFailure loading model )super__init__johnsnowlabsr   nlu.pipe.pipeliner   ImportErrorsys
executableosenvironstart	Exception
isinstancestrloadr   to_nlu_pipe)selfr   r   r   r   r   exc	__class__s          g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/johnsnowlabs.pyr   zJohnSnowLabsEmbeddings.__init__   s    	""6"""	((((((5555555 	 	 	E  		G+.>BJ'(25.BJ./IIoI6666 	G 	G 	G<==3F	G	>%%% 4 XXe__


E;// 4"


 __U33


 	> 	> 	>344#=	>sQ   ) 
AAAAB 
B4B//B48/D )D D 
D=(D88D=forbid)extratextsreturnc                     | j                             |d          }d}|j        D ]}d|v r|}	d ||                                         D             S )zCompute doc embeddings using a JohnSnowLabs transformer model.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        document)output_levelN	embeddingc                 6    g | ]}|                                 S r   )tolist).0vecs     r'   
<listcomp>z:JohnSnowLabsEmbeddings.embed_documents.<locals>.<listcomp>P   s     ===

===    )r   predictcolumnsr1   )r$   r*   dfemb_colcs        r'   embed_documentsz&JohnSnowLabsEmbeddings.embed_documentsA   si     ZJ?? 	 	Aa==7(:(:(<(<====r5   textc                 :    |                      |g          d         S )zCompute query embeddings using a JohnSnowLabs transformer model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r;   )r$   r<   s     r'   embed_queryz"JohnSnowLabsEmbeddings.embed_queryR   s     ##TF++A..r5   )r
   r   )__name__
__module____qualname____doc__r   r   __annotations__r!   r   r   model_configr   floatr;   r>   __classcell__)r&   s   @r'   r	   r	   	   s         
 
 'E3&&& +$#> #>#> #> 	#> #> #> #> #> #>J :  L>T#Y >4U3D > > > >"	/ 	/U 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/r5   r	   )r   r   typingr   r   langchain_core.embeddingsr   pydanticr   r   r	   r   r5   r'   <module>rJ      s    				 



         0 0 0 0 0 0 * * * * * * * *R/ R/ R/ R/ R/Y
 R/ R/ R/ R/ R/r5   