
    dh                     X    S SK r S SKrS SKJrJr  S SKJr  S SKJrJ	r	   " S S\\5      r
g)    N)AnyList)
Embeddings)	BaseModel
ConfigDictc                      ^  \ rS rSr% SrSr\\S'     SS\S\S\4U 4S jjjr	\
" SS	9rS
\\   S\\\      4S jrS\S\\   4S jrSrU =r$ )JohnSnowLabsEmbeddings	   a]  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hardware_targetkwargsc                 L  > [         TU ]  " S0 UD6   SSKJn  SSKJn   [        R                  [        R                  S'   [        R                  [        R                  S'   UR                  US9   [        U[        5      (       a  UR                  U5      U l        g[        X5      (       a  Xl        gUR#                  U5      U l        g! [         a  n[        S5      UeSnAff = f! [         a  n[        S	5      UeSnAff = f! [         a  n[        S
5      UeSnAff = f)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          c/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/johnsnowlabs.pyr   JohnSnowLabsEmbeddings.__init__   s    	"6"	(5	G+.>>BJJ'(25..BJJ./IIoI6
	>%%% XXe_
E//"
 __U3
+  	E 	  	G<=3F	G  	>34#=	>sS   C AC* 2+D D 5D 
C'C""C'*
D4D  D
D#DD#forbid)extratextsreturnc                     U R                   R                  USS9nSnUR                   H  nSU;   d  M  UnM     X#   R                  5        Vs/ sH  oUR                  5       PM     sn$ s  snf )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	embedding)r   predictcolumnstolist)r$   r+   dfemb_colcvecs         r'   embed_documents&JohnSnowLabsEmbeddings.embed_documentsA   sh     ZZJ?Aa  )+(:(:(<=(<

(<===s   A)textc                 ,    U R                  U/5      S   $ )zCompute query embeddings using a JohnSnowLabs transformer model.

Args:
    text: The text to embed.

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