
    _j	                     n    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
 d dlZ G d dee                   ZdS )    )EmbeddingFunctionSpace
Embeddings	Documentsvalidate_config_schema)ListDictAnyNc                       e Zd ZdZd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 )Text2VecEmbeddingFunctionza
    This class is used to generate embeddings for a list of texts using the Text2Vec model.
     shibing624/text2vec-base-chinese
model_namec                     	 ddl m} n# t          $ r t          d          w xY w|| _         ||          | _        dS )z
        Initialize the Text2VecEmbeddingFunction.

        Args:
            model_name (str, optional): The name of the model to use for text embeddings.
                Defaults to "shibing624/text2vec-base-chinese".
        r   )SentenceModelz[The text2vec python package is not installed. Please install it with `pip install text2vec`)model_name_or_pathN)text2vecr   ImportError
ValueErrorr   _model)selfr   r   s      {/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/utils/embedding_functions/text2vec_embedding_function.py__init__z"Text2VecEmbeddingFunction.__init__   sm    	....... 	 	 	m  	
 %#mzBBBs   	 #inputreturnc                     t          d |D                       st          d          | j                            t	          |          d          }d |D             S )z
        Generate embeddings for the given documents.

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

        Returns:
            Embeddings for the documents.
        c              3   @   K   | ]}t          |t                    V  d S N)
isinstancestr).0items     r   	<genexpr>z5Text2VecEmbeddingFunction.__call__.<locals>.<genexpr>)   s,      ;;T:dC((;;;;;;    z1Text2Vec only supports text documents, not imagesT)convert_to_numpyc                 N    g | ]"}t          j        |t           j                   #S ))dtype)nparrayfloat32)r!   	embeddings     r   
<listcomp>z6Text2VecEmbeddingFunction.__call__.<locals>.<listcomp>/   s)    RRR)"*555RRRr$   )allr   r   encodelist)r   r   
embeddingss      r   __call__z"Text2VecEmbeddingFunction.__call__   sj     ;;U;;;;; 	RPQQQ[''Ud'KK
 SRzRRRRr$   c                      dS )Nr    r3   r$   r   namezText2VecEmbeddingFunction.name1   s    zr$   c                     dS )Ncosiner3   r   s    r   default_spacez'Text2VecEmbeddingFunction.default_space5   s    xr$   c                 
    g dS )N)r6   l2ipr3   r7   s    r   supported_spacesz*Text2VecEmbeddingFunction.supported_spaces8   s    %%%%r$   configzEmbeddingFunction[Documents]c                 d    |                      d          }|
J d            t          |          S )Nr   FzThis code should not be reachedr   )getr   )r=   r   s     r   build_from_configz+Text2VecEmbeddingFunction.build_from_config;   s9    ZZ--
;;;;;(J????r$   c                     d| j         iS )Nr   r?   r7   s    r   
get_configz$Text2VecEmbeddingFunction.get_configD   s    do..r$   
old_config
new_configNc                     d S r   r3   )r   rD   rE   s      r   validate_config_updatez0Text2VecEmbeddingFunction.validate_config_updateG   s	     	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)Text2VecEmbeddingFunction.validate_configO   s     	vz22222r$   )r   )__name__
__module____qualname____doc__r    r   r   r   r1   staticmethodr4   r   r8   r	   r<   r
   r   rA   rC   rG   rI   r3   r$   r   r   r      s        C C3 C C C C$Si SJ S S S S& #    \u    &$u+ & & & & @$sCx. @5S @ @ @ \@/DcN / / / /sCx.6:38n	    
3S#X 
34 
3 
3 
3 \
3 
3 
3r$   r   )chromadb.api.typesr   r   r   r   *chromadb.utils.embedding_functions.schemasr   typingr	   r
   r   numpyr(   r   r3   r$   r   <module>rS      s    N N N N N N N N N N N N M M M M M M " " " " " " " " " "    S3 S3 S3 S3 S3 1) < S3 S3 S3 S3 S3r$   