Ë
    lQêjò!  ã                   ó�   — d dl mZmZmZmZ d dlmZmZmZm	Z	 d dl
Z
d dlZd dlmZ d dlZ G d„ dee   «      Z G d„ dee   «      Zy)	é    )Ú
EmbeddingsÚ	DocumentsÚEmbeddingFunctionÚSpace)ÚListÚDictÚAnyÚOptionalN©Úvalidate_config_schemac                   óü   — e Zd ZdZ	 	 	 ddee   dedefd„Zdedefd	„Z	e
defd
„«       Zdefd„Zdee   fd„Ze
deeef   ddfd„«       Zdeeef   fd„Zdeeef   deeef   ddfd„Ze
deeef   ddfd„«       Zy)ÚHuggingFaceEmbeddingFunctionzÎ
    This class is used to get embeddings for a list of texts using the HuggingFace API.
    It requires an API key and a model name. The default model name is "sentence-transformers/all-MiniLM-L6-v2".
    NÚapi_keyÚ
model_nameÚapi_key_env_varc                 ó  — 	 ddl }|�t        j                  dt
        «       t        j                  d«      �d| _        n|| _        |xs t        j                  | j                  «      | _	        | j                  st        d| j                  › d�«      ‚|| _
        d|› �| _        |j                  «       | _        | j                  j                  j                  d	d
| j                  › �i«       y# t        $ r t        d«      ‚w xY w)a¢  
        Initialize the HuggingFaceEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the HuggingFace API.
                Defaults to "CHROMA_HUGGINGFACE_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "sentence-transformers/all-MiniLM-L6-v2".
        r   NúUThe httpx python package is not installed. Please install it with `pip install httpx`ú€Direct api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.ÚHUGGINGFACE_API_KEYzThe z! environment variable is not set.zAhttps://api-inference.huggingface.co/pipeline/feature-extraction/ÚAuthorizationúBearer )ÚhttpxÚImportErrorÚ
ValueErrorÚwarningsÚwarnÚDeprecationWarningÚosÚgetenvr   r   r   Ú_api_urlÚClientÚ_sessionÚheadersÚupdate)Úselfr   r   r   r   s        ú†/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/huggingface_embedding_function.pyÚ__init__z%HuggingFaceEmbeddingFunction.__init__   sû   € ð	Ûð ÐÜ�M‰Mð_ä"ôô
 �9‰9Ð*Ó+Ð7Ø#8ˆDÕ à#2ˆDÔ àÒA¤"§)¡)¨D×,@Ñ,@Ó"AˆŒØ�|Š|ÜØ�t×+Ñ+Ð,Ð,MÐNóð ð %ˆŒà[Ð\fÐ[gÐhˆŒØŸ™›ˆŒØ�‰×Ñ×$Ñ$ o¸ÀÇÁÀÐ7OÐ%PÕQøô5 ò 	ÜØgóð ð	ús   ‚C. Ã.DÚinputÚreturnc                 óæ   — | j                   j                  | j                  |ddidœ¬«      j                  «       }|D �cg c]'  }t	        j
                  |t        j                  ¬«      ‘Œ) c}S c c}w )a½  
        Get the embeddings for a list of texts.

        Args:
            input (Documents): A list of texts to get embeddings for.

        Returns:
            Embeddings: The embeddings for the texts.

        Example:
            >>> hugging_face = HuggingFaceEmbeddingFunction(api_key_env_var="CHROMA_HUGGINGFACE_API_KEY")
            >>> texts = ["Hello, world!", "How are you?"]
            >>> embeddings = hugging_face(texts)
        Úwait_for_modelT)ÚinputsÚoptions©Újson©Údtype©r"   Úpostr    r/   ÚnpÚarrayÚfloat32©r%   r(   ÚresponseÚ	embeddings       r&   Ú__call__z%HuggingFaceEmbeddingFunction.__call__<   se   € ð  —=‘=×%Ñ%Ø�M‰MØ!Ð/?ÀÐ.FÑGð &ó 
÷ ‰$‹&ð 	ð HPÖP¸)”—‘˜¬"¯*©*Ö5ÒPÐPùÒPs   ¿,A.c                   ó   — y)NÚhuggingface© r=   ó    r&   Únamez!HuggingFaceEmbeddingFunction.nameT   s   € àr>   c                  ó   — y©NÚcosiner=   ©r%   s    r&   Údefault_spacez*HuggingFaceEmbeddingFunction.default_spaceX   ó   € Ør>   c                 ó
   — g d¢S ©N)rB   Úl2Úipr=   rC   s    r&   Úsupported_spacesz-HuggingFaceEmbeddingFunction.supported_spaces[   ó   € Ú%Ð%r>   ÚconfigúEmbeddingFunction[Documents]c                 óv   — | j                  d«      }| j                  d«      }|�|€J d«       ‚t        ||¬«      S )Nr   r   zThis code should not be reached©r   r   )Úgetr   )rL   r   r   s      r&   Úbuild_from_configz.HuggingFaceEmbeddingFunction.build_from_config^   sG   € à Ÿ*™*Ð%6Ó7ˆØ—Z‘Z Ó-ˆ
àÐ" jÐ&8Ø;Ð;Ó;�5ä+Ø+¸
ô
ð 	
r>   c                 ó4   — | j                   | j                  dœS )NrO   rO   rC   s    r&   Ú
get_configz'HuggingFaceEmbeddingFunction.get_configj   s   € Ø#'×#7Ñ#7ÀtÇÁÑWÐWr>   Ú
old_configÚ
new_configc                 ó"   — d|v rt        d«      ‚y )Nr   zSThe model name cannot be changed after the embedding function has been initialized.)r   ©r%   rT   rU   s      r&   Úvalidate_config_updatez3HuggingFaceEmbeddingFunction.validate_config_updatem   s!   € ð ˜:Ñ%ÜØeóð ð &r>   c                 ó   — t        | d«       y)úÝ
        Validate the configuration using the JSON schema.

        Args:
            config: Configuration to validate

        Raises:
            ValidationError: If the configuration does not match the schema
        r<   Nr   ©rL   s    r&   Úvalidate_configz,HuggingFaceEmbeddingFunction.validate_configu   s   € ô 	˜v }Õ5r>   )Nz&sentence-transformers/all-MiniLM-L6-v2ÚCHROMA_HUGGINGFACE_API_KEY)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   Ústrr'   r   r   r:   Ústaticmethodr?   r   rD   r   rJ   r   r	   rQ   rS   rX   r\   r=   r>   r&   r   r   	   s!  „ ñð "&ØBØ;ñ	+Rà˜#‘ð+Rð ð+Rð ó	+RðZQ˜ið Q¨Jó Qð0 ð�#ò ó ðð˜uó ð& $ u¡+ó &ð ð	
 $ s¨C x¡.ð 	
Ð5Sò 	
ó ð	
ðX˜D  c ™Nó XðØ˜s C˜x™.ðØ6:¸3À¸8±nðà	óð ð
6  S¨# X¡ð 
6°4ò 
6ó ñ
6r>   r   c                   ó   — e Zd ZdZ	 	 ddedee   dee   fd„Zdedefd	„Z	e
defd
„«       Zdefd„Zdee   fd„Ze
deeef   ddfd„«       Zdeeef   fd„Zdeeef   deeef   ddfd„Ze
deeef   ddfd„«       Zy)ÚHuggingFaceEmbeddingServerzÞ
    This class is used to get embeddings for a list of texts using the HuggingFace Embedding server
    (https://github.com/huggingface/text-embeddings-inference).
    The embedding model is configured in the server.
    NÚurlr   r   c                 óþ  — 	 ddl }|�t        j                  dt
        «       || _        || _        t        j                  d«      �d| _        | j                  �)|xs t        j                  | j                  «      | _
        n|| _
        |› | _        |j                  «       | _        | j                  �5| j                  j                  j                  dd| j                  › �i«       yy# t        $ r t        d«      ‚w xY w)aa  
        Initialize the HuggingFaceEmbeddingServer.

        Args:
            url (str): The URL of the HuggingFace Embedding Server.
            api_key (Optional[str]): The API key for the HuggingFace Embedding Server.
            api_key_env_var (str, optional): Environment variable name that contains your API key for the HuggingFace API.
        r   Nr   r   r   r   r   )r   r   r   r   r   r   rf   r   r   r   r   r    r!   r"   r#   r$   )r%   rf   r   r   r   s        r&   r'   z#HuggingFaceEmbeddingServer.__init__Š   sì   € ð	Ûð ÐÜ�M‰Mð_ä"ôð ˆŒà.ˆÔÜ�9‰9Ð*Ó+Ð7Ø#8ˆDÔ à×ÑÐ+Ø"ÒE¤b§i¡i°×0DÑ0DÓ&EˆD�Là"ˆDŒLà˜%ˆŒØŸ™›ˆŒà�<‰<Ð#Ø�M‰M×!Ñ!×(Ñ(¨/¸WÀTÇ\Á\ÀNÐ;SÐ)TÕUð $øô5 ò 	ÜØgóð ð	ús   ‚C' Ã'C<r(   r)   c                 óà   — | j                   j                  | j                  d|i¬«      j                  «       }|D �cg c]'  }t	        j
                  |t        j                  ¬«      ‘Œ) c}S c c}w )a°  
        Get the embeddings for a list of texts.

        Args:
            input (Documents): A list of texts to get embeddings for.

        Returns:
            Embeddings: The embeddings for the texts.

        Example:
            >>> hugging_face = HuggingFaceEmbeddingServer(url="http://localhost:8080/embed")
            >>> texts = ["Hello, world!", "How are you?"]
            >>> embeddings = hugging_face(texts)
        r,   r.   r0   r2   r7   s       r&   r:   z#HuggingFaceEmbeddingServer.__call__·   sV   € ð  —=‘=×%Ñ% d§m¡m¸8ÀUÐ:KÐ%ÓL×QÑQÓSˆð HPÖP¸)”—‘˜¬"¯*©*Ö5ÒPÐPùÒPs   ¼,A+c                   ó   — y)NÚhuggingface_serverr=   r=   r>   r&   r?   zHuggingFaceEmbeddingServer.nameÌ   s   € à#r>   c                  ó   — yrA   r=   rC   s    r&   rD   z(HuggingFaceEmbeddingServer.default_spaceÐ   rE   r>   c                 ó
   — g d¢S rG   r=   rC   s    r&   rJ   z+HuggingFaceEmbeddingServer.supported_spacesÓ   rK   r>   rL   rM   c                 óz   — | j                  d«      }| j                  d«      }|€t        d«      ‚t        ||¬«      S )Nrf   r   z3URL must be provided for HuggingFaceEmbeddingServer©rf   r   )rP   r   re   )rL   rf   r   s      r&   rQ   z,HuggingFaceEmbeddingServer.build_from_configÖ   s=   € à�j‰j˜ÓˆØ Ÿ*™*Ð%6Ó7ˆØˆ;ÜÐRÓSÐSä)¨cÀ?ÔSÐSr>   c                 ó4   — | j                   | j                  dœS )Nrn   rn   rC   s    r&   rS   z%HuggingFaceEmbeddingServer.get_configß   s   € Ø—x‘x°D×4HÑ4HÑIÐIr>   rT   rU   c                 óH   — d|v r|d   | j                   k7  rt        d«      ‚y y )Nrf   zLThe URL cannot be changed after the embedding function has been initialized.)rf   r   rW   s      r&   rX   z1HuggingFaceEmbeddingServer.validate_config_updateâ   s5   € ð �JÑ :¨eÑ#4¸¿¹Ò#@ÜØ^óð ð $AÐr>   c                 ó   — t        | d«       y)rZ   rj   Nr   r[   s    r&   r\   z*HuggingFaceEmbeddingServer.validate_configê   s   € ô 	˜vÐ';Õ<r>   )NN)r^   r_   r`   ra   rb   r
   r'   r   r   r:   rc   r?   r   rD   r   rJ   r   r	   rQ   rS   rX   r\   r=   r>   r&   re   re   ƒ   s&  „ ñð *.Ø!%ñ	+Vàð+Vð " #™ð+Vð ˜#‘ó	+VðZQ˜ið Q¨Jó Qð* ð$�#ò $ó ð$ð˜uó ð& $ u¡+ó &ð ðT $ s¨C x¡.ð TÐ5Sò Tó ðTðJ˜D  c ™Nó JðØ˜s C˜x™.ðØ6:¸3À¸8±nðà	óð ð
=  S¨# X¡ð 
=°4ò 
=ó ñ
=r>   re   )Úchromadb.api.typesr   r   r   r   Útypingr   r   r	   r
   r   Únumpyr4   Ú*chromadb.utils.embedding_functions.schemasr   r   r   re   r=   r>   r&   ú<module>rv      sF   ðß NÓ Nß ,Ó ,Û 	Û Ý MÛ ôw6Ð#4°YÑ#?ô w6ôtr=Ð!2°9Ñ!=õ r=r>   