
    'Xh                        d dl Z d dlmZ d dlmZmZmZmZmZm	Z	 d dl
mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlm 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)m*Z*m+Z+  G d de      Z,y)    N)tee)AnyIterableOptionalSequenceUnionget_args)deepcopy)	BaseModel)grpc)show_warning)
QdrantBase)ModelEmbedder)models)common_types)
GrpcToRest)INFERENCE_OBJECT_TYPES)ModelSchemaParser)reciprocal_rank_fusion)FastEmbedMiscOnnxProvider)QueryResponseTextEmbeddingSparseTextEmbeddingIDF_EMBEDDING_MODELSc                       e Zd ZU dZdZeed<   dede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j                   f   f   fd       Ze
deeeeef   f   fd       Zedefd       Zedee   fd       Z	 	 	 	 	 	 	 dNdedee   dee   dee   deed      dedeee      dededdfdZ	 	 	 	 	 	 dOdee   dee   dee   deed      dedeee      dededdfdZe
dedeeej                   f   fd       Z	 	 	 	 dPdedee   dee   deed      dededdfdZ	 	 	 	 dPdedee   dee   deed      dededd fd!Z ed"d#dfd$e!e   ded%ed&ed'ee   de!eeee"   f      fd(Z#ed"dfd$e!e   ded%ed'ee   de!e$jJ                     f
d)Z&defd*Z'dee   fd+Z(d,ee$jR                     dee*   fd-Z+	 dQd.ee!ejX                        d/ee!eeef         d0e!eeee"   f      d1ed2ee!e$jJ                        de!ejZ                     fd3Z.d4ej^                  ddfd5Z0	 dQdee   defd6Z1	 	 	 dRd7ee   d8eejd                     d9eejf                     deeejh                  f   fd:Z5	 	 dSd7ee   d;eejl                     deeeejn                  f      fd<Z8	 	 	 	 dTd=ed$e!e   d/ee!eeef         d.ee!ejX                        d%ed'ee   dedee9eef      fd>Z:	 	 dUd=ed?ed@eejv                     dAededee*   fdBZ<	 	 dUd=edCee   d@eejv                     dAededeee*      fdDZ=e
dEe9e$j|                  ee"   eee"      e$jJ                  e$j~                  e$j                  ej                  ej                  ej                  df
   deej~                     fdF       ZDdEej                  dej                  fdGZFdHeej                     deej                     fdIZG	 	 dVdJe9eHe!eH   f   dKed%ee   de!eH   fdLZI	 	 dSdJe!e9eeeHf   eHf      d%ee   d'ee   de!eH   fdMZJ xZKS )WQdrantFastembedMixinzBAAI/bge-small-en   _FASTEMBED_INSTALLEDparserkwargsc                     d | _         d | _        t        dd|i|| _        t	        j
                         | j                  _        t        | $  di | y )Nr     )
_embedding_model_name_sparse_embedding_model_namer   _model_embedderr   is_installed	__class__r   super__init__)selfr    r!   r(   s      H/RAG/venv/lib/python3.12/site-packages/qdrant_client/qdrant_fastembed.pyr*   zQdrantFastembedMixin.__init__$   sM    48";?),EFEfE.;.H.H.J+"6"    returnc                 *    t        j                         S )zLists the supported dense text models.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        )r   list_text_modelsclss    r,   r0   z%QdrantFastembedMixin.list_text_models,   s     --//r-   c                 *    t        j                         S )zLists the supported image dense models.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        )r   list_image_modelsr1   s    r,   r4   z&QdrantFastembedMixin.list_image_models5   s     ..00r-   c                 *    t        j                         S )zLists the supported late interaction text models.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        )r   !list_late_interaction_text_modelsr1   s    r,   r6   z6QdrantFastembedMixin.list_late_interaction_text_models>   s     >>@@r-   c                 *    t        j                         S )zLists the supported late interaction multimodal models.

        Returns:
            dict[str, tuple[int, models.Distance]]: A dict of model names, their dimensions and distance metrics.
        )r   'list_late_interaction_multimodal_modelsr1   s    r,   r8   z<QdrantFastembedMixin.list_late_interaction_multimodal_modelsG   s     DDFFr-   c                 *    t        j                         S )zLists the supported sparse text models.

        Returns:
            dict[str, dict[str, Any]]: A dict of model names and their descriptions.
        )r   list_sparse_modelsr1   s    r,   r:   z'QdrantFastembedMixin.list_sparse_modelsP   s     //11r-   c                 T    | j                   | j                  | _         | j                   S N)r$   DEFAULT_EMBEDDING_MODELr+   s    r,   embedding_model_namez)QdrantFastembedMixin.embedding_model_nameY   s(    %%-)-)E)ED&)))r-   c                     | j                   S r<   )r%   r>   s    r,   sparse_embedding_model_namez0QdrantFastembedMixin.sparse_embedding_model_name_   s    000r-   Nr?   
max_length	cache_dirthreads	providersr   cuda
device_ids	lazy_loadc	                 p    |t        dt        d        | j                  d|||||||dd|	 || _        y)a\  
        Set embedding model to use for encoding documents and queries.

        Args:
            embedding_model_name: One of the supported embedding models. See `SUPPORTED_EMBEDDING_MODELS` for details.
            max_length (int, optional): Deprecated. Defaults to None.
            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: The list of onnx providers (with or without options) to use. Defaults to None.
                Example configuration:
                https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options
            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.
        Raises:
            ValueError: If embedding model is not supported.
            ImportError: If fastembed is not installed.

        Returns:
            None
        Nzhmax_length parameter is deprecated and will be removed in the future. It's not used by fastembed models.   )messagecategory
stacklevelT
model_namerC   rD   rE   rF   rG   rH   
deprecatedr#   )r   DeprecationWarning_get_or_init_modelr$   )
r+   r?   rB   rC   rD   rE   rF   rG   rH   r!   s
             r,   	set_modelzQdrantFastembedMixin.set_modelc   sa    N !5+	 	  
	
+!
	
 
	
 &:"r-   c                 L    | | j                   d|||||||dd| || _        y)a  
        Set sparse embedding model to use for hybrid search over documents in combination with dense embeddings.

        Args:
            embedding_model_name: One of the supported sparse embedding models. See `SUPPORTED_SPARSE_EMBEDDING_MODELS` for details.
                        If None, sparse embeddings will not be used.
            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: The list of onnx providers (with or without options) to use. Defaults to None.
                Example configuration:
                https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options
            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.
        Raises:
            ValueError: If embedding model is not supported.
            ImportError: If fastembed is not installed.

        Returns:
            None
        NTrN   r#   )_get_or_init_sparse_modelr%   )	r+   r?   rC   rD   rE   rF   rG   rH   r!   s	            r,   set_sparse_modelz%QdrantFastembedMixin.set_sparse_model   sM    J  +*D** 
/##%#
 
 -A)r-   rO   c                 \   t        j                          t        j                         t        j                         t        j                         t        j
                         fD ]  }|j                  |      x}s|c S  |t        j                         v rt        d      t        d|       )NzFSparse embeddings do not return fixed embedding size and distance typezUnsupported embedding model: )	r   import_fastembedr0   r4   r6   r8   getr:   
ValueError)r2   rO   descriptionsparamss       r,   _get_model_paramsz&QdrantFastembedMixin._get_model_params   s    &&( **,++-;;=AAC	
L &))*55v5
 99;;X  8EFFr-   rP   r   c           	          t        j                           | j                  j                  j                  d|||||d|S N)rO   rC   rD   rE   rP   r#   )r   rX   r&   embedderget_or_init_modelr+   rO   rC   rD   rE   rP   r!   s          r,   rR   z'QdrantFastembedMixin._get_or_init_model   sO     	&&(>t##,,>> 
!!
 
 	
r-   r   c           	          t        j                           | j                  j                  j                  d|||||d|S r_   )r   rX   r&   r`   get_or_init_sparse_modelrb   s          r,   rU   z.QdrantFastembedMixin._get_or_init_sparse_model   sO     	&&(Et##,,EE 
!!
 
 	
r-       default	documents
batch_size
embed_typeparallelc              #   H  K   | j                  |d      t        |d      \  }}|dk(  rj                  |||      }n9|dk(  rfd|D        }n(|dk(  rj                  |||      }nt	        d	|       t        ||      D ]  \  }	}
|
|	j                         f  y w)
NTrO   rP      passagerh   rj   queryc              3   Z   K   | ]"  }t        j                  |             d    $ yw)rp   r   N)listquery_embed).0rp   embedding_models     r,   	<genexpr>z8QdrantFastembedMixin._embed_documents.<locals>.<genexpr>  s-      OZe_00u0=>qA{s   (+rf   zUnknown embed type: )rR   r   passage_embedembedrZ   ziptolist)r+   rg   r?   rh   ri   rj   documents_adocuments_bvectors_itervectordocrv   s              @r,   _embed_documentsz%QdrantFastembedMixin._embed_documents  s      11=Q^b1c#&y!#4 ["*88
X 9 L 7"OZL 9$*00
X 1 L 3J<@AA|[9KFCv}}&& :s   BB"c              #      K   | j                  |d      }|j                  |||      }|D ]K  }t        j                  |j                  j                         |j                  j                                M y w)NTrl   ro   indicesvalues)rU   ry   typesSparseVectorr   r{   r   )r+   rg   r?   rh   rj   sparse_embedding_modelr~   sparse_vectors           r,   _sparse_embed_documentsz,QdrantFastembedMixin._sparse_embed_documents*  s      "&!?!?+ "@ "
 .33*x 4 
 *M$$%--446$++224  *s   A9A;c                 d    | j                   j                  d      d   j                         }d| S )
        Returns name of the vector field in qdrant collection, used by current fastembed model.
        Returns:
            Name of the vector field.
        /zfast-)r?   splitlowerr+   rO   s     r,   get_vector_field_namez*QdrantFastembedMixin.get_vector_field_name?  s5     ..44S9"=CCE
zl##r-   c                 ~    | j                   1| j                   j                  d      d   j                         }d| S y)r   Nr   r   zfast-sparse-)rA   r   r   r   s     r,   get_sparse_vector_field_namez1QdrantFastembedMixin.get_sparse_vector_field_nameH  sD     ++799??DRHNNPJ!*..r-   scored_pointsc                    g }| j                         }| j                         }|D ]  }t        |j                  t              r|j                  j                  |d       nd }d }|8t        |j                  t              r|j                  j                  |d       nd }|j                  t        |j                  |||j                  |j                  j                  dd      |j                                |S )Ndocument )id	embeddingsparse_embeddingmetadatar   score)r   r   
isinstancer   dictrY   appendr   r   payloadr   )r+   r   responsevector_field_namesparse_vector_field_namescored_pointr   r   s           r,   !_scored_points_to_query_responsesz6QdrantFastembedMixin._scored_points_to_query_responsesS  s      668#'#D#D#F )L l1148 ##''(94@ 
  $'3 ","5"5t< !''++,DdK ! OO#'%5)11)1155j"E&,,	 *0 r-   idsr   encoded_docsids_accumulatorsparse_vectorsc              #   X  K   |t        d d       }|t        d d       }|t        d d      }| j                         }| j                         }t        ||||      D ]H  \  }}	\  }
}}|j	                  |       d|
i|	}||i}|||||<   t        j                  |||       J y w)Nc                  >    t        j                         j                  S r<   )uuiduuid4hexr#   r-   r,   <lambda>z7QdrantFastembedMixin._points_iterator.<locals>.<lambda>~  s    tzz|//r-   c                      i S r<   r#   r#   r-   r,   r   z7QdrantFastembedMixin._points_iterator.<locals>.<lambda>  s    Br-   c                       y r<   r#   r#   r-   r,   r   z7QdrantFastembedMixin._points_iterator.<locals>.<lambda>  s    $r-   Tr   )r   r   r   )iterr   r   rz   r   r   PointStruct)r+   r   r   r   r   r   vector_namesparse_vector_nameidxmetar   r   r   r   point_vectors                  r,   _points_iteratorz%QdrantFastembedMixin._points_iteratoru  s      ;/6CJ-H!!,5N002!>>@7:<8
3C}Vm ""3'!3/$/G6A65JL!--2K3@/0$$W\RR8
s   B(B*collection_infoc                 &   | j                  | j                        \  }}| j                         }t        |j                  j
                  j                  t              s(J d|j                  j
                  j                          ||j                  j
                  j                  v s+J d|j                  j
                  j                   d|        |j                  j
                  j                  |   }||j                  k(  sJ d| d|j                          ||j                  k(  sJ d| d|j                          | j                         }|||j                  j
                  j                  v s(J d|j                  j
                  j                          | j                  t        v ra|j                  j
                  j                  |   j                  }|t        j                   j"                  k(  sJ | j                   d|        y y y )NrO   z,Collection have incompatible vector params: z, expected zEmbedding size mismatch: z != zDistance mismatch: z, requires modifier IDF, current modifier is )r]   r?   r   r   configr\   vectorsr   sizedistancer   r   rA   r   modifierr   ModifierIDF)r+   r   embeddings_sizer   r   vector_paramsr   r   s           r,   _validate_collection_infoz.QdrantFastembedMixin._validate_collection_info  s4   $($:$:dF_F_$:$`! 668 ""))114
 	b9/:P:P:W:W:_:_9`a	b 

 !7!7!>!>!F!FF	@9/:P:P:W:W:_:_9``kl}k~	@F (..55==>OP }111	Q&&7tM<N<N;OP	Q1 ...	H 
$}/E/E.FG	H. $(#D#D#F #/(O,B,B,I,I,X,XXf=o>T>T>[>[>c>c=defX//3GG*1188GG,(   3 33o6677cdlcmno3 H	 0r-   c                 P    |xs | j                   }| j                  |      \  }}|S )a  Get the size of the embeddings produced by the specified model.

        Args:
            model_name: optional, the name of the model to get the embedding size for. If None, the default model will
                be used.

        Returns:
            int: the size of the embeddings produced by the model.

        Raises:
            ValueError: If sparse model name is passed or model is not found in the supported models.
        r   )r?   r]   )r+   rO   r   _s       r,   get_embedding_sizez'QdrantFastembedMixin.get_embedding_size  s2       <4#<#<
!33z3Jr-   on_diskquantization_confighnsw_configc                     | j                         }| j                  | j                        \  }}|t        j                  |||||      iS )a  
        Generates vector configuration, compatible with fastembed models.

        Args:
            on_disk: if True, vectors will be stored on disk. If None, default value will be used.
            quantization_config: Quantization configuration. If None, quantization will be disabled.
            hnsw_config: HNSW configuration. If None, default configuration will be used.

        Returns:
            Configuration for `vectors_config` argument in `create_collection` method.
        r   )r   r   r   r   r   )r   r]   r?   r   VectorParams)r+   r   r   r   r   r   r   s          r,   get_fastembed_vector_paramsz0QdrantFastembedMixin.get_fastembed_vector_params  sZ    " !668$($:$:dF_F_$:$`!v22$!$7' 
 	
r-   r   c                     | j                         }| j                  t        v r|t        j                  j
                  n|}|y|t        j                  t        j                  |      |      iS )a  
        Generates vector configuration, compatible with fastembed sparse models.

        Args:
            on_disk: if True, vectors will be stored on disk. If None, default value will be used.
            modifier: Sparse vector queries modifier. E.g. Modifier.IDF for idf-based rescoring. Default: None.
        Returns:
            Configuration for `vectors_config` argument in `create_collection` method.
        N)r   )indexr   )r   rA   r   r   r   r   SparseVectorParamsSparseIndexParams)r+   r   r   r   s       r,   "get_fastembed_sparse_vector_paramsz7QdrantFastembedMixin.get_fastembed_sparse_vector_params  ss     !==?++/CC.6.>v**HH$ v88..# "	 
 	
r-   collection_namec           	         | j                  || j                  |d|      }d}	| j                  | j                  || j                  ||      }		 | j	                  |      }
| j                  |
       g }| j                  |||||	      } | j                  d||d|xs d	|d
| |S # t
        $ rE | j                  || j                         | j                                | j	                  |      }
Y w xY w)a  
        Adds text documents into qdrant collection.
        If collection does not exist, it will be created with default parameters.
        Metadata in combination with documents will be added as payload.
        Documents will be embedded using the specified embedding model.

        If you want to use your own vectors, use `upsert` method instead.

        Args:
            collection_name (str):
                Name of the collection to add documents to.
            documents (Iterable[str]):
                List of documents to embed and add to the collection.
            metadata (Iterable[dict[str, Any]], optional):
                List of metadata dicts. Defaults to None.
            ids (Iterable[models.ExtendedPointId], optional):
                List of ids to assign to documents.
                If not specified, UUIDs will be generated. Defaults to None.
            batch_size (int, optional):
                How many documents to embed and upload in single request. Defaults to 32.
            parallel (Optional[int], optional):
                How many parallel workers to use for embedding. Defaults to None.
                If number is specified, data-parallel process will be used.

        Raises:
            ImportError: If fastembed is not installed.

        Returns:
            List of IDs of added documents. If no ids provided, UUIDs will be randomly generated on client side.

        rn   )rg   r?   rh   ri   rj   N)rg   r?   rh   rj   )r   )r   vectors_configsparse_vectors_config)r   r   r   r   r   T   )r   pointswaitrj   rh   r#   )r   r?   rA   r   get_collection	Exceptioncreate_collectionr   r   r   r   upload_points)r+   r   rg   r   r   rh   rj   r!   r   encoded_sparse_docsr   inserted_idsr   s                r,   addzQdrantFastembedMixin.add  sO   V ,,!%!:!:!  - 
 #++7"&">">#%)%E%E%!	 #? #	S"11/1RO 	&&7&&%(. ' 
 	 	
+]!	
 	
 ;  	S"" /#??A&*&M&M&O # 
 #11/1RO	Ss   B( (AC65C6
query_textquery_filterlimitc                    | j                  | j                  d      }t        |j                  |            }|d   j	                         }| j
                  J| j                   | j                  d|t        j                  | j                         |      ||dd|      S | j                  | j
                  d      }	t        |	j                  |            d   }
t        j                  |
j                  j	                         |
j                  j	                               }t        j                  dt        j                  | j                         |      ||dd|}t        j                  dt        j                   | j#                         |      ||dd|}| j%                  |||g	      \  }}| j                  t'        ||g|
            S )aO  
        Search for documents in a collection.
        This method automatically embeds the query text using the specified embedding model.
        If you want to use your own query vector, use `search` method instead.

        Args:
            collection_name: Collection to search in
            query_text:
                Text to search for. This text will be embedded using the specified embedding model.
                And then used as a query vector.
            query_filter:
                - Exclude vectors which doesn't fit given conditions.
                - If `None` - search among all vectors
            limit: How many results return
            **kwargs: Additional search parameters. See `qdrant_client.models.SearchRequest` for details.

        Returns:
            list[types.ScoredPoint]: List of scored points.

        Trl   rr   r   namer   )r   query_vectorr   r   with_payloadr   r   filterr   r   r   requestsr   r#   )rR   r?   rs   rt   r{   rA   r   searchr   NamedVectorr   rU   r   r   r   SearchRequestNamedSparseVectorr   search_batchr   )r+   r   r   r   r   r!   embedding_model_inst
embeddingsr   sparse_embedding_model_instr   sparse_query_vectordense_requestsparse_requestdense_request_responsesparse_request_responses                   r,   rp   zQdrantFastembedMixin.queryd  s   :  $6600T  7  
 .:::LM
!!}++-++399 	$3!'!3!3!779," ".!%	 	  '+&D&D77D 'E '
# 8DD:DVWXYZ$11!))002 ''..0

 ,, 	
%%//1#  	
 	
  -- 	
++668*  	
 	
 ;?:K:K+}n6U ;L ;
7 7 55"$:<S#T\ab
 	
r-   query_textsc           	         | j                  | j                  d      }t        |j                  |            }g }|D ]^  }	t	        j
                  dt	        j                  | j                         |	j                               ||dd|}
|j                  |
       ` | j                  2| j                  ||      }|D cg c]  }| j                  |       c}S | j                  | j                  d      }|j                  |      D cg c]I  }t	        j                  |j                   j                         |j"                  j                         	      K }}|D ]P  }t	        j
                  dt	        j$                  | j'                         |      ||dd|}
|j                  |
       R | j                  ||      }|dt)        |       }|t)        |      d }t+        ||      D cg c]  \  }}t-        ||g|
       }}}|D cg c]  }| j                  |       c}S c c}w c c}w c c}}w c c}w )a  
        Search for documents in a collection with batched query.
        This method automatically embeds the query text using the specified embedding model.

        Args:
            collection_name: Collection to search in
            query_texts:
                A list of texts to search for. Each text will be embedded using the specified embedding model.
                And then used as a query vector for a separate search requests.
            query_filter:
                - Exclude vectors which doesn't fit given conditions.
                - If `None` - search among all vectors
                This filter will be applied to all search requests.
            limit: How many results return
            **kwargs: Additional search parameters. See `qdrant_client.models.SearchRequest` for details.

        Returns:
            list[list[QueryResponse]]: List of lists of responses for each query text.

        Trl   rr   r   r   Nr   )rg   r   r   r#   )rR   r?   rs   rt   r   r   r   r   r{   r   rA   r   r   rU   ry   r   r   r   r   r   lenrz   r   )r+   r   r   r   r   r!   r   query_vectorsr   r   request	responsesr   r   r   sparse_query_vectorsdense_responsessparse_responsesdense_responsesparse_responses                       r,   query_batchz QdrantFastembedMixin.query_batch  s   8  $6600T  7  
 1==K=PQ#F** ))335fmmo $! G OOG$ $ ++3)) /! * I V__U^D::8DU^__&*&D&D77D 'E '
# "=!B!B[!B!Y 

 "Z	 %--446$++224 "Z 	  
 2M** 	//::<( $!	 	G OOG$ 2 %%+ & 
	
 $$6c+&67$S%5%78 47HX3Y
3Y/ #NO#DER3Y 	 

 R[[QZX66x@QZ[[M `
 
8

 \s   H+AH00H5H;rp   c                    t        |t        t        j                              st        |t        j                        r|S t        |t        j
                        rt        j                  |      S t        |t        j                        r$t        j                  |j                               S t        |t              rt        j                  |      S t        |t        t        j                              rGt        |t        j                        rt        j                  |      n|}t        j                  |      S t        |t        t                    rt        j                  |      S |yt!        dt#        |             )ac  Resolves query interface into a models.Query object

        Args:
            query: models.QueryInterface - query as a model or a plain structure like list[float]

        Returns:
            Optional[models.Query]: query as it was, models.Query(nearest=query) or None

        Raises:
            ValueError: if query is not of supported type
        )nearestNzUnsupported query type: )r   r	   r   Queryr   r   r   NearestQuerynpndarrayr{   rs   PointIdr   convert_point_idr   rZ   type)r2   rp   s     r,   _resolve_queryz#QdrantFastembedMixin._resolve_query  s   6 eXekk23z%7TLeU//0&&u55eRZZ(&&u||~>>eT"&&u55eXemm456@6U
++E2[`  &&u55eX&<=>&&u55=3DK=ABBr-   c                 \    t        |      }| j                  |j                        |_        |S )zResolve QueryRequest query field

        Args:
            query: models.QueryRequest - query request to resolve

        Returns:
            models.QueryRequest: A deepcopy of the query request with resolved query field
        )r
   r  rp   )r+   rp   s     r,   _resolve_query_requestz+QdrantFastembedMixin._resolve_query_requestI  s(     ))%++6r-   r   c                 J    |D cg c]  }| j                  |       c}S c c}w )a  Resolve query field for each query request in a batch

        Args:
            requests: Sequence[models.QueryRequest] - query requests to resolve

        Returns:
            Sequence[models.QueryRequest]: A list of deep copied query requests with resolved query fields
        )r  )r+   r   rp   s      r,   _resolve_query_batch_requestz1QdrantFastembedMixin._resolve_query_batch_requestV  s)     AIIu++E2IIIs    
raw_modelsis_queryc              #      K   t        j                          | j                  j                  |||xs | j                        E d {    y 7 w)N)r  r  rh   )r   rX   r&   embed_modelsDEFAULT_BATCH_SIZE)r+   r  r  rh   s       r,   _embed_modelsz"QdrantFastembedMixin._embed_modelsc  sK      	&&(''44!!<T%<%< 5 
 	
 	
   AAAAc              #      K   t        j                          | j                  j                  ||xs | j                  |      E d {    y 7 w)N)r  rh   rj   )r   rX   r&   embed_models_strictr  )r+   r  rh   rj   s       r,   _embed_models_strictz)QdrantFastembedMixin._embed_models_strictq  sK      	&&('';;!!<T%<%< < 
 	
 	
r  )NNNNFNF)NNNFNF)NNNFr<   )NNN)NN)NNre   N)N
   )FN)L__name__
__module____qualname__r=   r  bool__annotations__r   r   r*   classmethodr   strtupleintr   Distancer0   r4   r6   r8   r:   propertyr?   r   rA   r   rs   rS   rV   r]   rR   rU   r   floatr   r   r   r   r   r   ScoredPointr   r   ExtendedPointIdr   r   CollectionInfor   r   QuantizationConfigHnswConfigDiffr   r   r   r   r   r   r   Filterrp   r	  r  r  
NumpyArrayDocumentImageInferenceObjectr  QueryRequestr  r  r   r  r!  __classcell__)r(   s   @r,   r   r      s	   1#0 #C # 0c5foo1E+F&F!G 0 0 1$sE#v2F,G'G"H 1 1 A$sE#vBV<W7W2X A A GS%V__H\B]=]8^ G G 24T#s(^(;#< 2 2 *c * *
 1Xc] 1 1 %)#'!%8<*.::!:: SM:: C=	::
 #:: H^45:: :: T#Y':: :: :: 
::~ $(!%8<*.1A&sm1A C=1A #	1A
 H^451A 1A T#Y'1A 1A 1A 
1Af G3 G5foo9M3N G G, $(!%8< 

 C=
 #	

 H^45
 
 
 

. $(!%8< 

 C=
 #	

 H^45
 
 
 

. %<#"&'C=' "' 	'
 ' 3-' 
%T%[()	*'> %<"&C= " 	
 3- 
%$$	%*$s $	hsm 	 E--.  
m	 P BFShv5567S 8DcN34S uS$u+%567	S
 S !%*<*<!=>S 
&$$	%S<"o9N9N "oSW "oL %)SM 
, #'CG7;	
$
 &f&?&?@
 f334	

 
c6&&&	'
> #'.2
$
 6??+
 
$sF5556	7	
D 8<:>"&\\ C=\ 8DcN34	\
 hv5567\ \ 3-\ \ 
eCHo	\D 15T
T
 T
 v}}-	T

 T
 T
 
m	T
t 15Y\Y\ #YY\ v}}-	Y\
 Y\ Y\ 
d=!	"Y\v 1CMMKeKKOOLL""	
1C 
&,,	1C 1CfF,?,? FDWDW J !4!45J	&%%	&J  $(	
)Xi%889
 
 SM	

 
)	
" %)"&	
U4Y#7#BCD
 SM
 3-	

 
)	
r-   r   )-r   	itertoolsr   typingr   r   r   r   r   r	   copyr
   numpyr  pydanticr   qdrant_clientr   $qdrant_client.common.client_warningsr   qdrant_client.client_baser   "qdrant_client.embed.model_embedderr   qdrant_client.httpr   qdrant_client.conversionsr   r   $qdrant_client.conversions.conversionr   qdrant_client.embed.commonr   !qdrant_client.embed.schema_parserr   qdrant_client.hybrid.fusionr   qdrant_client.fastembed_commonr   r   r   r   r   r   r   r#   r-   r,   <module>rK     sS      E E     = 0 < % ; ; = ? > F ]
: ]
r-   