
    dh                        S SK Jr  S SKrS SKJrJrJrJrJr  S SK	r	S SK
Jr  S SKJrJrJr  S SKJrJrJrJr  S SKJrJrJrJr  \R4                  " \5      rSS jrSS
 jr " S S	\\5      rg)    )annotationsN)AnyCallableDictListOptional)
Embeddings)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDictField	SecretStr)before_sleep_logretrystop_after_attemptwait_exponentialc            
         Sn SnSnSn[        S[        U5      [        XUS9[        [        [
        R                  5      S9$ )z#Returns a tenacity retry decorator.         T)
multiplierminmax)reraisestopwaitbefore_sleep)r   r   r   r   loggerloggingWARNING)r   min_secondsmax_secondsmax_retriess       ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/minimax.py_create_retry_decoratorr'      sH     JKKK,+V%fgoo>	     MiniMaxEmbeddingsc                B   ^  [        5       nUSU 4S jj5       nU" U0 UD6$ )z*Use tenacity to retry the completion call.c                 (   > TR                   " U 0 UD6$ )N)embed)argskwargs
embeddingss     r&   _embed_with_retry+embed_with_retry.<locals>._embed_with_retry(   s    000r(   )r-   r   r.   r   returnr   )r'   )r/   r-   r.   retry_decoratorr0   s   `    r&   embed_with_retryr4   $   s/    -/O1 1 d-f--r(   c                      \ rS rSr% SrSrS\S'    SrS\S'    SrS\S	'    S
r	S\S'    \
" SSS9rS\S'    \
" SSS9rS\S'    \" SSS9r\SS j5       r      SS jrSS jrSS jrSrg) r)   /   u  MiniMax embedding model integration.

Setup:
    To use, you should have the environment variable ``MINIMAX_GROUP_ID`` and
    ``MINIMAX_API_KEY`` set with your API token.

    .. code-block:: bash

        export MINIMAX_API_KEY="your-api-key"
        export MINIMAX_GROUP_ID="your-group-id"

Key init args — completion params:
    model: Optional[str]
        Name of ZhipuAI model to use.
    api_key: Optional[str]
        Automatically inferred from env var `MINIMAX_GROUP_ID` if not provided.
    group_id: Optional[str]
        Automatically inferred from env var `MINIMAX_GROUP_ID` 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 MiniMaxEmbeddings

        embed = MiniMaxEmbeddings(
            model="embo-01",
            # api_key="...",
            # group_id="...",
            # other
        )

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

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

    .. code-block:: python

        [0.03016241, 0.03617699, 0.0017198119, -0.002061239, -0.00029994643, -0.0061320597, -0.0043635326, ...]

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.0021588828, -0.007608119, 0.029349545, -0.0038194496, 0.008031177, -0.004529633, -0.020150753, ...],
            [ -0.00023150232, -0.011122423, 0.016930554, 0.0083089275, 0.012633711, 0.019683322, -0.005971041, ...]
        ]
z&https://api.minimax.chat/v1/embeddingsstrendpoint_urlzembo-01modeldbembed_type_dbqueryembed_type_queryNgroup_id)defaultaliaszOptional[str]minimax_group_idapi_keyzOptional[SecretStr]minimax_api_keyTforbid)populate_by_nameextrac                d    [        USS/S5      n[        [        USS/S5      5      nX!S'   X1S'   U$ )z9Validate that group id and api key exists in environment.rA   r>   MINIMAX_GROUP_IDrC   rB   MINIMAX_API_KEY)r   r
   )clsvaluesrA   rC   s       r&   validate_environment&MiniMaxEmbeddings.validate_environment}   sX     0'46H
 0 *I68I

 &6!"$3 !r(   c                &   U R                   UUS.nSU R                  R                  5        3SS.nSU R                  0n[        R
                  " U R                  XTUS9nUR                  5       nUS   S   S	:w  a  [        S
US    35      eUS   nU$ )N)r9   typetextszBearer zapplication/json)AuthorizationzContent-TypeGroupId)paramsheadersjson	base_respstatus_coder   zMiniMax API returned an error: vectors)	r9   rC   get_secret_valuerA   requestspostr8   rU   
ValueError)	selfrP   
embed_typepayloadrT   rS   responseparsed_responser/   s	            r&   r,   MiniMaxEmbeddings.embed   s     ZZ
  't';';'L'L'N&OP.
 t,,

 ==fG
 #--/ ;'6!;1/+2N1OP  %Y/
r(   c                .    [        XU R                  S9nU$ )zEmbed documents using a MiniMax embedding endpoint.

Args:
    texts: The list of texts to embed.

Returns:
    List of embeddings, one for each text.
rP   r^   )r4   r;   )r]   rP   r/   s      r&   embed_documents!MiniMaxEmbeddings.embed_documents   s     &dDDVDVW
r(   c                6    [        X/U R                  S9nUS   $ )z}Embed a query using a MiniMax embedding endpoint.

Args:
    text: The text to embed.

Returns:
    Embeddings for the text.
rd   r   )r4   r=   )r]   textr/   s      r&   embed_queryMiniMaxEmbeddings.embed_query   s'     &4+@+@

 !}r(    )rK   r   r2   r   )rP   	List[str]r^   r7   r2   List[List[float]])rP   rl   r2   rm   )rh   r7   r2   zList[float])__name__
__module____qualname____firstlineno____doc__r8   __annotations__r9   r;   r=   r   rA   rC   r   model_configr   rL   r,   re   ri   __static_attributes__rk   r(   r&   r)   r)   /   s    8t AL#@E3'M3#c#&+D
&KmK#+0Y+OO(O"L
  ## # 
	#J
r(   )r2   zCallable[[Any], Any])r/   r)   r-   r   r.   r   r2   r   ) 
__future__r   r!   typingr   r   r   r   r   rZ   langchain_core.embeddingsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r   tenacityr   r   r   r   	getLoggerrn   r    r'   r4   r)   rk   r(   r&   <module>r}      sY    "  6 6  0 V V < <  
		8	$ .Z	: Zr(   