
    'Xh+                        U d dl mZmZ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
j0                  j2                  f# c} ni Zeeeee
j0                  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]  }|jC                  dd      r|d    c}n e"       Z#e"e   ed<   er< ej.                         D  ci c]!  } | d   | d   e
j0                  j2                  f# c} ni Z$eeeee
j0                  f   f   ed<   er< ej.                         D  ci c]!  } | d   | d   e
j0                  j2                  f# c} ni Z%eeeee
j0                  f   f   ed<   er< ej.                         D  ci c]!  } | d   | d   e
j0                  j2                  f# c} ni Z&eeeee
j0                  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OptionalUnion)	BaseModelField)SparseVector)models)TextEmbeddingSparseTextEmbeddingImageEmbeddingLateInteractionTextEmbedding"LateInteractionMultimodalEmbedding)OnnxProvider
ImageInputNc                       e Zd ZU eeef   ed<   eee	      ed<    e
d      Zee   ed<   eeef   ed<   eed<   e	ed<   y)	QueryResponseid	embeddingN)defaultsparse_embeddingmetadatadocumentscore)__name__
__module____qualname__r   strint__annotations__r   listfloatr   r   r   dictr        H/RAG/venv/lib/python3.12/site-packages/qdrant_client/fastembed_common.pyr   r      sL    c3hU$$/4T/Bh|,B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      )Nzjfastembed is not installed. Please install it to enable fast vector indexing with `pip install fastembed`.)r*   r5   )r6   s    r%   import_fastembedzFastEmbedMisc.import_fastembedE   s#     ^
 	
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
   r4   r	   DistanceCOSINEr6   r;   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.
        r;   r<   )r   r4   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	
 	
rA   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.
        r;   r<   )r   r4   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	
 	
rA   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.
        r;   r<   )r   r4   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	
 	
rA   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.
        r;   )r   r4   pop)r6   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@   r6   rM   r;   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 rO   )rP   r,   rC   rQ   s      r%   is_supported_image_modelz&FastEmbedMisc.is_supported_image_model   si     !2!228;8M8M8OP8OuU[[]8OP!2!22 QrS   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rO   )rP   r-   rE   rQ   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-
rS   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rO   )rP   r.   rG   rQ   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
rS   c                     |j                         | j                  v ry| j                         D ch c]  }|j                          c}| _        |j                         | j                  v ryyc c}w rO   )rP   r/   rL   rQ   s      r%   is_supported_sparse_modelz'FastEmbedMisc.is_supported_sparse_model   si     !3!339<9O9O9QR9Qekkm9QR!3!33 SrS   )r0   N) r   r   r   r*   boolr   setr+   r   r,   r-   r.   r/   classmethodr7   r9   r"   tupler   r	   r=   r@   rC   rE   rG   r   rL   rR   rU   rW   rY   r[   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)   r;   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   r   r   pydanticr   r   &qdrant_client.conversions.common_typesr   qdrant_client.httpr	   r2   r
   r   r   r   r   fastembed.commonr   r   r5   r   r)   r4   r=   r>   r`   r"   r   r_   r   r   ra   getr]   rc   rd   re   rf   )r;   model_configs   00r%   <module>rn      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<I2I7&I&I)&I!.II