
    sOip+                        U d dl mZ d dl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mZ d dlmZmZ  G d d	ed
      Z G d d      Ze
r< e
j*                         D  ci c]!  } | d   | d   ej,                  j.                  f# c} ni Zeeeeej,                  f   f   ed<   er# ej*                         D  ci c]  } | d   | 
 c} ni Zeeeeef   f   ed<   er4 ej*                         D ch c]  }|j?                  dd      r|d    c}n e        Z!e e   ed<   er< ej*                         D  ci c]!  } | d   | d   ej,                  j.                  f# c} ni Z"eeeeej,                  f   f   ed<   er< ej*                         D  ci c]!  } | d   | d   ej,                  j.                  f# c} ni Z#eeeeej,                  f   f   ed<   er< ej*                         D  ci c]!  } | d   | d   ej,                  j.                  f# c} ni Z$eeeeej,                  f   f   ed<   y# e$ r dZ
dZdZdZdZdZdZY w xY wc c} w c c} w c c}w c c} w c c} w c c} w )    )Any)	BaseModelField)SparseVector)models)TextEmbeddingSparseTextEmbeddingImageEmbeddingLateInteractionTextEmbedding"LateInteractionMultimodalEmbedding)OnnxProvider
ImageInputNc                   ~    e Zd ZU eez  ed<   ee   dz  ed<    ed      Z	e
dz  ed<   eeef   ed<   eed<   eed<   y)	QueryResponseidN	embedding)defaultsparse_embeddingmetadatadocumentscore)__name__
__module____qualname__strint__annotations__listfloatr   r   r   dictr        e/volume1/homes/robertsu/coba/app/.venv/lib/python3.12/site-packages/qdrant_client/fastembed_common.pyr   r      sG    c	ME{T!!,1$,?lT)?38nMLr"   r   forbid)extrac                   ~   e Zd ZU dZeed<    e       Zee   ed<    e       Z	ee   ed<    e       Z
ee   ed<    e       Zee   ed<    e       Zee   ed<   edefd	       Zedd       Zedeeeeej(                  f   f   fd       Zedeeeeej(                  f   f   fd       Zedeeeeej(                  f   f   fd       Zedeeeeej(                  f   f   fd       Zedeeeeef   f   fd       Zededefd       Zededefd       Zededefd       Zededefd       Zededefd       Zy
)FastEmbedMiscFIS_INSTALLED_TEXT_MODELS_IMAGE_MODELS_LATE_INTERACTION_TEXT_MODELS#_LATE_INTERACTION_MULTIMODAL_MODELS_SPARSE_MODELSreturnc                    | j                   r| j                   S 	 ddlm}m}m}m}m} t         |j                               dkD  sJ t         |j                               dkD  sJ t         |j                               dkD  sJ t         |j                               dkD  sJ t         |j                               dkD  sJ d| _         | j                   S # t        $ r d| _         Y | j                   S w xY w)Nr   )r	   r   r
   r   r   TF)
r(   	fastembedr	   r   r
   r   r   lenlist_supported_modelsImportError)clsr	   r   r
   r   r   s         r#   is_installedzFastEmbedMisc.is_installed,   s   ###	%  @*@@BCaGGG:}::<=AAA;~;;=>BBBI3IIKLqPPPO9OOQRUVVVV#C   	%$C	%s   B0C C43C4Nc                 2    | j                   ry t        d      )Nzxfastembed is not installed. Please install it to compute embedding for document implicitly with `pip install fastembed`.)r(   r3   )r4   s    r#   import_fastembedzFastEmbedMisc.import_fastembedE   s#     l
 	
r"   c                     t         rCt        j                         D ci c]%  }|d   |d   t        j                  j                  f' c}S i S c c}w )a  Lists the supported dense text models.

        Requires invocation of TextEmbedding.list_supported_models() to support custom models.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        modeldim)r   r2   r   DistanceCOSINEr4   r9   s     r#   list_text_modelszFastEmbedMisc.list_text_modelsP   s]      +@@BBE guv/E/E FFB	
 	
   *Ac                     t         rCt        j                         D ci c]%  }|d   |d   t        j                  j                  f' c}S i S c c}w )at  Lists the supported image dense models.

        Custom image models are not supported yet, but calls to ImageEmbedding.list_supported_models() is done each
        time in order for preserving the same style as with TextEmbedding.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        r9   r:   )r
   r2   r   r;   r<   r=   s     r#   list_image_modelszFastEmbedMisc.list_image_modelsb   s]      ,AACCE guv/E/E FFC	
 	
r?   c                     t         rCt        j                         D ci c]%  }|d   |d   t        j                  j                  f' c}S i S c c}w )a  Lists the supported late interaction text models.

        Custom late interaction models are not supported yet, but calls to
        LateInteractionTextEmbedding.list_supported_models()
        is done each time in order for preserving the same style as with TextEmbedding.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        r9   r:   )r   r2   r   r;   r<   r=   s     r#   !list_late_interaction_text_modelsz/FastEmbedMisc.list_late_interaction_text_modelsu   s]      , :OOQQE guv/E/E FFQ	
 	
r?   c                     t         rCt        j                         D ci c]%  }|d   |d   t        j                  j                  f' c}S i S c c}w )a  Lists the supported late interaction multimodal models.

        Custom late interaction multimodal models are not supported yet, but calls to
        LateInteractionMultimodalEmbedding.list_supported_models()
        is done each time in order for preserving the same style as with TextEmbedding.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        r9   r:   )r   r2   r   r;   r<   r=   s     r#   'list_late_interaction_multimodal_modelsz5FastEmbedMisc.list_late_interaction_multimodal_models   s^      2 @UUWWE guv/E/E FFW	
 	
r?   c                 p    i }t         r-t        j                         D ]  }|||j                  d      <    |S )a`  Lists the supported sparse models.

        Custom sparse models are not supported yet, but calls to
        SparseTextEmbedding.list_supported_models()
        is done each time in order for preserving the same style as with TextEmbedding.

        Returns:
            dict[str, dict[str, Any]]: A dict of model names and their descriptions.
        r9   )r	   r2   pop)r4   descriptionsdescriptions      r#   list_sparse_modelsz FastEmbedMisc.list_sparse_models   s9     2HHJ9D[__W56  Kr"   
model_namec                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w zChecks if the model is supported by fastembed.

        Args:
            model_name (str): The name of the model to check.

        Returns:
            bool: True if the model is supported, False otherwise.
        TF)lowerr)   r>   r4   rK   r9   s      r#   is_supported_text_modelz%FastEmbedMisc.is_supported_text_model   si     !1!117:7K7K7MN7MeEKKM7MN!1!11 O   A-c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rM   )rN   r*   rA   rO   s      r#   is_supported_image_modelz&FastEmbedMisc.is_supported_image_model   si     !2!228;8M8M8OP8OuU[[]8OP!2!22 QrQ   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rM   )rN   r+   rC   rO   s      r#   (is_supported_late_interaction_text_modelz6FastEmbedMisc.is_supported_late_interaction_text_model   sp     !B!BB (+'L'L'N-
'NeEKKM'N-
) !B!BB-
rQ   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rM   )rN   r,   rE   rO   s      r#   .is_supported_late_interaction_multimodal_modelz<FastEmbedMisc.is_supported_late_interaction_multimodal_model   sp     !H!HH (+'R'R'T3
'TeEKKM'T3
/ !H!HH3
rQ   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rM   )rN   r-   rJ   rO   s      r#   is_supported_sparse_modelz'FastEmbedMisc.is_supported_sparse_model   si     !3!339<9O9O9QR9Qekkm9QR!3!33 SrQ   )r.   N) r   r   r   r(   boolr   setr)   r   r*   r+   r,   r-   classmethodr5   r7   r    tupler   r   r;   r>   rA   rC   rE   r   rJ   rP   rS   rU   rW   rY   r!   r"   r#   r'   r'   $   s/   L$ UL#c("!eM3s8#.1e!3s8347E'S9"uNCH$ T    0 
 
 
c5foo1E+F&F!G 
 
" 
$sE#v2F,G'G"H 
 
$ 
$sE#vBV<W7W2X 
 
& 
S%V__H\B]=]8^ 
 
& 4T#s(^(;#<       " # $  " # $  &  PT  & 3 4  r"   r'   r9   r:   SUPPORTED_EMBEDDING_MODELS!SUPPORTED_SPARSE_EMBEDDING_MODELSrequires_idfIDF_EMBEDDING_MODELS"_LATE_INTERACTION_EMBEDDING_MODELS_IMAGE_EMBEDDING_MODELS-_LATE_INTERACTION_MULTIMODAL_EMBEDDING_MODELS)%typingr   pydanticr   r   &qdrant_client.conversions.common_typesr   qdrant_client.httpr   r0   r   r	   r
   r   r   fastembed.commonr   r   r3   r   r'   r2   r;   r<   r^   r    r   r]   r   r   r_   getr[   ra   rb   rc   rd   )r9   model_configs   00r#   <module>rl      s    % ? %  :IX f fb  9]88::E 	guv'='=>>:
 
 DeC,@&A!AB   )R(;(Q(Q(ST(SuU7^U(ST	 "4T#s(^(;#<   F/EEGGLND1 	WG 
 c#h  $ H1GGIIE 	guv'='=>>I
 
 #DeC4H.I)I$J   :^99;;E 	guv'='=>>;
 
 c5foo)=#>>?  * N7MMOOE 	guv'='=>>O
 
 .tCsFOO?S9T4T/U U	  MN#' )-&LJ@ Us5   H* &I8I	.I3&I&I%&I*I I