
    3i7                         S SK JrJrJrJr  S SKJrJrJrJ	r	J
r
  S SKrS SKrS SKJr  S SKJr  S SKr " S S\\   5      r " S S\\   5      r " S	 S
\\   5      rg)    )
Embeddings	DocumentsEmbeddingFunctionSpace)ListDictAnycastOptionalNvalidate_config_schemac                      \ rS rSrSr   SS\\   S\S\4S jjrS\S	\	4S
 jr
\S	\4S j5       rS	\4S jrS	\\   4S jr\S\\\4   S	S4S j5       rS	\\\4   4S jrS\\\4   S\\\4   S	S4S jr\S\\\4   S	S4S j5       rSrg)GooglePalmEmbeddingFunction
   zvTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a PaLM API key.Napi_key
model_nameapi_key_env_varc                 ^    SSK Jn  Ub  [        R
                  " S[        5        X0l        U=(       d    [        R                  " U5      U l
        U R                  (       d  [        SU S35      eX l        UR                  U R                  S9  X@l        g! [         a    [        S5      ef = f)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   NrThe 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.The ! environment variable is not set.r   )google.generativeaigenerativeaiImportError
ValueErrorwarningswarnDeprecationWarningr   osgetenvr   r   	configure_palm)selfr   r   r   palms        v/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/utils/embedding_functions/google_embedding_function.py__init__$GooglePalmEmbeddingFunction.__init__   s    	. MM_"
  /<"))O"<||tO#44UVWW$t||,
'  	 E 	s   B B,inputreturnc           
         [        S U 5       5      (       d  [        S5      eU Vs/ s HK  n[        R                  " U R                  R                  U R                  US9S   [        R                  S9PMM     sn$ s  snf )
Generate embeddings for the given documents.

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

Returns:
    Embeddings for the documents.
c              3   B   #    U  H  n[        U[        5      v   M     g 7fN
isinstancestr.0items     r'   	<genexpr>7GooglePalmEmbeddingFunction.__call__.<locals>.<genexpr>>        ;UT:dC((U   z4Google PaLM only supports text documents, not images)modeltext	embeddingdtype)allr   nparrayr$   generate_embeddingsr   float32)r%   r*   r;   s      r'   __call__$GooglePalmEmbeddingFunction.__call__3   s     ;U;;;STT 
  HH

..T__4.P jj	 
 	
 
s   AA<c                      g)Ngoogle_palm rH       r'   name GooglePalmEmbeddingFunction.nameK   s    rI   c                     gNcosinerH   r%   s    r'   default_space)GooglePalmEmbeddingFunction.default_spaceO       rI   c                 
    / SQ$ N)rN   l2iprH   rO   s    r'   supported_spaces,GooglePalmEmbeddingFunction.supported_spacesR       %%rI   configEmbeddingFunction[Documents]c                 r    U R                  S5      nU R                  S5      nUb  Uc   S5       e[        XS9$ )Nr   r   This code should not be reachedr   r   )getr   )rZ   r   r   s      r'   build_from_config-GooglePalmEmbeddingFunction.build_from_configU   sE     **%67ZZ-
"j&8;;;5*+
 	
rI   c                 4    U R                   U R                  S.$ )Nr^   r^   rO   s    r'   
get_config&GooglePalmEmbeddingFunction.get_configa   s    #'#7#7tWWrI   
old_config
new_configc                 &    SU;   a  [        S5      eg )Nr   SThe model name cannot be changed after the embedding function has been initialized.r   r%   re   rf   s      r'   validate_config_update2GooglePalmEmbeddingFunction.validate_config_updated   s!     :%e  &rI   c                     [        U S5        g)
Validate the configuration using the JSON schema.

Args:
    config: Configuration to validate

Raises:
    ValidationError: If the configuration does not match the schema
rG   Nr   rZ   s    r'   validate_config+GooglePalmEmbeddingFunction.validate_configl   s     	v}5rI   )r$   r   r   r   )Nzmodels/embedding-gecko-001CHROMA_GOOGLE_PALM_API_KEY__name__
__module____qualname____firstlineno____doc__r   r2   r(   r   r   rD   staticmethodrJ   r   rP   r   rW   r   r	   r`   rc   rk   rp   __static_attributes__rH   rI   r'   r   r   
   s    A "&6;	$#$ $ 	$L
i 
J 
0 #  u &$u+ & 	
$sCx. 	
5S 	
 	
XDcN XsCx.6:38n	 
6S#X 
64 
6 
6rI   r   c            	          \ rS rSrSr    SS\\   S\S\S\4S jjrS	\S
\	4S jr
\S
\4S j5       rS
\4S jrS
\\   4S jr\S\\\4   S
S4S j5       rS
\\\4   4S jrS\\\4   S\\\4   S
S4S jr\S\\\4   S
S4S j5       rSrg)#GoogleGenerativeAiEmbeddingFunctionz   zxTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a Google API key.Nr   r   	task_typer   c                 j    SSK Jn  Ub  [        R
                  " S[        5        X@l        U=(       d    [        R                  " U5      U l
        U R                  (       d  [        SU S35      eX l        X0l        UR                  U R                  S9  XPl        g! [         a    [        S5      ef = f)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 "CHROMA_GOOGLE_GENAI_API_KEY".
    model_name (str, optional): The name of the model to use for text embeddings.
        Defaults to "models/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".
r   Nr   r   r   r   r   )r   r   r   r   r   r   r    r   r!   r"   r   r   r~   r#   _genai)r%   r   r   r~   r   genais         r'   r(   ,GoogleGenerativeAiEmbeddingFunction.__init__}   s    &	/ MM_"
  /<"))O"<||tO#44UVWW$"-)  	 E 	s   B B2r*   r+   c                 D   [        S U 5       5      (       d  [        S5      e/ nU Hg  nU R                  R                  U R                  UU R
                  S9nUR                  [        R                  " US   [        R                  S95        Mi     [        [        U5      $ )r-   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr/   r0   r3   s     r'   r6   ?GoogleGenerativeAiEmbeddingFunction.__call__.<locals>.<genexpr>   r8   r9   z=Google Generative AI only supports text documents, not images)r:   contentr~   r<   r=   )r?   r   r   embed_contentr   r~   appendr@   rA   rC   r
   r   r%   r*   embeddings_listr;   embedding_results        r'   rD   ,GoogleGenerativeAiEmbeddingFunction.__call__   s     ;U;;;O  :<D#{{88oo..  9  
 "")+6bjjI  J00rI   c                      g)Ngoogle_generative_airH   rH   rI   r'   rJ   (GoogleGenerativeAiEmbeddingFunction.name   s    %rI   c                     grM   rH   rO   s    r'   rP   1GoogleGenerativeAiEmbeddingFunction.default_space   rR   rI   c                 
    / SQ$ rT   rH   rO   s    r'   rW   4GoogleGenerativeAiEmbeddingFunction.supported_spaces   rY   rI   rZ   r[   c                     U R                  S5      nU R                  S5      nU R                  S5      nUb  Ub  Uc   S5       e[        XUS9$ )Nr   r   r~   r]   r   r   r~   )r_   r|   )rZ   r   r   r~   s       r'   r`   5GoogleGenerativeAiEmbeddingFunction.build_from_config   sZ     **%67ZZ-
JJ{+	"j&8I<M;;;52+i
 	
rI   c                 J    U R                   U R                  U R                  S.$ )Nr   r   rO   s    r'   rc   .GoogleGenerativeAiEmbeddingFunction.get_config   s#    #33//
 	
rI   re   rf   c                 H    SU;   a  [        S5      eSU;   a  [        S5      eg )Nr   rh   r~   zRThe task type cannot be changed after the embedding function has been initialized.ri   rj   s      r'   rk   :GoogleGenerativeAiEmbeddingFunction.validate_config_update   s;     :%e  *$d  %rI   c                     [        U S5        g)rn   r   Nr   ro   s    r'   rp   3GoogleGenerativeAiEmbeddingFunction.validate_config   s     	v'=>rI   )r   r   r   r   r~   )Nzmodels/embedding-001RETRIEVAL_DOCUMENTCHROMA_GOOGLE_GENAI_API_KEYrs   rH   rI   r'   r|   r|   z   s&    C "&0-<)#) ) 	)
 )V1i 1J 1< &# & &u &$u+ & 

$sCx. 

5S 

 


DcN 

sCx.
6:38n
	
 
?S#X 
?4 
? 
?rI   r|   c                   $   \ rS rSrSr     SS\\   S\S\S\S\4
S	 jjrS
\S\	4S jr
\S\4S j5       rS\4S jrS\\   4S jr\S\\\4   SS4S j5       rS\\\4   4S jrS\\\4   S\\\4   SS4S jr\S\\\4   SS4S j5       rSrg)GoogleVertexEmbeddingFunction   zTo use this EmbeddingFunction, you must have the vertexai Python package installed and have Google Cloud credentials configured.Nr   r   
project_idregionr   c                     SSK nSSKJn  Ub  [
        R                  " S[        5        XPl        U=(       d    [        R                  " U5      U l        U R                  (       d  [	        SU S35      eX l        X0l        X@l        UR                  X4S9  UR!                  U5      U l        g! [         a    [	        S5      ef = f)	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   )projectlocation)vertexaivertexai.language_modelsr   r   r   r   r   r    r   r!   r"   r   r   r   r   initfrom_pretrained_model)r%   r   r   r   r   r   r   r   s           r'   r(   &GoogleVertexEmbeddingFunction.__init__  s    *	C MM_"
  /<"))O"<||tO#44UVWW$$j:(88D+  	| 	s   
B, ,Cr*   r+   c                 2   [        S U 5       5      (       d  [        S5      e/ nU H^  nU R                  R                  U/5      nUR	                  [
        R                  " US   R                  [
        R                  S95        M`     [        [        U5      $ )r-   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr/   r0   r3   s     r'   r6   9GoogleVertexEmbeddingFunction.__call__.<locals>.<genexpr>;  r8   r9   z6Google Vertex only supports text documents, not imagesr   r=   )r?   r   r   get_embeddingsr   r@   rA   valuesrC   r
   r   r   s        r'   rD   &GoogleVertexEmbeddingFunction.__call__0  s     ;U;;;UVV9;D#{{994&A"")!,332::F  J00rI   c                      g)Ngoogle_vertexrH   rH   rI   r'   rJ   "GoogleVertexEmbeddingFunction.nameH  s    rI   c                     grM   rH   rO   s    r'   rP   +GoogleVertexEmbeddingFunction.default_spaceL  rR   rI   c                 
    / SQ$ rT   rH   rO   s    r'   rW   .GoogleVertexEmbeddingFunction.supported_spacesO  rY   rI   rZ   r[   c                     U R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nUb	  Ub  Ub  Uc   S5       e[        UUUUS9$ )Nr   r   r   r   r]   r   r   r   r   )r_   r   )rZ   r   r   r   r   s        r'   r`   /GoogleVertexEmbeddingFunction.build_from_configR  sx     **%67ZZ-
ZZ-
H% #!!~;;;5,+!!	
 	
rI   c                 `    U R                   U R                  U R                  U R                  S.$ )Nr   r   rO   s    r'   rc   (GoogleVertexEmbeddingFunction.get_configh  s*    #33////kk	
 	
rI   re   rf   c                 j    SU;   a  [        S5      eSU;   a  [        S5      eSU;   a  [        S5      eg )Nr   rh   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.ri   rj   s      r'   rk   4GoogleVertexEmbeddingFunction.validate_config_updatep  sU     :%e  :%e  z!a  "rI   c                     [        U S5        g)rn   r   Nr   ro   s    r'   rp   -GoogleVertexEmbeddingFunction.validate_config  s     	v7rI   )r   r   r   r   r   r   )Nztextembedding-geckozcloud-large-language-modelszus-central1CHROMA_GOOGLE_VERTEX_API_KEYrs   rH   rI   r'   r   r      s9    K "&/7#=-E#-E -E 	-E
 -E -E^1i 1J 10 #  u &$u+ & 
$sCx. 
5S 
 
*
DcN 
sCx.6:38n	  
8S#X 
84 
8 
8rI   r   )chromadb.api.typesr   r   r   r   typingr   r   r	   r
   r   r!   numpyr@   numpy.typingnpt*chromadb.utils.embedding_functions.schemasr   r   r   r|   r   rH   rI   r'   <module>r      s^    N N 2 2 	   M m6"3I"> m6`A?*;I*F A?HM8$5i$@ M8rI   