
    dh5                     `    S SK JrJrJrJr  S SKJr  S SKJr  S SK	J
r
JrJr   " S S\
\5      rg)    )AnyDictListOptional)
Embeddings)get_from_dict_or_env)	BaseModelFieldmodel_validatorc                       \ rS rSr% Sr\" SSS9r\\S'   \" SS9r	\
\S	'    \
\S
'    Sr\\   \S'    \" SS9\S\S\4S j5       5       rS\
S\\   4S jrS\\
   S\\\      4S jrSrg)ZhipuAIEmbeddings   u^  ZhipuAI embedding model integration.

Setup:

    To use, you should have the ``zhipuai`` python package installed, and the
    environment variable ``ZHIPU_API_KEY`` set with your API KEY.

    More instructions about ZhipuAi Embeddings, you can get it
    from  https://open.bigmodel.cn/dev/api#vector

    .. code-block:: bash

        pip install -U zhipuai
        export ZHIPU_API_KEY="your-api-key"

Key init args — completion params:
    model: Optional[str]
        Name of ZhipuAI model to use.
    api_key: str
        Automatically inferred from env var `ZHIPU_API_KEY` if not provided.

See full list of supported init args and their descriptions in the params section.

Instantiate:

    .. code-block:: python

        from langchain_community.embeddings import ZhipuAIEmbeddings

        embed = ZhipuAIEmbeddings(
            model="embedding-2",
            # api_key="...",
        )

Embed single text:
    .. code-block:: python

        input_text = "The meaning of life is 42"
        embed.embed_query(input_text)

    .. code-block:: python

        [-0.003832892, 0.049372625, -0.035413884, -0.019301128, 0.0068899863, 0.01248398, -0.022153955, 0.006623926, 0.00778216, 0.009558191, ...]


Embed multiple text:
    .. code-block:: python

        input_texts = ["This is a test query1.", "This is a test query2."]
        embed.embed_documents(input_texts)

    .. code-block:: python

        [
            [0.0083934665, 0.037985895, -0.06684559, -0.039616987, 0.015481004, -0.023952313, ...],
            [-0.02713102, -0.005470169, 0.032321047, 0.042484466, 0.023290444, 0.02170547, ...]
        ]
NT)defaultexcludeclientzembedding-2)r   modelapi_key
dimensionsbefore)modevaluesreturnc                 ~    [        USS5      US'    SSKJn  U" US   S9US'   U$ ! [         a    [        S5      ef = f)z/Validate that auth token exists in environment.r   ZHIPUAI_API_KEYr   )ZhipuAI)r   r   zUCould not import zhipuai python package.Please install it with `pip install zhipuai`.)r   zhipuair   ImportError)clsr   r   s      ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/zhipuai.pyvalidate_environment&ZhipuAIEmbeddings.validate_environmentO   s_     1DUVy	'&vi/@AF8   	@ 	s   & <textc                 0    U R                  U/5      nUS   $ )z|
Embeds a text using the AutoVOT algorithm.

Args:
    text: A text to embed.

Returns:
    Input document's embedded list.
r   )embed_documents)selfr"   resps      r   embed_queryZhipuAIEmbeddings.embed_query_   s     ##TF+Aw    textsc                 B   U R                   b:  U R                  R                  R                  U R                  UU R                   S9nO.U R                  R                  R                  U R                  US9nUR
                   Vs/ sH  o3R                  PM     nnU$ s  snf )z
Embeds a list of text documents using the AutoVOT algorithm.

Args:
    texts: A list of text documents to embed.

Returns:
    A list of embeddings for each document in the input list.
    Each embedding is represented as a list of float values.
)r   inputr   )r   r,   )r   r   
embeddingscreater   data	embedding)r%   r*   r&   rr-   s        r   r$   !ZhipuAIEmbeddings.embed_documentsl   s     ??&;;))00jj?? 1 D ;;))00tzz0OD+/9959akk9
5 6s   B )__name__
__module____qualname____firstlineno____doc__r
   r   r   __annotations__r   strr   r   intr   classmethodr   r    r   floatr'   r$   __static_attributes__r3   r)   r   r   r      s    9v d3FC3}-E3-LN $J$
 (#$ 3   $ U T#Y 4U3D r)   r   N)typingr   r   r   r   langchain_core.embeddingsr   langchain_core.utilsr   pydanticr	   r
   r   r   r3   r)   r   <module>rC      s'    , , 0 5 6 6x	: xr)   