
    _j`                         d dl mZmZmZmZ d dl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d dl	mZ erd dlZ G d dee                   ZdS )	    )EmbeddingFunctionSpace
Embeddings	Documentsvalidate_config_schema)decode_embedding)ListDictAnyOptionalN)TYPE_CHECKINGc            
       L   e Zd ZdZ	 	 	 	 dde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dS )PerplexityEmbeddingFunctionza
    This class is used to generate embeddings for a list of texts using the Perplexity API.
    Npplx-embed-v1-0.6bPERPLEXITY_API_KEYapi_key
model_nameapi_key_env_var
dimensionsc                    	 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        | j	                  | _        dS )	a  
        Initialize the PerplexityEmbeddingFunction.

        Args:
            api_key_env_var (str, optional): Environment variable name that contains your API key for the Perplexity API.
                Defaults to "PERPLEXITY_API_KEY".
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "pplx-embed-v1-0.6b".
            api_key (str, optional): API key for the Perplexity API. If not provided, will look for it in the environment variable.
            dimensions (int, optional): Perplexity embeddings support Matryoshka representation learning, allowing you
                to reduce embedding dimensions while maintaining quality.
        r   NzcThe perplexityai python package is not installed. Please install it with `pip install perplexityai`zDirect api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.r   zThe z! environment variable is not set.)r   )
perplexityImportError
ValueErrorwarningswarnDeprecationWarningosgetenvr   r   r   r   
Perplexity_client)selfr   r   r   r   r   s         }/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/utils/embedding_functions/perplexity_embedding_function.py__init__z$PerplexityEmbeddingFunction.__init__   s   &	 	 	 	u  	
 M_"   9)**6#7D  #2D A")D,@"A"A| 	Nt+NNN   %$,z,T\BBB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.
        )r%   modelr   c                 6    g | ]}t          |j                  S  )r	   	embedding).0embs     r#   
<listcomp>z8PerplexityEmbeddingFunction.__call__.<locals>.<listcomp>S   s#    IIIC //III    )r!   
embeddingscreater   r   data)r"   r%   responses      r#   __call__z$PerplexityEmbeddingFunction.__call__C   sI     <*11/ 2 
 
 JI8=IIIIr/   c                      dS )Nr   r*   r*   r/   r#   namez PerplexityEmbeddingFunction.nameU   s    |r/   c                     dS )Ncosiner*   r"   s    r#   default_spacez)PerplexityEmbeddingFunction.default_spaceY   s    xr/   c                 
    g dS )N)r8   l2ipr*   r9   s    r#   supported_spacesz,PerplexityEmbeddingFunction.supported_spaces\   s    %%%%r/   configzEmbeddingFunction[Documents]c                     |                      d          }|                      d          }|                      d          }||
J d            t          |||          S )Nr   r   r   FzThis code should not be reachedr   r   r   )getr   )r?   r   r   r   s       r#   build_from_configz-PerplexityEmbeddingFunction.build_from_config_   sp     **%677ZZ--
ZZ--
"j&8;;;;;*+!!
 
 
 	
r/   c                 ,    | j         | j        | j        dS )NrA   rA   r9   s    r#   
get_configz&PerplexityEmbeddingFunction.get_confign   s!    #3//
 
 	
r/   
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"   rF   rG   s      r#   validate_config_updatez2PerplexityEmbeddingFunction.validate_config_updateu   s,     :%%e   &%r/   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   )r?   s    r#   validate_configz+PerplexityEmbeddingFunction.validate_config}   s     	v|44444r/   )Nr   r   N)__name__
__module____qualname____doc__r   strintr$   r   r   r4   staticmethodr6   r   r:   r
   r>   r   r   rC   rE   rI   rK   r*   r/   r#   r   r      s         "&.3$(.C .C#.C .C 	.C
 SM.C .C .C .C`Ji JJ J J J J$ #    \u    &$u+ & & & & 
$sCx. 
5S 
 
 
 \

DcN 
 
 
 
sCx.6:38n	    
5S#X 
54 
5 
5 
5 \
5 
5 
5r/   r   )chromadb.api.typesr   r   r   r   *chromadb.utils.embedding_functions.schemasr   (chromadb.utils.embedding_functions.utilsr	   typingr
   r   r   r   r   numpynpr   r   r   r   r*   r/   r#   <module>rY      s    N N N N N N N N N N N N M M M M M M E E E E E E , , , , , , , , , , , , 				                  z5 z5 z5 z5 z5"3I"> z5 z5 z5 z5 z5r/   