
    _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 d dlZd dlZd dlZ G d dee                   ZdS )    )EmbeddingFunctionSpace
Embeddings	Documentsvalidate_config_schema)ListDictAnyOptionalNc                   R   e Zd ZdZ	 	 	 	 	 ddee         deded	e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dS )VoyageAIEmbeddingFunctionz_
    This class is used to generate embeddings for a list of texts using the VoyageAI API.
    Nvoyage-large-2CHROMA_VOYAGE_API_KEYTapi_key
model_nameapi_key_env_var
input_type
truncationc                    	 ddl }n# t          $ r t          d          w xY w|t          j        dt
                     t          j        d          d| _        n|| _        |pt          j        | j                  | _	        | j	        st          d| j         d          || _
        || _        || _        |                    | j	                  | _        dS )	a  
        Initialize the VoyageAIEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the VoyageAI API.
                Defaults to "CHROMA_VOYAGE_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "voyage-large-2".
            api_key (str, optional): API key for the VoyageAI API. If not provided, will look for it in the environment variable.
            input_type (str, optional): The type of input to use for the VoyageAI API.
                Defaults to None.
            truncation (bool): Whether to truncate the input text.
                Defaults to True.
        r   Nz[The voyageai python package is not installed. Please install it with `pip install voyageai`zDirect api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.VOYAGE_API_KEYzThe z! environment variable is not set.)r   )voyageaiImportError
ValueErrorwarningswarnDeprecationWarningosgetenvr   r   r   r   r   Client_client)selfr   r   r   r   r   r   s          {/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/utils/embedding_functions/voyageai_embedding_function.py__init__z"VoyageAIEmbeddingFunction.__init__   s   ,	OOOO 	 	 	m  	
 M_"   9%&&2#3D  #2D A")D,@"A"A| 	Nt+NNN   %$$t|<<s    !inputreturnc                 ~    | j                             || j        | j        | j                  }d |j        D             S )z
        Generate embeddings for the given documents.

        Args:
            input: Documents to generate embeddings for.

        Returns:
            Embeddings for the documents.
        )textsmodelr   r   c                 N    g | ]"}t          j        |t           j                   #S ))dtype)nparrayfloat32).0	embeddings     r#   
<listcomp>z6VoyageAIEmbeddingFunction.__call__.<locals>.<listcomp>T   s6     
 
 
6?BHYbj111
 
 
    )r!   embedr   r   r   
embeddings)r"   r%   r4   s      r#   __call__z"VoyageAIEmbeddingFunction.__call__B   sV     \''/	 ( 
 


 
CMCX
 
 
 	
r2   c                      dS )Nr    r7   r2   r#   namezVoyageAIEmbeddingFunction.nameX   s    zr2   c                     dS )Ncosiner7   r"   s    r#   default_spacez'VoyageAIEmbeddingFunction.default_space\   s    xr2   c                 
    g dS )N)r:   l2ipr7   r;   s    r#   supported_spacesz*VoyageAIEmbeddingFunction.supported_spaces_   s    %%%%r2   configzEmbeddingFunction[Documents]c                     |                      d          }|                      d          }|                      d          }|                      d          }||
J d            t          |||||nd          S )	Nr   r   r   r   FzThis code should not be reachedTr   r   r   r   )getr   )rA   r   r   r   r   s        r#   build_from_configz+VoyageAIEmbeddingFunction.build_from_configb   s     **%677ZZ--
ZZ--
ZZ--
"j&8;;;;;(+!!%/%;zz	
 
 
 	
r2   c                 8    | j         | j        | j        | j        dS )NrC   rC   r;   s    r#   
get_configz$VoyageAIEmbeddingFunction.get_configs   s&    #3///	
 
 	
r2   
old_config
new_configc                 ,    d|v rt          d          d S )Nr   zSThe model name cannot be changed after the embedding function has been initialized.)r   )r"   rH   rI   s      r#   validate_config_updatez0VoyageAIEmbeddingFunction.validate_config_update{   s,     :%%e   &%r2   c                 &    t          | d           dS )z
        Validate the configuration using the JSON schema.

        Args:
            config: Configuration to validate

        Raises:
            ValidationError: If the configuration does not match the schema
        r   Nr   )rA   s    r#   validate_configz)VoyageAIEmbeddingFunction.validate_config   s     	vz22222r2   )Nr   r   NT)__name__
__module____qualname____doc__r   strboolr$   r   r   r5   staticmethodr8   r   r<   r	   r@   r
   r   rE   rG   rK   rM   r7   r2   r#   r   r   	   s         "&*6$(2= 2=#2= 2= 	2=
 SM2= 2= 2= 2= 2=h
i 
J 
 
 
 
, #    \u    &$u+ & & & & 
$sCx. 
5S 
 
 
 \
 
DcN 
 
 
 
sCx.6:38n	    
3S#X 
34 
3 
3 
3 \
3 
3 
3r2   r   )chromadb.api.typesr   r   r   r   *chromadb.utils.embedding_functions.schemasr   typingr	   r
   r   r   r   numpyr,   r   r   r7   r2   r#   <module>rY      s    N N N N N N N N N N N N M M M M M M , , , , , , , , , , , , 				     E3 E3 E3 E3 E3 1) < E3 E3 E3 E3 E3r2   