
    Ig70                        d dl mZmZmZmZmZmZmZmZ d dl	Z
d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ dd	d
ddddidddd	dddddddddddddddiddddd
dddd iddd!dddd"dd#iddd$d%d&dd'dd(iddd)dd*d+d,dd-iddd.dd/dddd0iddd1dd2d+d3dd1id4dd5dd2d+d'dd5id4dd6dd2d+ddd6id4dd7d	d2d+d8dd9id4dd:d	d;d+d<dd:id4dd=dd2d+d>dd=id4dgZ G d? d@eee
j0                           Z G dA dBe      Zy)C    )AnyDictIterableListOptionalSequenceTypeUnionN)OnnxProvider)OnnxOutputContext)define_cache_dir	normalize)OnnxTextModelTextEmbeddingWorker)TextEmbeddingBasezBAAI/bge-base-eni   z}Text embeddings, Unimodal (text), English, 512 input tokens truncation, Prefixes for queries/documents: necessary, 2023 year.mitgzG?urlzGhttps://storage.googleapis.com/qdrant-fastembed/fast-bge-base-en.tar.gzzmodel_optimized.onnx)modeldimdescriptionlicense
size_in_GBsources
model_filezBAAI/bge-base-en-v1.5zText embeddings, Unimodal (text), English, 512 input tokens truncation, Prefixes for queries/documents: not so necessary, 2023 year.gzG?zLhttps://storage.googleapis.com/qdrant-fastembed/fast-bge-base-en-v1.5.tar.gzzqdrant/bge-base-en-v1.5-onnx-q)r   hfzBAAI/bge-large-en-v1.5i   g333333?r   zqdrant/bge-large-en-v1.5-onnxz
model.onnxzBAAI/bge-small-eni  gp=
ף?zHhttps://storage.googleapis.com/qdrant-fastembed/BAAI-bge-small-en.tar.gzBAAI/bge-small-en-v1.5gx&?zqdrant/bge-small-en-v1.5-onnx-qzBAAI/bge-small-zh-v1.5i   zText embeddings, Unimodal (text), Chinese, 512 input tokens truncation, Prefixes for queries/documents: not so necessary, 2023 year.g
ףp=
?zMhttps://storage.googleapis.com/qdrant-fastembed/fast-bge-small-zh-v1.5.tar.gzz;sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2zText embeddings, Unimodal (text), Multilingual (~50 languages), 512 input tokens truncation, Prefixes for queries/documents: not necessary, 2019 year.z
apache-2.0g)\(?z3qdrant/paraphrase-multilingual-MiniLM-L12-v2-onnx-Qzthenlper/gte-largezText embeddings, Unimodal (text), English, 512 input tokens truncation, Prefixes for queries/documents: not necessary, 2023 year.zqdrant/gte-large-onnxz"mixedbread-ai/mxbai-embed-large-v1z}Text embeddings, Unimodal (text), English, 512 input tokens truncation, Prefixes for queries/documents: necessary, 2024 year.g{Gz?zonnx/model.onnxz#snowflake/snowflake-arctic-embed-xsz"snowflake/snowflake-arctic-embed-sz"snowflake/snowflake-arctic-embed-mgQ?z"Snowflake/snowflake-arctic-embed-mz'snowflake/snowflake-arctic-embed-m-longz~Text embeddings, Unimodal (text), English, 2048 input tokens truncation, Prefixes for queries/documents: necessary, 2024 year.gHzG?z"snowflake/snowflake-arctic-embed-lgRQ?c                       e Zd ZdZedeeeef      fd       Z		 	 	 	 	 	 	 	 ddede
e   de
e   de
ee      ded	e
ee      d
ede
e   f fdZ	 	 ddeeee   f   dede
e   deej&                     fdZeded   fd       Zdeeej&                  f   deeej&                  f   fdZdedeej&                     fdZddZ xZS )OnnxTextEmbeddingz+Implementation of the Flag Embedding model.returnc                     t         S )z
        Lists the supported models.

        Returns:
            List[Dict[str, Any]]: A list of dictionaries containing the model information.
        )supported_onnx_modelsclss    Z/var/www/html/answerous/venv/lib/python3.12/site-packages/fastembed/text/onnx_embedding.pylist_supported_modelsz'OnnxTextEmbedding.list_supported_models   s
     %$    
model_name	cache_dirthreads	providerscuda
device_ids	lazy_load	device_idc	                    t        
|   |||fi |	 || _        || _        || _        || _        ||| _        n(| j                  | j                  d   | _        nd| _        | j                  |      | _        t        |      | _
        | j                  | j                  | j                  | j                        | _        | j                  s| j                          yy)a  
        Args:
            model_name (str): The name of the model to use.
            cache_dir (str, optional): The path to the cache directory.
                                       Can be set using the `FASTEMBED_CACHE_PATH` env variable.
                                       Defaults to `fastembed_cache` in the system's temp directory.
            threads (int, optional): The number of threads single onnxruntime session can use. Defaults to None.
            providers (Optional[Sequence[OnnxProvider]], optional): The list of onnxruntime providers to use.
                Mutually exclusive with the `cuda` and `device_ids` arguments. Defaults to None.
            cuda (bool, optional): Whether to use cuda for inference. Mutually exclusive with `providers`
                Defaults to False.
            device_ids (Optional[List[int]], optional): The list of device ids to use for data parallel processing in
                workers. Should be used with `cuda=True`, mutually exclusive with `providers`. Defaults to None.
            lazy_load (bool, optional): Whether to load the model during class initialization or on demand.
                Should be set to True when using multiple-gpu and parallel encoding. Defaults to False.
            device_id (Optional[int], optional): The device id to use for loading the model in the worker process.

        Raises:
            ValueError: If the model_name is not in the format <org>/<model> e.g. BAAI/bge-base-en.
        Nr   )local_files_only)super__init__r*   r-   r,   r+   r.   _get_model_descriptionmodel_descriptionr   r(   download_model_local_files_only
_model_dirload_onnx_model)selfr'   r(   r)   r*   r+   r,   r-   r.   kwargs	__class__s             r$   r2   zOnnxTextEmbedding.__init__   s    @ 	YB6B"" %	  &DN__(!__Q/DN!DN!%!<!<Z!H))4--""DNNTE[E[ . 
 ~~  " r&   	documents
batch_sizeparallelc              +      K    | j                   d| j                  t        | j                        |||| j                  | j
                  | j                  d|E d{    y7 w)a  
        Encode a list of documents into list of embeddings.
        We use mean pooling with attention so that the model can handle variable-length inputs.

        Args:
            documents: Iterator of documents or single document to embed
            batch_size: Batch size for encoding -- higher values will use more memory, but be faster
            parallel:
                If > 1, data-parallel encoding will be used, recommended for offline encoding of large datasets.
                If 0, use all available cores.
                If None, don't use data-parallel processing, use default onnxruntime threading instead.

        Returns:
            List of embeddings, one per document
        )r'   r(   r<   r=   r>   r*   r+   r,   N )_embed_documentsr'   strr(   r*   r+   r,   )r9   r<   r=   r>   r:   s        r$   embedzOnnxTextEmbedding.embed   sb     , )4(( 

$..)!nn

 

 
	
 
	
s   AA$A"A$r   c                     t         S )N)OnnxTextEmbeddingWorkerr"   s    r$   _get_worker_classz#OnnxTextEmbedding._get_worker_class  s    &&r&   
onnx_inputc                     |S )z,
        Preprocess the onnx input.
        r@   )r9   rG   r:   s      r$   _preprocess_onnx_inputz(OnnxTextEmbedding._preprocess_onnx_input  s
     r&   outputc                 x    |j                   }t        |d d df         j                  t        j                        S )Nr   )model_outputr   astypenpfloat32)r9   rJ   
embeddingss      r$   _post_process_onnx_outputz+OnnxTextEmbedding._post_process_onnx_output  s0    ((
AqD)*11"**==r&   c                     | j                  | j                  | j                  d   | j                  | j                  | j
                  | j                         y )Nr   )	model_dirr   r)   r*   r+   r.   )_load_onnx_modelr7   r4   r)   r*   r+   r.   )r9   s    r$   r8   z!OnnxTextEmbedding.load_onnx_model"  sF    oo--l;LLnnnn 	 	
r&   )r   NNNFNFN)   N)r   N)__name__
__module____qualname____doc__classmethodr   r   rB   r   r%   r   intr   r   boolr2   r
   r   rN   ndarrayrC   r	   rF   rI   r   rQ   r8   __classcell__)r;   s   @r$   r   r      sz   5%d4S>&: % % 3#'!%6:*.#'7#7# C=7# #	7#
 H\237# 7# T#Y'7# 7# C=7#x "&	 
hsm+, 
  
 3-	 
 
"**	 
D '$'<"= ' 'sBJJ/	c2::o	>0A >hrzzFZ >
r&   r   c                        e Zd ZdededefdZy)rE   r'   r(   r   c                      t        d||dd|S )N   )r'   r(   r)   r@   )r   )r9   r'   r(   r:   s       r$   init_embeddingz&OnnxTextEmbeddingWorker.init_embedding.  s)     ! 
!
 	
 	
r&   N)rV   rW   rX   rB   r   rb   r@   r&   r$   rE   rE   -  s#    

 

 

r&   rE   )typingr   r   r   r   r   r   r	   r
   numpyrN   fastembed.commonr   fastembed.common.onnx_modelr   fastembed.common.utilsr   r   fastembed.text.onnx_text_modelr   r   "fastembed.text.text_embedding_baser   r!   r]   r   rE   r@   r&   r$   <module>rj      s   M M M  ) 9 > M @ $ W\
 -
 ) ^a2
 - * ^1
 #
 % W]
 -
 * ^3
 -
 * ^b
 -
 O pG
 -
 & [)
 #
 6 W6
 (
 7 W7
 (
 6 W6
 (
 6 W6
 (
 ; X;
 (
 6 W6
 (
c\ ~@
)=+D @
F
1 
r&   