o
    :ib+                     @   s  U d dl mZ d dlmZmZ d dlmZ d dlmZ zd dl	m
Z
mZmZmZmZ d dlmZmZ W n eyJ   dZ
dZdZdZdZdZdZY nw G dd	 d	ed
dZG dd dZe
rgdd e
 D ni Zeeeeejf f ed< erdd e D ni Zeeeeef f ed< erdd e D ne Zee ed< erdd e D ni Z eeeeejf f ed< erdd e D ni Z!eeeeejf f ed< erdd e D ni Z"eeeeejf f ed< dS )    )Any)	BaseModelField)SparseVector)models)TextEmbeddingSparseTextEmbeddingImageEmbeddingLateInteractionTextEmbedding"LateInteractionMultimodalEmbedding)OnnxProvider
ImageInputNc                   @   s`   e Zd ZU eeB ed< ee dB ed< eddZ	e
dB ed< eeef ed< eed< eed< dS )	QueryResponseidN	embedding)defaultsparse_embeddingmetadatadocumentscore)__name__
__module____qualname__strint__annotations__listfloatr   r   r   dictr    r   r   k/home/aiteam/pcaa-dev/dashboard-backend/venv/lib/python3.10/site-packages/qdrant_client/fastembed_common.pyr      s   
 r   forbid)extrac                   @   s  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	d
Zed#ddZedeeeeejf f fddZedeeeeejf f fddZedeeeeejf f fddZedeeeeejf f fddZedeeeeef f fddZededefddZededefddZededefddZededefdd Zededefd!d"ZdS )$FastEmbedMiscFIS_INSTALLED_TEXT_MODELS_IMAGE_MODELS_LATE_INTERACTION_TEXT_MODELS#_LATE_INTERACTION_MULTIMODAL_MODELS_SPARSE_MODELSreturnc                 C   s   | j r| j S zGddlm}m}m}m}m} t| dksJ t| dks)J t| dks3J t| dks=J t| dksGJ d| _ W | j S  t	y[   d| _ Y | j S w )Nr   )r   r   r	   r   r
   TF)
r$   	fastembedr   r   r	   r   r
   lenlist_supported_modelsImportError)clsr   r   r	   r   r
   r   r   r    is_installed,   s   zFastEmbedMisc.is_installedNc                 C   s   | j rd S td)Nzjfastembed is not installed. Please install it to enable fast vector indexing with `pip install fastembed`.)r$   r.   r/   r   r   r    import_fastembedE   s
   zFastEmbedMisc.import_fastembedc                 C      t rdd t  D S i S )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.
        c                 S   "   i | ]}|d  |d t jjfqS modeldimr   DistanceCOSINE.0r6   r   r   r    
<dictcomp>Z       z2FastEmbedMisc.list_text_models.<locals>.<dictcomp>)r   r-   r1   r   r   r    list_text_modelsP   s   zFastEmbedMisc.list_text_modelsc                 C   r3   )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.
        c                 S   r4   r5   r8   r;   r   r   r    r=   m   r>   z3FastEmbedMisc.list_image_models.<locals>.<dictcomp>)r	   r-   r1   r   r   r    list_image_modelsb   s   zFastEmbedMisc.list_image_modelsc                 C   r3   )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.
        c                 S   r4   r5   r8   r;   r   r   r    r=      r>   zCFastEmbedMisc.list_late_interaction_text_models.<locals>.<dictcomp>)r
   r-   r1   r   r   r    !list_late_interaction_text_modelsu      z/FastEmbedMisc.list_late_interaction_text_modelsc                 C   r3   )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.
        c                 S   r4   r5   r8   r;   r   r   r    r=      r>   zIFastEmbedMisc.list_late_interaction_multimodal_models.<locals>.<dictcomp>)r   r-   r1   r   r   r    'list_late_interaction_multimodal_models   rB   z5FastEmbedMisc.list_late_interaction_multimodal_modelsc                 C   s(   i }t rt  D ]	}|||d< q|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.
        r6   )r   r-   pop)r/   descriptionsdescriptionr   r   r    list_sparse_models   s
   z FastEmbedMisc.list_sparse_models
model_namec                 C   <   |  | jv r	dS dd |  D | _|  | jv rdS dS )Checks 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.
        Tc                 S      h | ]}|  qS r   lowerr;   r   r   r    	<setcomp>       z8FastEmbedMisc.is_supported_text_model.<locals>.<setcomp>F)rM   r%   r?   r/   rH   r   r   r    is_supported_text_model      
z%FastEmbedMisc.is_supported_text_modelc                 C   rI   )rJ   Tc                 S   rK   r   rL   r;   r   r   r    rN      rO   z9FastEmbedMisc.is_supported_image_model.<locals>.<setcomp>F)rM   r&   r@   rP   r   r   r    is_supported_image_model   rR   z&FastEmbedMisc.is_supported_image_modelc                 C   rI   )rJ   Tc                 S   rK   r   rL   r;   r   r   r    rN          zIFastEmbedMisc.is_supported_late_interaction_text_model.<locals>.<setcomp>F)rM   r'   rA   rP   r   r   r    (is_supported_late_interaction_text_model      
z6FastEmbedMisc.is_supported_late_interaction_text_modelc                 C   rI   )rJ   Tc                 S   rK   r   rL   r;   r   r   r    rN      rT   zOFastEmbedMisc.is_supported_late_interaction_multimodal_model.<locals>.<setcomp>F)rM   r(   rC   rP   r   r   r    .is_supported_late_interaction_multimodal_model   rV   z<FastEmbedMisc.is_supported_late_interaction_multimodal_modelc                 C   rI   )rJ   Tc                 S   rK   r   rL   r;   r   r   r    rN     rO   z:FastEmbedMisc.is_supported_sparse_model.<locals>.<setcomp>F)rM   r)   rG   rP   r   r   r    is_supported_sparse_model   rR   z'FastEmbedMisc.is_supported_sparse_model)r*   N) r   r   r   r$   boolr   setr%   r   r&   r'   r(   r)   classmethodr0   r2   r   tupler   r   r9   r?   r@   rA   rC   r   rG   rQ   rS   rU   rW   rX   r   r   r   r    r#   $   s>   
 
"""" r#   c                 C   r4   r5   r8   r;   r   r   r    r=     r>   r=   SUPPORTED_EMBEDDING_MODELSc                 C   s   i | ]}|d  |qS )r6   r   r;   r   r   r    r=     s    !SUPPORTED_SPARSE_EMBEDDING_MODELSc                 C   s    h | ]}| d dr|d qS )requires_idfNr6   )get)r<   model_configr   r   r    rN      s    
rN   IDF_EMBEDDING_MODELSc                 C   r4   r5   r8   r;   r   r   r    r=   *  r>   "_LATE_INTERACTION_EMBEDDING_MODELSc                 C   r4   r5   r8   r;   r   r   r    r=   3  r>   _IMAGE_EMBEDDING_MODELSc                 C   r4   r5   r8   r;   r   r   r    r=   <  r>   -_LATE_INTERACTION_MULTIMODAL_EMBEDDING_MODELS)#typingr   pydanticr   r   &qdrant_client.conversions.common_typesr   qdrant_client.httpr   r+   r   r   r	   r
   r   fastembed.commonr   r   r.   r   r#   r-   r]   r   r   r\   r   r9   r   r^   rZ   rb   rc   rd   re   r   r   r   r    <module>   sj    
	 r 