
    3i                         S SK Jr  S SKJrJrJrJrJrJrJ	r	J
r
  S SKJrJrJrJrJrJr  S SKrS SKrS SKrS SKJr  S SKrS SKr " S S\	\   5      rg)    validate_config_schema)	Documents
EmbeddingsImagesis_documentis_image
EmbeddableEmbeddingFunctionSpace)ListDictAnyUnioncastOptionalN)BytesIOc            	          \ 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)RoboflowEmbeddingFunction   za
This class is used to generate embeddings for a list of texts or images using the Roboflow API.
Napi_keyapi_urlapi_key_env_varreturnc                    Ub  [         R                  " S[        5        X0l        U=(       d    [        R
                  " U5      U l        U R                  (       d  [        SU S35      eX l         [        R                  " S5      U l        [        R                  " S5      U l        g! [         a    [        S5      ef = f)a7  
Create a RoboflowEmbeddingFunction.

Args:
    api_key_env_var (str, optional): Environment variable name that contains your API key for the Roboflow API.
        Defaults to "CHROMA_ROBOFLOW_API_KEY".
    api_url (str, optional): The URL of the Roboflow API.
        Defaults to "https://infer.roboflow.com".
NzDirect api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.zThe z! environment variable is not set.z	PIL.ImagezTThe PIL python package is not installed. Please install it with `pip install pillow`httpx)warningswarnDeprecationWarningr   osgetenvr   
ValueErrorr   	importlibimport_module	_PILImageImportError_httpx)selfr   r   r   s       x/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/utils/embedding_functions/roboflow_embedding_function.py__init__"RoboflowEmbeddingFunction.__init__   s      MM_"
  /<"))O"<||tO#44UVWW	&44[ADN  --g6  	f 	s   0B' 'B=inputc                 Z   / nU GH  n[        U5      (       a  U R                  R                  U5      n[        5       nUR	                  USS9  [
        R                  " UR                  5       5      R                  S5      nSSUS.0nU R                  R                  U R                   SU R                   3US9nUR                  5       S	   n	UR                  [        R                   " U	S
   [        R"                  S95        GM  [%        U5      (       d  GM  SU0n
U R                  R                  U R                   SU R                   3U
S9nUR                  5       S	   n	UR                  [        R                   " U	S
   [        R"                  S95        GM     ['        [(        U5      $ )z
Generate embeddings for the given documents or images.

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

Returns:
    Embeddings for the documents or images.
JPEG)formatzutf-8imagebase64)typevaluez/clip/embed_image?api_key=)json
embeddingsr   )dtypetextz/clip/embed_text?api_key=)r	   r%   	fromarrayr   saver1   	b64encodegetvaluedecoder'   postr   r   r4   appendnparrayfloat32r   r   r   )r(   r,   r5   itemr0   bufferbase64_imageinfer_clip_payload_imageresresultinfer_clip_payload_texts              r)   __call__"RoboflowEmbeddingFunction.__call__@   sz    
D~~006 

6&
1%//0ABII'R  (!-,( kk&&||n$>t||nM1 ' 
 L1!!"((6!9BJJ"GHT""D+' kk&&||n$=dll^L0 ' 
 L1!!"((6!9BJJ"GHE J J
++    c                      g)Nroboflow rN   rK   r)   nameRoboflowEmbeddingFunction.names   s    rK   c                     g)NcosinerN   r(   s    r)   default_space'RoboflowEmbeddingFunction.default_spacew   s    rK   c                 
    / SQ$ )N)rR   l2iprN   rS   s    r)   supported_spaces*RoboflowEmbeddingFunction.supported_spacesz   s    %%rK   configz+EmbeddingFunction[Union[Documents, Images]]c                 r    U R                  S5      nU R                  S5      nUb  Uc   S5       e[        XS9$ )Nr   r   zThis code should not be reachedr   r   )getr   )r[   r   r   s      r)   build_from_config+RoboflowEmbeddingFunction.build_from_config}   sF     !**%67**Y'"go;;;5(+
 	
rK   c                 4    U R                   U R                  S.$ )Nr]   r]   rS   s    r)   
get_config$RoboflowEmbeddingFunction.get_config   s    #'#7#7DLLQQrK   
old_config
new_configc                     g )NrN   )r(   rd   re   s      r)   validate_config_update0RoboflowEmbeddingFunction.validate_config_update   s     	rK   c                     [        U S5        g)z
Validate the configuration using the JSON schema.

Args:
    config: Configuration to validate

Raises:
    ValidationError: If the configuration does not match the schema
rM   Nr   )r[   s    r)   validate_config)RoboflowEmbeddingFunction.validate_config   s     	vz2rK   )r%   r'   r   r   r   )Nzhttps://infer.roboflow.comCHROMA_ROBOFLOW_API_KEY)__name__
__module____qualname____firstlineno____doc__r   strr*   r
   r   rI   staticmethodrO   r   rT   r   rY   r   r   r_   rb   rg   rj   __static_attributes__rN   rK   r)   r   r      s&    "&38	$7#$7 $7 	$7
 
$7L1,j 1,Z 1,f #  u &$u+ & 
S#X
	6
 
RDcN RsCx.6:38n	 
3S#X 
34 
3 
3rK   r   )*chromadb.utils.embedding_functions.schemasr   chromadb.api.typesr   r   r   r   r	   r
   r   r   typingr   r   r   r   r   r   r    r#   r1   ior   numpyr?   r   r   rN   rK   r)   <module>rz      sE    M	 	 	 : 9 	     J3 1* = J3rK   