Ë
    lQêj#\  ã                   óè   — d dl mZmZmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZ d dlZd dlZd dlmZ d dlmZ d dlZ G d„ dee   «      ZeZ G d„ d	ee   «      Z G d
„ dee   «      Z G d„ dee   «      Zy)é    )Ú
EmbeddingsÚ	DocumentsÚEmbeddingFunctionÚSpace)Ú__version__)ÚListÚDictÚAnyÚcastÚOptionalN©Úvalidate_config_schemac                   ó2  — e Zd ZdZ	 	 	 	 	 	 	 ddedee   dee   dee   de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)ÚGoogleGeminiEmbeddingFunctionzqTo use this EmbeddingFunction, you must have the google-genai Python package installed and have a Gemini API key.NÚ
model_nameÚ	task_typeÚ	dimensionÚapi_key_env_varÚvertexaiÚprojectÚlocationc                 ó8  — 	 ddl m} || _        || _        || _        || _        || _        || _	        || _
        | j                  rt        j                  | j                  «      nd| _        | j                  r| j                  rt        d«      ‚| j                  s%| j                  st        d| j                  › d�«      ‚ddl m}	 |j                  | j                  ||||	j!                  dd	t"        › �i¬
«      ¬«      | _        y# t        $ r t        d«      ‚w xY w)ué  
        Initialize the GoogleGeminiEmbeddingFunction.

        Args:
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "gemini-embedding-001".
            task_type (str, optional): The task type for the embeddings.
                Valid values include SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING,
                RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, CODE_RETRIEVAL_QUERY,
                QUESTION_ANSWERING, FACT_VERIFICATION.
            dimension (int, optional): The output dimensionality for the embeddings.
                Supported range: 128â€“3072. If None, the model's default is used.
            api_key_env_var (str, optional): Environment variable name that contains your API key.
                Defaults to "GEMINI_API_KEY".
            vertexai (bool, optional): Whether to use Vertex AI.
                If enabled, an API key must not be provided, and the environment variable `GOOGLE_APPLICATION_CREDENTIALS` must be set to the path of your service account JSON file.
            project (str, optional): The Google Cloud project ID (required for Vertex AI).
            location (str, optional): The Google Cloud location/region (required for Vertex AI).
        r   NzcThe google-genai python package is not installed. Please install it with `pip install google-genai`zGVertex AI and API key are mutually exclusive in the client initializer.úThe z= environment variable must be set if vertexai is not enabled.)Útypesúx-goog-api-clientúchroma/)Úheaders)Úapi_keyr   r   r   Úhttp_options)Úgoogle.genaiÚgenaiÚImportErrorÚ
ValueErrorr   r   r   r   r   r   r   ÚosÚgetenvr   r   ÚClientÚHttpOptionsr   Úclient)
Úselfr   r   r   r   r   r   r   r!   r   s
             ú�/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/google_embedding_function.pyÚ__init__z&GoogleGeminiEmbeddingFunction.__init__   s  € ð:	Ý(ð %ˆŒØ"ˆŒØ"ˆŒØ.ˆÔØ ˆŒØˆŒØ ˆŒØ:>×:NÒ:N”r—y‘y ×!5Ñ!5Ô6ÐTXˆŒØ�<Š<˜DŸMšMÜØYóð ð �|Š| D§M¢MÜØ�t×+Ñ+Ð,Ð,iÐjóð õ 	'à—l‘lØ—L‘LØØØØ×*Ñ*Ø,°¼°}Ð.EÐFð +ó ð #ó 
ˆ�øô1 ò 	ÜØuóð ð	ús   ‚D ÄDÚinputÚreturnc                 óÎ  — |st        d«      ‚t        |t        t        f«      st        d«      ‚t	        d„ |D «       «      st        d«      ‚ddlm}  || j                  | j                  ¬«      }	 | j                  j                  j                  | j                  ||¬«      }t        |d«      r|j                   st        d«      ‚g }|j                   D ]W  }t        |d«      st        d«      ‚|j#                  t%        j&                  |j(                  t$        j*                  ¬«      «       ŒY t-        t.        |«      S # t        $ r}t        d	t        |«      › �«      |‚d
}~ww xY w)úÂ
        Generate embeddings for the given documents.

        Args:
            input: Documents to generate embeddings for.

        Returns:
            Embeddings for the documents.
        zInput documents cannot be emptyz*Input must be a list or tuple of documentsc              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­w©N©Ú
isinstanceÚstr)Ú.0Údocs     r*   ú	<genexpr>z9GoogleGeminiEmbeddingFunction.__call__.<locals>.<genexpr>]   s   è ø€ Ò9¨C”:˜c¤3×'Ñ9ùó   ‚z#All input documents must be stringsr   )ÚEmbedContentConfig)r   Úoutput_dimensionality)ÚmodelÚcontentsÚconfigzFailed to generate embeddings: NÚ
embeddingsz#No embeddings returned from the APIÚvaluesz.Malformed embedding response: missing 'values'©Údtype)r#   r3   ÚlistÚtupleÚallÚgoogle.genai.typesr9   r   r   r(   ÚmodelsÚembed_contentr   Ú	Exceptionr4   Úhasattrr>   ÚappendÚnpÚarrayr?   Úfloat32r   r   )r)   r,   r9   r=   ÚresponseÚeÚembeddings_listÚces           r*   Ú__call__z&GoogleGeminiEmbeddingFunction.__call__O   sC  € ñ ÜÐ>Ó?Ð?Ü˜%¤$¬ Ô/ÜÐIÓJÐJÜÑ9°5Ô9Ô9ÜÐBÓCÐCå9á#Ø—n‘nØ"&§.¡.ô
ˆð
	PØ—{‘{×)Ñ)×7Ñ7Ø—o‘oØØð 8ó ˆHô �x Ô.°h×6IÒ6IÜÐBÓCÐCàˆØ×%Ñ%ò 	JˆBÜ˜2˜xÔ(Ü Ð!QÓRÐRØ×"Ñ"¤2§8¡8¨B¯I©I¼R¿Z¹ZÔ#HÕIð	Jô
 ”J Ó0Ð0øô ò 	PÜÐ>¼sÀ1»v¸hÐGÓHÈaÐOûð	Pús   Á12D> Ä>	E$ÅEÅE$c                   ó   — y)NÚgoogle_gemini© rU   ó    r*   Únamez"GoogleGeminiEmbeddingFunction.name|   ó   € àrV   c                  ó   — y©NÚcosinerU   ©r)   s    r*   Údefault_spacez+GoogleGeminiEmbeddingFunction.default_space€   ó   € ØrV   c                 ó
   — g d¢S ©N)r[   Úl2ÚiprU   r\   s    r*   Úsupported_spacesz.GoogleGeminiEmbeddingFunction.supported_spacesƒ   ó   € Ú%Ð%rV   r=   úEmbeddingFunction[Documents]c           	      ó0  — | j                  d«      }| j                  d«      }| j                  d«      }| j                  dd«      }| j                  d«      }| j                  d«      }| j                  d«      }|€t        d	«      ‚t        |||||||¬
«      S )Nr   r   r   r   ÚGEMINI_API_KEYr   r   r   zThe model name is required.)r   r   r   r   r   r   r   )Úgetr#   r   )r=   r   r   r   r   r   r   r   s           r*   Úbuild_from_configz/GoogleGeminiEmbeddingFunction.build_from_config†   sœ   € à—Z‘Z Ó-ˆ
Ø—J‘J˜{Ó+ˆ	Ø—J‘J˜{Ó+ˆ	Ø Ÿ*™*Ð%6Ð8HÓIˆØ—:‘:˜jÓ)ˆØ—*‘*˜YÓ'ˆØ—:‘:˜jÓ)ˆàÐÜÐ:Ó;Ð;ä,Ø!ØØØ+ØØØô
ð 	
rV   c                 óæ   — | j                   | j                  | j                  | j                  | j                  dœ}| j
                  �| j
                  |d<   | j                  �| j                  |d<   |S )N)r   r   r   r   r   r   r   )r   r   r   r   r   r   r   ©r)   r=   s     r*   Ú
get_configz(GoogleGeminiEmbeddingFunction.get_config�   se   € àŸ/™/Ø#×3Ñ3ØŸ™Ø—|‘|ØŸ™ñ"
ˆð �>‰>Ð%Ø"&§.¡.ˆF�;ÑØ�>‰>Ð%Ø"&§.¡.ˆF�;ÑØˆrV   Ú
old_configÚ
new_configc                 óš   — d|v rt        d«      ‚d|v rt        d«      ‚d|v rt        d«      ‚d|v rt        d«      ‚d	|v rt        d
«      ‚y )Nr   úSThe model name cannot be changed after the embedding function has been initialized.r   úRThe dimension cannot be changed after the embedding function has been initialized.r   zQThe vertexai cannot be changed after the embedding function has been initialized.r   zPThe project cannot be changed after the embedding function has been initialized.r   zQThe location cannot be changed after the embedding function has been initialized.©r#   ©r)   rm   rn   s      r*   Úvalidate_config_updatez4GoogleGeminiEmbeddingFunction.validate_config_update«   s‰   € ð ˜:Ñ%ÜØeóð ð ˜*Ñ$ÜØdóð ð ˜Ñ#ÜØcóð ð ˜
Ñ"ÜØbóð ð ˜Ñ#ÜØcóð ð $rV   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
        rT   Nr   ©r=   s    r*   Úvalidate_configz-GoogleGeminiEmbeddingFunction.validate_configÃ   ó   € ô 	˜v Õ7rV   )úgemini-embedding-001NNrg   NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r   ÚintÚboolr+   r   r   rR   ÚstaticmethodrW   r   r]   r   rc   r	   r
   ri   rl   rt   rx   rU   rV   r*   r   r      s_  „ Ù{ð 1Ø#'Ø#'Ø)9Ø#'Ø!%Ø"&ñ?
àð?
ð ˜C‘=ð?
ð ˜C‘=ð	?
ð
 " #™ð?
ð ˜4‘.ð?
ð ˜#‘ð?
ð ˜3‘-ó?
ðB+1˜ið +1¨Jó +1ðZ ð�#ò ó ðð˜uó ð& $ u¡+ó &ð ð
 $ s¨C x¡.ð 
Ð5Sò 
ó ð
ð,˜D  c ™Nó ðØ˜s C˜x™.ðØ6:¸3À¸8±nðà	óð0 ð
8  S¨# X¡ð 
8°4ò 
8ó ñ
8rV   r   c                   ó  — e Zd ZdZ	 	 	 	 	 ddee   deded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)Ú#GoogleGenerativeAiEmbeddingFunctionzxTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a Google API key.Nr   r   r   r   r   c                 óä  — 	 ddl m} |�t	        j
                  dt        «       t        j                  d«      �d| _	        n|| _	        |xs t        j                  | j                  «      | _
        | j                  st        d| j                  › d�«      ‚|| _        || _        || _        |j                  | j                  dd	d
t        › �ii¬«       || _        y# t        $ r t        d«      ‚w xY w)a  
        Initialize the GoogleGenerativeAiEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the Google Generative AI API.
                Defaults to "GEMINI_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "gemini-embedding-001".
            task_type (str, optional): The task type for the embeddings.
                Use "RETRIEVAL_DOCUMENT" for embedding documents and "RETRIEVAL_QUERY" for embedding queries.
                Defaults to "RETRIEVAL_DOCUMENT".
            dimension (int, optional): The output dimensionality for the embeddings.
                If None, the model's default dimensionality is used.
        r   NúrThe Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`ú€Direct api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.ÚGOOGLE_API_KEYr   ú! environment variable is not set.r   r   r   ©r   Úclient_options)Úgoogle.generativeaiÚgenerativeair"   r#   ÚwarningsÚwarnÚDeprecationWarningr$   r%   r   r   r   r   r   Ú	configurer   Ú_genai)r)   r   r   r   r   r   r!   s          r*   r+   z,GoogleGenerativeAiEmbeddingFunction.__init__Ø   sý   € ð,	Ý/ð ÐÜ�M‰Mð_ä"ôô
 �9‰9Ð%Ó&Ð2Ø#3ˆDÕ à#2ˆDÔ àÒA¤"§)¡)¨D×,@Ñ,@Ó"AˆŒØ�|Š|ÜØ�t×+Ñ+Ð,Ð,MÐNóð ð %ˆŒØ"ˆŒØ"ˆŒà�‰Ø—L‘LØ%Ð(;¸wÄ{ÀmÐ=TÐ'UÐVð 	ô 	
ð ˆ�øô= ò 	Üð Eóð ð	ús   ‚C ÃC/r,   r-   c                 ó~  — t        d„ |D «       «      st        d«      ‚g }|D ]Š  }| j                  || j                  dœ}| j                  �| j                  |d<    | j
                  j                  di |¤Ž}|j                  t        j                  |d   t        j                  ¬«      «       ŒŒ t        t        |«      S )r/   c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr1   r2   ©r5   Úitems     r*   r7   z?GoogleGenerativeAiEmbeddingFunction.__call__.<locals>.<genexpr>  ó   è ø€ Ò;¨T”:˜d¤C×(Ñ;ùr8   z=Google Generative AI only supports text documents, not images)r;   Úcontentr   r:   Ú	embeddingr@   rU   )rD   r#   r   r   r   r‘   rG   rJ   rK   rL   rM   r   r   )r)   r,   rP   ÚtextÚkwargsÚembedding_results         r*   rR   z,GoogleGenerativeAiEmbeddingFunction.__call__  sº   € ô Ñ;°UÔ;Ô;ÜØOóð ð :<ˆØò 	ˆDàŸ™ØØ!Ÿ^™^ñ&ˆFð
 �~‰~Ð)Ø26·.±.�Ð.Ñ/Ø8˜tŸ{™{×8Ñ8ÑB¸6ÑBÐØ×"Ñ"Ü—‘Ð)¨+Ñ6¼b¿j¹jÔIõð	ô ”J Ó0Ð0rV   c                   ó   — y)NÚgoogle_generative_airU   rU   rV   r*   rW   z(GoogleGenerativeAiEmbeddingFunction.name/  s   € à%rV   c                  ó   — yrZ   rU   r\   s    r*   r]   z1GoogleGenerativeAiEmbeddingFunction.default_space3  r^   rV   c                 ó
   — g d¢S r`   rU   r\   s    r*   rc   z4GoogleGenerativeAiEmbeddingFunction.supported_spaces6  rd   rV   r=   re   c                 óÂ   — | j                  d«      }| j                  d«      }| j                  d«      }| j                  d«      }|�|�|€J d«       ‚t        ||||¬«      S )Nr   r   r   r   úThis code should not be reached©r   r   r   r   )rh   rƒ   )r=   r   r   r   r   s        r*   ri   z5GoogleGenerativeAiEmbeddingFunction.build_from_config9  so   € à Ÿ*™*Ð%6Ó7ˆØ—Z‘Z Ó-ˆ
Ø—J‘J˜{Ó+ˆ	Ø—J‘J˜{Ó+ˆ	àÐ" jÐ&8¸IÐ<MØ;Ð;Ó;�5ä2Ø+Ø!ØØô	
ð 	
rV   c                 ó„   — | j                   | j                  | j                  dœ}| j                  �| j                  |d<   |S )N)r   r   r   r   r¢   rk   s     r*   rl   z.GoogleGenerativeAiEmbeddingFunction.get_configJ  s?   € à#×3Ñ3ØŸ/™/ØŸ™ñ"
ˆð
 �>‰>Ð%Ø"&§.¡.ˆF�;ÑØˆrV   rm   rn   c                 ó^   — d|v rt        d«      ‚d|v rt        d«      ‚d|v rt        d«      ‚y )Nr   rp   r   zRThe task type cannot be changed after the embedding function has been initialized.r   rq   rr   rs   s      r*   rt   z:GoogleGenerativeAiEmbeddingFunction.validate_config_updateT  sU   € ð ˜:Ñ%ÜØeóð ð ˜*Ñ$ÜØdóð ð ˜*Ñ$ÜØdóð ð %rV   c                 ó   — t        | d«       y)rv   r�   Nr   rw   s    r*   rx   z3GoogleGenerativeAiEmbeddingFunction.validate_configd  s   € ô 	˜vÐ'=Õ>rV   )Nrz   ÚRETRIEVAL_DOCUMENTrg   N)r{   r|   r}   r~   r   r4   r   r+   r   r   rR   r�   rW   r   r]   r   rc   r	   r
   ri   rl   rt   rx   rU   rV   r*   rƒ   rƒ   Õ   s7  „ ñ Cð "&Ø0Ø-Ø/Ø#'ñ6à˜#‘ð6ð ð6ð ð	6ð
 ð6ð ˜C‘=ó6ðp1˜ið 1¨Jó 1ð> ð&�#ò &ó ð&ð˜uó ð& $ u¡+ó &ð ð
 $ s¨C x¡.ð 
Ð5Sò 
ó ð
ð ˜D  c ™Nó ðØ˜s C˜x™.ðØ6:¸3À¸8±nðà	óð  ð
?  S¨# X¡ð 
?°4ò 
?ó ñ
?rV   rƒ   c                   óü   — 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)ÚGooglePalmEmbeddingFunctionzvTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a PaLM API key.Nr   r   r   c                 óÈ  — 	 ddl m} |�t	        j
                  dt        «       t        j                  d«      �d| _	        n|| _	        |xs t        j                  | j                  «      | _
        | j                  st        d| j                  › d�«      ‚|| _        |j                  | j                  dd	d
t        › �ii¬«       || _        y# t        $ r t        d«      ‚w xY w)a•  
        Initialize the GooglePalmEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the Google PaLM API.
                Defaults to "CHROMA_GOOGLE_PALM_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "models/embedding-gecko-001".
        r   Nr…   r†   r‡   r   rˆ   r   r   r   r‰   )r‹   rŒ   r"   r#   r�   rŽ   r�   r$   r%   r   r   r   r�   r   Ú_palm)r)   r   r   r   Úpalms        r*   r+   z$GooglePalmEmbeddingFunction.__init__u  sï   € ð	Ý.ð ÐÜ�M‰Mð_ä"ôô
 �9‰9Ð%Ó&Ð2Ø#3ˆDÕ à#2ˆDÔ àÒA¤"§)¡)¨D×,@Ñ,@Ó"AˆŒØ�|Š|ÜØ�t×+Ñ+Ð,Ð,MÐNóð ð %ˆŒà�‰Ø—L‘LØ%Ð(;¸wÄ{ÀmÐ=TÐ'UÐVð 	ô 	
ð ˆ�
øô9 ò 	Üð Eóð ð	ús   ‚C ÃC!r,   r-   c           	      óü   — t        d„ |D «       «      st        d«      ‚|D �cg c]O  }t        j                  | j                  j                  | j                  |¬«      d   t        j                  ¬«      ‘ŒQ c}S c c}w )úÌ
        Generate embeddings for the given documents.

        Args:
            input: Documents or images to generate embeddings for.

        Returns:
            Embeddings for the documents.
        c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr1   r2   r”   s     r*   r7   z7GooglePalmEmbeddingFunction.__call__.<locals>.<genexpr>¯  r–   r8   z4Google PaLM only supports text documents, not images)r;   r™   r˜   r@   )rD   r#   rK   rL   rª   Úgenerate_embeddingsr   rM   )r)   r,   r™   s      r*   rR   z$GooglePalmEmbeddingFunction.__call__¤  sw   € ô Ñ;°UÔ;Ô;ÜÐSÓTÐTð ö
ð ô �H‰HØ—
‘
×.Ñ.°T·_±_È4Ð.ÓPØñô —j‘jö	ò
ð 	
ùò 
s   ¢AA9c                   ó   — y)NÚgoogle_palmrU   rU   rV   r*   rW   z GooglePalmEmbeddingFunction.name¼  s   € àrV   c                  ó   — yrZ   rU   r\   s    r*   r]   z)GooglePalmEmbeddingFunction.default_spaceÀ  r^   rV   c                 ó
   — g d¢S r`   rU   r\   s    r*   rc   z,GooglePalmEmbeddingFunction.supported_spacesÃ  rd   rV   r=   re   c                 óv   — | j                  d«      }| j                  d«      }|�|€J d«       ‚t        ||¬«      S )Nr   r   r¡   ©r   r   )rh   r¨   )r=   r   r   s      r*   ri   z-GooglePalmEmbeddingFunction.build_from_configÆ  sG   € à Ÿ*™*Ð%6Ó7ˆØ—Z‘Z Ó-ˆ
àÐ" jÐ&8Ø;Ð;Ó;�5ä*Ø+¸
ô
ð 	
rV   c                 ó4   — | j                   | j                  dœS )Nrµ   rµ   r\   s    r*   rl   z&GooglePalmEmbeddingFunction.get_configÒ  s   € Ø#'×#7Ñ#7ÀtÇÁÑWÐWrV   rm   rn   c                 ó"   — d|v rt        d«      ‚y )Nr   rp   rr   rs   s      r*   rt   z2GooglePalmEmbeddingFunction.validate_config_updateÕ  s!   € ð ˜:Ñ%ÜØeóð ð &rV   c                 ó   — t        | d«       y)rv   r±   Nr   rw   s    r*   rx   z+GooglePalmEmbeddingFunction.validate_configÝ  s   € ô 	˜v }Õ5rV   )Nzmodels/embedding-gecko-001ÚCHROMA_GOOGLE_PALM_API_KEY©r{   r|   r}   r~   r   r4   r+   r   r   rR   r�   rW   r   r]   r   rc   r	   r
   ri   rl   rt   rx   rU   rV   r*   r¨   r¨   r  s  „ ñ Að "&Ø6Ø;ñ	-à˜#‘ð-ð ð-ð ó	-ð^
˜ið 
¨Jó 
ð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ó ñ
6rV   r¨   c                   ó  — e Zd ZdZ	 	 	 	 	 ddee   ded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)ÚGoogleVertexEmbeddingFunctionz€To use this EmbeddingFunction, you must have the vertexai Python package installed and have Google Cloud credentials configured.Nr   r   Ú
project_idÚregionr   c                 óö  — 	 ddl }ddlm} |�t        j                  dt        «       t        j                  d«      �d| _
        n|| _
        |xs t        j                  | j                  «      | _        | j                  st	        d| j                  › d�«      ‚|| _        || _        || _        |j                  ||d	d
t         › �fg¬«       |j#                  |«      | _        y# t        $ r t	        d«      ‚w xY w)a  
        Initialize the GoogleVertexEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the Google Vertex AI API.
                Defaults to "CHROMA_GOOGLE_VERTEX_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "textembedding-gecko".
            project_id (str, optional): The Google Cloud project ID.
                Defaults to "cloud-large-language-models".
            region (str, optional): The Google Cloud region.
                Defaults to "us-central1".
        r   N)ÚTextEmbeddingModelzjThe vertexai python package is not installed. Please install it with `pip install google-cloud-aiplatform`r†   r‡   r   rˆ   r   r   )r   r   Úrequest_metadata)r   Úvertexai.language_modelsrÀ   r"   r#   r�   rŽ   r�   r$   r%   r   r   r   r½   r¾   Úinitr   Úfrom_pretrainedÚ_model)r)   r   r   r½   r¾   r   r   rÀ   s           r*   r+   z&GoogleVertexEmbeddingFunction.__init__î  s  € ð*	ÛÝCð ÐÜ�M‰Mð_ä"ôô
 �9‰9Ð%Ó&Ð2Ø#3ˆDÕ à#2ˆDÔ àÒA¤"§)¡)¨D×,@Ñ,@Ó"AˆŒØ�|Š|ÜØ�t×+Ñ+Ð,Ð,MÐNóð ð %ˆŒØ$ˆŒØˆŒà�‰ØØØ2°g¼k¸]Ð4KÐLÐMð 	ô 	
ð
 )×8Ñ8¸ÓDˆ�øô? ò 	ÜØ|óð ð	ús   ‚
C# Ã#C8r,   r-   c                 ó(  — t        d„ |D «       «      st        d«      ‚g }|D ]_  }| j                  j                  |g«      }|j	                  t        j                  |d   j                  t
        j                  ¬«      «       Œa t        t        |«      S )r­   c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr1   r2   r”   s     r*   r7   z9GoogleVertexEmbeddingFunction.__call__.<locals>.<genexpr>2  r–   r8   z6Google Vertex only supports text documents, not imagesr   r@   )rD   r#   rÅ   Úget_embeddingsrJ   rK   rL   r?   rM   r   r   )r)   r,   rP   r™   r›   s        r*   rR   z&GoogleVertexEmbeddingFunction.__call__'  s„   € ô Ñ;°UÔ;Ô;ÜÐUÓVÐVà9;ˆØò 	ˆDØ#Ÿ{™{×9Ñ9¸4¸&ÓAÐØ×"Ñ"Ü—‘Ð)¨!Ñ,×3Ñ3¼2¿:¹:ÔFõð	ô ”J Ó0Ð0rV   c                   ó   — y)NÚgoogle_vertexrU   rU   rV   r*   rW   z"GoogleVertexEmbeddingFunction.name?  rX   rV   c                  ó   — yrZ   rU   r\   s    r*   r]   z+GoogleVertexEmbeddingFunction.default_spaceC  r^   rV   c                 ó
   — g d¢S r`   rU   r\   s    r*   rc   z.GoogleVertexEmbeddingFunction.supported_spacesF  rd   rV   r=   re   c                 óÆ   — | j                  d«      }| j                  d«      }| j                  d«      }| j                  d«      }|�|�|�|€J d«       ‚t        ||||¬«      S )Nr   r   r½   r¾   r¡   ©r   r   r½   r¾   )rh   r¼   )r=   r   r   r½   r¾   s        r*   ri   z/GoogleVertexEmbeddingFunction.build_from_configI  sx   € à Ÿ*™*Ð%6Ó7ˆØ—Z‘Z Ó-ˆ
Ø—Z‘Z Ó-ˆ
Ø—‘˜HÓ%ˆð Ð#ØÐ!ØÐ!Øˆ~à;Ð;Ó;�5ä,Ø+Ø!Ø!Øô	
ð 	
rV   c                 ó`   — | j                   | j                  | j                  | j                  dœS )NrÎ   rÎ   r\   s    r*   rl   z(GoogleVertexEmbeddingFunction.get_config_  s*   € à#×3Ñ3ØŸ/™/ØŸ/™/Ø—k‘kñ	
ð 	
rV   rm   rn   c                 ó^   — d|v rt        d«      ‚d|v rt        d«      ‚d|v rt        d«      ‚y )Nr   rp   r½   zSThe project ID cannot be changed after the embedding function has been initialized.r¾   zOThe region cannot be changed after the embedding function has been initialized.rr   rs   s      r*   rt   z4GoogleVertexEmbeddingFunction.validate_config_updateg  sU   € ð ˜:Ñ%ÜØeóð ð ˜:Ñ%ÜØeóð ð �zÑ!ÜØaóð ð "rV   c                 ó   — t        | d«       y)rv   rÊ   Nr   rw   s    r*   rx   z-GoogleVertexEmbeddingFunction.validate_configw  ry   rV   )Nztextembedding-geckozcloud-large-language-modelszus-central1ÚCHROMA_GOOGLE_VERTEX_API_KEYrº   rU   rV   r*   r¼   r¼   ë  s9  „ ñ Kð "&Ø/Ø7Ø#Ø=ñ7Eà˜#‘ð7Eð ð7Eð ð	7Eð
 ð7Eð ó7Eðr1˜ið 1¨Jó 1ð0 ð�#ò ó ðð˜uó ð& $ u¡+ó &ð ð
 $ s¨C x¡.ð 
Ð5Sò 
ó ð
ð*
˜D  c ™Nó 
ðØ˜s C˜x™.ðØ6:¸3À¸8±nðà	óð  ð
8  S¨# X¡ð 
8°4ò 
8ó ñ
8rV   r¼   )Úchromadb.api.typesr   r   r   r   Úchromadbr   Útypingr   r	   r
   r   r   r$   ÚnumpyrK   Únumpy.typingÚnptÚ*chromadb.utils.embedding_functions.schemasr   r�   r   ÚGoogleGenaiEmbeddingFunctionrƒ   r¨   r¼   rU   rV   r*   ú<module>rÛ      s~   ðß NÓ NÝ  ß 2Õ 2Û 	Û Ý Ý MÛ ôC8Ð$5°iÑ$@ô C8ðN  =Ð ôZ?Ð*;¸IÑ*Fô Z?ôzv6Ð"3°IÑ">ô v6ôrW8Ð$5°iÑ$@õ W8rV   