
    Bvhq                     t    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y)    )EmbeddingFunctionSpace
Embeddings	Documentsvalidate_config_schema)ListDictAnyOptionalNc                      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y)VoyageAIEmbeddingFunctionz_
    This class is used to generate embeddings for a list of texts using the VoyageAI API.
    Napi_key
model_nameapi_key_env_var
input_type
truncationc                 b   	 ddl }|t        j                  dt
               || _        |xs t        j                  |      | _	        | j                  st        d| d      || _
        || _        || _        |j                  | j                        | _        y# t        $ r t        d      w xY w)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.zThe z! environment variable is not set.)r   )voyageaiImportError
ValueErrorwarningswarnDeprecationWarningr   osgetenvr   r   r   r   Client_client)selfr   r   r   r   r   r   s          h/RAG/venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/voyageai_embedding_function.py__init__z"VoyageAIEmbeddingFunction.__init__   s    ,	 MM_"  /<"))O"<||tO#44UVWW$$$t||<)  	m 	s   B B.inputreturnc                     | j                   j                  || j                  | j                  | j                        }|j
                  D cg c]'  }t        j                  |t        j                        ) c}S c c}w )z
        Generate embeddings for the given documents.

        Args:
            input: Documents to generate embeddings for.

        Returns:
            Embeddings for the documents.
        )textsmodelr   r   )dtype)	r   embedr   r   r   
embeddingsnparrayfloat32)r   r"   r)   	embeddings       r    __call__z"VoyageAIEmbeddingFunction.__call__<   sp     \\''//	 ( 

 DNCXCX
CXiBHHYbjj1CX
 	
 
s   ,A;c                       y)Nr    r0       r    namezVoyageAIEmbeddingFunction.nameR   s    r1   c                      y)Ncosiner0   r   s    r    default_spacez'VoyageAIEmbeddingFunction.default_spaceV   s    r1   c                 
    g dS )N)r4   l2ipr0   r5   s    r    supported_spacesz*VoyageAIEmbeddingFunction.supported_spacesY   s    %%r1   configzEmbeddingFunction[Documents]c                     | j                  d      }| j                  d      }| j                  d      }| j                  d      }||J d       t        |||||      S d      S )Nr   r   r   r   zThis code should not be reachedTr   r   r   r   )getr   )r;   r   r   r   r   s        r    build_from_configz+VoyageAIEmbeddingFunction.build_from_config\   s     **%67ZZ-
ZZ-
ZZ-
"j&8;;;5(+!!%/%;z	
 	
 BF	
 	
r1   c                 `    | j                   | j                  | j                  | j                  dS )Nr=   r=   r5   s    r    
get_configz$VoyageAIEmbeddingFunction.get_configm   s*    #33//////	
 	
r1   
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   rB   rC   s      r    validate_config_updatez0VoyageAIEmbeddingFunction.validate_config_updateu   s!     :%e  &r1   c                     t        | d       y)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   )r;   s    r    validate_configz)VoyageAIEmbeddingFunction.validate_config}   s     	vz2r1   )Nzvoyage-large-2CHROMA_VOYAGE_API_KEYNT)__name__
__module____qualname____doc__r   strboolr!   r   r   r.   staticmethodr2   r   r6   r	   r:   r
   r   r?   rA   rE   rG   r0   r1   r    r   r   	   s6    "&*6$(,=#,= ,= 	,=
 SM,= ,=\
i 
J 
, #  u &$u+ & 
$sCx. 
5S 
 
 
DcN 
sCx.6:38n	 
3S#X 
34 
3 
3r1   r   )chromadb.api.typesr   r   r   r   *chromadb.utils.embedding_functions.schemasr   typingr	   r
   r   r   r   numpyr*   r   r   r0   r1   r    <module>rT      s1    N N M , , 	  3 1) < 3r1   