Ë
    kQêj³  ã                   óÚ   — U d dl Z d dlmZ d dlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ d dlZd	Zd
d
dddœZeeef   ed<   i e¥dd
dddœ¥Zeeef   ed<    ed«       G d„ de«      «       Zy)é    N)Úcached_property)ÚListÚOptionalÚDictÚUnioné   )Úattempt_import_or_raiseé   )ÚTextEmbeddingFunction)Úregisterz!https://us-south.ml.cloud.ibm.comi   i€  i   )z'ibm/granite-embedding-278m-multilingualzibm/slate-125m-english-rtrvr-v2zibm/slate-30m-english-rtrvr-v2zintfloat/multilingual-e5-largeÚCURRENT_MODELS)z&sentence-transformers/all-minilm-l6-v2úibm/slate-125m-english-rtrvrzibm/slate-30m-english-rtrvrz'sentence-transformers/all-minilm-l12-v2ÚMODELS_DIMSÚwatsonxc                   ó  — e Zd ZU dZdZeed<   dZee   ed<   dZ	ee   ed<   dZ
ee   ed<   dZee   ed<   dZee   ed	<   d
ee   fd„Zed„ «       Zed„ «       Zd„ Zed„ «       Zdeee   ej0                  f   d
eee      fd„Zed„ «       Zy)ÚWatsonxEmbeddingsus  
    An embedding function that uses the IBM watsonx.ai Embeddings API.

    API Docs:
        https://cloud.ibm.com/apidocs/watsonx-ai#text-embeddings

    Supported embedding models:
        https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models-embed.html?context=wx

    Parameters
    ----------
    name : str, default "ibm/slate-125m-english-rtrvr"
        The ID of the embedding model to use.  For new tables,
        ``"ibm/granite-embedding-278m-multilingual"`` is recommended.
    api_key : str, optional
        IBM Cloud API key.  Falls back to the ``WATSONX_API_KEY`` environment
        variable when not provided.
    project_id : str, optional
        watsonx.ai project ID.  Explicit value takes precedence over the
        ``WATSONX_PROJECT_ID`` environment variable.  Mutually exclusive with
        ``space_id`` â€” exactly one must be supplied.
    space_id : str, optional
        watsonx.ai deployment space ID.  Explicit value takes precedence over
        the ``WATSONX_SPACE_ID`` environment variable.  Mutually exclusive with
        ``project_id`` â€” exactly one must be supplied.
    url : str, optional
        watsonx.ai service URL.  Defaults to
        ``"https://us-south.ml.cloud.ibm.com"``.
    params : dict, optional
        Extra parameters forwarded verbatim to ``Embeddings`` (e.g.
        ``{"truncate_input_tokens": 512}``).
    r   ÚnameNÚapi_keyÚ
project_idÚspace_idÚurlÚparamsÚreturnc                 ó8   — | j                   r| j                   gS g S ©N)r   ©Úselfs    ú_/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/embeddings/watsonx.pyÚ	endpointszWatsonxEmbeddings.endpointsZ   s   € Ø!ŸXšX�—‘ˆzÐ-¨2Ð-ó    c                  ó   — dgS )Nr   © r"   r    r   Úsensitive_keysz WatsonxEmbeddings.sensitive_keys]   s
   € àˆ{Ðr    c                  ó<   — t        t        j                  «       «      S )a  Return the IDs of models currently available for new tables.

        Legacy / deprecated IDs are intentionally excluded.  They remain
        resolvable for dimension lookups on existing tables via ``MODELS_DIMS``,
        but should not be used when creating new tables.
        )Úlistr   Úkeysr"   r    r   Úmodel_nameszWatsonxEmbeddings.model_namesa   s   € ô ”N×'Ñ'Ó)Ó*Ð*r    c                 ó   — | j                   S r   )Ú_ndimsr   s    r   ÚndimszWatsonxEmbeddings.ndimsk   s   € Ø�{‰{Ðr    c           	      ó¸   — | j                   t        vr6t        d| j                   › dt        t        j                  «       «      › �«      ‚t        | j                      S )NzUnknown model 'z'. Available models: )r   r   Ú
ValueErrorr%   r   r&   r   s    r   r)   zWatsonxEmbeddings._ndimsn   sV   € à�9‰9œKÑ'ÜØ! $§)¡) ð -%Ü%)¬.×*=Ñ*=Ó*?Ó%@Ð$AðCóð ô ˜4Ÿ9™9Ñ%Ð%r    Útextsc                 óP   —  | j                   j                  |dt        |«      i|¤ŽS )Nr-   )Ú_watsonx_clientÚembed_documentsr%   )r   r-   ÚargsÚkwargss       r   Úgenerate_embeddingsz%WatsonxEmbeddings.generate_embeddingsw   s8   € ð 4ˆt×#Ñ#×3Ñ3àð
Ü�u“+ð
ð ñ
ð 	
r    c                 ó~  — t        d«      }t        d«      }| j                  xs t        j                  j	                  d«      }|st        d«      ‚|j                  || j                  xs t        ¬«      }| j                  | j                  }}|€@|€>t        j                  j	                  d«      }t        j                  j	                  d«      }|r|rt        d«      ‚|s|st        d	«      ‚t        | j                  |¬
«      }| j                  r| j                  |d<   |r||d<   n||d<    |j                  di |¤ŽS )NÚibm_watsonx_aiz ibm_watsonx_ai.foundation_modelsÚWATSONX_API_KEYzqWATSONX_API_KEY not set. Either set it in your environment or pass it as `api_key` argument to WatsonxEmbeddings.)r   r   ÚWATSONX_PROJECT_IDÚWATSONX_SPACE_IDz4Provide either `project_id` or `space_id`, not both.z–Either WATSONX_PROJECT_ID or WATSONX_SPACE_ID must be set. Pass one as an argument to WatsonxEmbeddings or set the corresponding environment variable.)Úmodel_idÚcredentialsr   r   r   r"   )r	   r   ÚosÚenvironÚgetr,   ÚCredentialsr   ÚDEFAULT_WATSONX_URLr   r   Údictr   r   Ú
Embeddings)r   r5   Ú ibm_watsonx_ai_foundation_modelsr   r:   r   r   Úclient_kwargss           r   r/   z!WatsonxEmbeddings._watsonx_clientƒ   s7  € ä0Ð1AÓBˆÜ+BØ.ó,
Ð(ð —,‘,ÒC¤"§*¡*§.¡.Ð1BÓ"CˆÙÜðFóð ð %×0Ñ0ØØ—‘Ò/Ô/ð 1ó 
ˆð  $Ÿ}™}¨d¯o©o�*ˆàÐ (Ð"2äŸ™Ÿ™Ð(<Ó=ˆJÜ—z‘z—~‘~Ð&8Ó9ˆHá™(ÜÐSÓTÐTÙ¡(Üð6óð ô #¨D¯I©IÀ;ÔOˆØ�;Š;Ø&*§k¡kˆM˜(Ñ#ÙØ*4ˆM˜,Ò'à(0ˆM˜*Ñ%à:Ð/×:Ñ:ÑK¸]ÑKÐKr    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚ__annotations__r   r   r   r   r   r   r   r   r   Ústaticmethodr#   r'   r*   r   r)   r   ÚnpÚndarrayÚfloatr3   r/   r"   r    r   r   r   ,   só   … ñðJ /€Dˆ#Ó.Ø!€GˆX�c‰]Ó!Ø $€J�˜‘Ó$Ø"€Hˆh�s‰mÓ"Ø€Cˆ�#‰ÓØ!€FˆH�T‰NÓ!ð.˜4 ™9ó .ð ñó ðð ñ+ó ð+òð ñ&ó ð&ð

à�T˜#‘Y §
¡
Ð*Ñ+ð

ð
 
ˆd�5‰kÑ	ó

ð ñ/Ló ñ/Lr    r   )r;   Ú	functoolsr   Útypingr   r   r   r   Úutilr	   Úbaser   Úregistryr   ÚnumpyrK   r?   r   r@   rH   ÚintrI   r   r   r"   r    r   ú<module>rU      s¡   ðô
 
Ý %ß .Ó .å *Ý 'Ý ã à9Ð ð 03Ø'*Ø&)Ø&*ñ	"€��S˜#�X‘ó ðØðð /2à$'Ø#&Ø/2ò€ˆT�#�s�(‰^ó ñ 
ˆ)ÓôFLÐ-ó FLó ñFLr    