
    'Xh                     f   d dl mZmZmZmZmZmZ d dlmZ d dl	mZ d dl
mZ d dl d dlmZ  ej                   d      Z edd	      Zeeeef      Zeeeef   ef   Zd
ZdedededefdZ	 	 	 	 	 	 ddedeeef   dedededefdZerd dlmZ  G d d      Z G d de      Z G d de      Zy
)    )TYPE_CHECKINGAnyDictSetTypeVarUnion)	BaseModel)VERSION)*)modelsz2.Modelr	   )boundNmodelargskwargsreturnc                 V    t         r | j                  |i |S  | j                  |i |S N)PYDANTIC_V2model_dump_jsonjson)r   r   r   s      K/RAG/venv/lib/python3.12/site-packages/qdrant_client/http/api/search_api.pyto_jsonr      s3    $u$$d5f55uzz4*6**    objincludeby_aliasskip_defaultsexclude_unsetexclude_nonec           
      r    t        | d      st        | d      rt        | |||t        |xs |      |      S | S )Nr   r   )r   excluder   r   r    )hasattrr   bool)r   r   r"   r   r   r   r    s          r   jsonable_encoderr%      sH     sFws,=>}=>%
 	
 Jr   )	ApiClientc            	          e Zd ZddZ	 	 	 d dedej                  dedej                  fdZ		 	 	 d dedej                  dedej                  fd	Z	 	 	 d dedej                  ded
ej                  fdZ	 	 	 d dedej                  dedej                  fdZ	 	 	 d dedej                  dedej                   fdZ	 	 	 d dedej                  dedej$                  fdZ	 	 	 d dedej                  dedej(                  fdZ	 	 	 d dedej                  dedej,                  fdZ	 	 	 d dedej                  dedej0                  fdZ	 	 	 d dedej                  dedej4                  fdZ	 	 	 d dedej                  dedej4                  fdZ	 	 	 d dedej                  dedej:                  fdZ	 	 	 d dedej                  dedej>                  fdZ y)!
_SearchApic                     || _         y r   )
api_client)selfr*   s     r   __init__z_SearchApi.__init__4   s	    $r   Ncollection_nameconsistencytimeoutdiscover_request_batchc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
g
        Look for points based on target and/or positive and negative example pairs, in batch.
        r-   Nr.   r/   Content-Typeapplication/jsonPOSTz4/collections/{collection_name}/points/discover/batchtype_methodurlheaderspath_paramsparamscontentstrr%   r*   requestmInlineResponse20018)	r+   r-   r.   r/   r0   r;   query_paramsr:   bodys	            r    _build_for_discover_batch_pointsz+_SearchApi._build_for_discover_batch_points7   s     s?3
 "*-k*:L'&)'lL# 67(&8GN#&&''F&GD# ' 
 	
r   discover_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
  
        Use context and a target to find the most similar points to the target, constrained by the context. When using only the context (without a target), a special search - called context search - is performed where pairs of points are used to generate a loss that guides the search towards the zone where most positive examples overlap. This means that the score minimizes the scenario of finding a point closer to a negative than to a positive part of a pair. Since the score of a context relates to loss, the maximum score a point can get is 0.0, and it becomes normal that many points can have a score of 0.0. When using target (with or without context), the score behaves a little different: The  integer part of the score represents the rank with respect to the context, while the decimal part of the score relates to the distance to the target. The context part of the score for  each pair is calculated +1 if the point is closer to a positive than to a negative part of a pair,  and -1 otherwise.
        r-   Nr.   r/   r3   r4   r5   z./collections/{collection_name}/points/discoverr6   r?   r%   r*   r@   rA   InlineResponse20017)	r+   r-   r.   r/   rF   r;   rC   r:   rD   s	            r   _build_for_discover_pointsz%_SearchApi._build_for_discover_pointsY   s     s?3
 "*-k*:L'&)'lL# 01(&8GN#&&''@&GD# ' 
 	
r   query_request_batchc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )

        Universally query points in batch. This endpoint covers all capabilities of search, recommend, discover, filters. But also enables hybrid and multi-stage queries.
        r-   Nr.   r/   r3   r4   r5   z1/collections/{collection_name}/points/query/batchr6   )r?   r%   r*   r@   rA   InlineResponse20023)	r+   r-   r.   r/   rL   r;   rC   r:   rD   s	            r   _build_for_query_batch_pointsz(_SearchApi._build_for_query_batch_points{   s     s?3
 "*-k*:L'&)'lL# 34(&8GN#&&''C&GD# ' 
 	
r   query_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )

        Universally query points. This endpoint covers all capabilities of search, recommend, discover, filters. But also enables hybrid and multi-stage queries.
        r-   Nr.   r/   r3   r4   r5   z+/collections/{collection_name}/points/queryr6   )r?   r%   r*   r@   rA   InlineResponse20022)	r+   r-   r.   r/   rQ   r;   rC   r:   rD   s	            r   _build_for_query_pointsz"_SearchApi._build_for_query_points   s     s?3
 "*-k*:L'&)'lL#.(&8GN#&&''=&GD# ' 
 	
r   query_groups_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
L
        Universally query points, grouped by a given payload field
        r-   Nr.   r/   r3   r4   r5   z2/collections/{collection_name}/points/query/groupsr6   r?   r%   r*   r@   rA   InlineResponse20019)	r+   r-   r.   r/   rV   r;   rC   r:   rD   s	            r   _build_for_query_points_groupsz)_SearchApi._build_for_query_points_groups        s?3
 "*-k*:L'&)'lL# 45(&8GN#&&''D&GD# ' 
 	
r   recommend_request_batchc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )

        Look for the points which are closer to stored positive examples and at the same time further to negative examples.
        r-   Nr.   r/   r3   r4   r5   z5/collections/{collection_name}/points/recommend/batchr6   r>   )	r+   r-   r.   r/   r]   r;   rC   r:   rD   s	            r   !_build_for_recommend_batch_pointsz,_SearchApi._build_for_recommend_batch_points   s     s?3
 "*-k*:L'&)'lL# 78(&8GN#&&''G&GD# ' 
 	
r   recommend_groups_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )

        Look for the points which are closer to stored positive examples and at the same time further to negative examples, grouped by a given payload field.
        r-   Nr.   r/   r3   r4   r5   z6/collections/{collection_name}/points/recommend/groupsr6   rY   )	r+   r-   r.   r/   ra   r;   rC   r:   rD   s	            r   !_build_for_recommend_point_groupsz,_SearchApi._build_for_recommend_point_groups  s     s?3
 "*-k*:L'&)'lL# 89(&8GN#&&''H&GD# ' 
 	
r   recommend_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
r_   r-   Nr.   r/   r3   r4   r5   z//collections/{collection_name}/points/recommendr6   rI   )	r+   r-   r.   r/   re   r;   rC   r:   rD   s	            r   _build_for_recommend_pointsz&_SearchApi._build_for_recommend_points%  s     s?3
 "*-k*:L'&)'lL# 12(&8GN#&&''A&GD# ' 
 	
r   search_request_batchc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
p
        Retrieve by batch the closest points based on vector similarity and given filtering conditions
        r-   Nr.   r/   r3   r4   r5   z2/collections/{collection_name}/points/search/batchr6   r>   )	r+   r-   r.   r/   rh   r;   rC   r:   rD   s	            r   _build_for_search_batch_pointsz)_SearchApi._build_for_search_batch_pointsG  r\   r   search_matrix_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
_
        Compute distance matrix for sampled points with an offset based output format
        r-   Nr.   r/   r3   r4   r5   z;/collections/{collection_name}/points/search/matrix/offsetsr6   )r?   r%   r*   r@   rA   InlineResponse20025	r+   r-   r.   r/   rl   r;   rC   r:   rD   s	            r    _build_for_search_matrix_offsetsz+_SearchApi._build_for_search_matrix_offsetsi  s     s?3
 "*-k*:L'&)'lL# 56(&8GN#&&''M&GD# ' 
 	
r   c           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
\
        Compute distance matrix for sampled points with a pair based output format
        r-   Nr.   r/   r3   r4   r5   z9/collections/{collection_name}/points/search/matrix/pairsr6   )r?   r%   r*   r@   rA   InlineResponse20024rp   s	            r   _build_for_search_matrix_pairsz)_SearchApi._build_for_search_matrix_pairs  s     s?3
 "*-k*:L'&)'lL# 56(&8GN#&&''K&GD# ' 
 	
r   search_groups_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )

        Retrieve closest points based on vector similarity and given filtering conditions, grouped by a given payload field
        r-   Nr.   r/   r3   r4   r5   z3/collections/{collection_name}/points/search/groupsr6   rY   )	r+   r-   r.   r/   rv   r;   rC   r:   rD   s	            r   _build_for_search_point_groupsz)_SearchApi._build_for_search_point_groups  s     s?3
 "*-k*:L'&)'lL# 56(&8GN#&&''E&GD# ' 
 	
r   search_requestc           	          dt        |      i}i }|t        |      |d<   |t        |      |d<   i }t        |      }d|vrd|d<   | j                  j                  t        j
                  dd|r|nd|||	      S )
c
        Retrieve closest points based on vector similarity and given filtering conditions
        r-   Nr.   r/   r3   r4   r5   z,/collections/{collection_name}/points/searchr6   rI   )	r+   r-   r.   r/   rz   r;   rC   r:   rD   s	            r   _build_for_search_pointsz#_SearchApi._build_for_search_points  s     s?3
 "*-k*:L'&)'lL#/(&8GN#&&''>&GD# ' 
 	
r   )r*   z Union[ApiClient, AsyncApiClient]NNN)!__name__
__module____qualname__r,   r?   rA   ReadConsistencyintDiscoverRequestBatchrE   DiscoverRequestrK   QueryRequestBatchrP   QueryRequestrU   QueryGroupsRequestr[   RecommendRequestBatchr`   RecommendGroupsRequestrd   RecommendRequestrg   SearchRequestBatchrk   SearchMatrixRequestrq   ru   SearchGroupsRequestry   SearchRequestr}    r   r   r(   r(   3   si   % *.9= 
 
 && 
 	 

 !" 6 6 
J *..2 
 
 && 
 	 

 ++ 
J *.37 
 
 && 
 	 

 00 
J *.(, 
 
 && 
 	 

 ~~ 
J *.59 
 
 && 
 	 

  22 
J *.;? 
 
 && 
 	 

 "#!8!8 
J *.=A 
 
 && 
 	 

 #$":": 
J *.04 
 
 && 
 	 

 -- 
J *.59 
 
 && 
 	 

  22 
J *.7; 
 
 && 
 	 

  !44 
J *.7; 
 
 && 
 	 

  !44 
J *.7; 
 
 && 
 	 

  !44 
J *.*. 
 
 && 
 	 

  
r   r(   c                      e Zd Z	 	 	 ddedej
                  dedej                  dej                  f
dZ		 	 	 ddedej
                  dedej                  dej                  f
d	Z	 	 	 ddedej
                  ded
ej                  dej                  f
dZ	 	 	 ddedej
                  dedej                   dej"                  f
dZ	 	 	 ddedej
                  dedej&                  dej(                  f
dZ	 	 	 ddedej
                  dedej,                  dej                  f
dZ	 	 	 ddedej
                  dedej0                  dej(                  f
dZ	 	 	 ddedej
                  dedej4                  dej                  f
dZ	 	 	 ddedej
                  dedej8                  dej                  f
dZ	 	 	 ddedej
                  dedej<                  dej>                  f
dZ 	 	 	 ddedej
                  dedej<                  dejB                  f
dZ"	 	 	 ddedej
                  dedejF                  dej(                  f
dZ$	 	 	 ddedej
                  dedejJ                  dej                  f
dZ&y) AsyncSearchApiNr-   r.   r/   r0   r   c                 H   K   | j                  ||||       d{   S 7 w)r2   r-   r.   r/   r0   NrE   r+   r-   r.   r/   r0   s        r   discover_batch_pointsz$AsyncSearchApi.discover_batch_points  s6      ::+##9	 ; 
 
 	
 
   " "rF   c                 H   K   | j                  ||||       d{   S 7 w)rH   r-   r.   r/   rF   NrK   r+   r-   r.   r/   rF   s        r   discover_pointszAsyncSearchApi.discover_points  s6      44+#-	 5 
 
 	
 
r   rL   c                 H   K   | j                  ||||       d{   S 7 w)rN   r-   r.   r/   rL   NrP   r+   r-   r.   r/   rL   s        r   query_batch_pointsz!AsyncSearchApi.query_batch_points  s6      77+# 3	 8 
 
 	
 
r   rQ   c                 H   K   | j                  ||||       d{   S 7 w)rS   r-   r.   r/   rQ   NrU   r+   r-   r.   r/   rQ   s        r   query_pointszAsyncSearchApi.query_points&  s6      11+#'	 2 
 
 	
 
r   rV   c                 H   K   | j                  ||||       d{   S 7 w)rX   r-   r.   r/   rV   Nr[   r+   r-   r.   r/   rV   s        r   query_points_groupsz"AsyncSearchApi.query_points_groups7  6      88+#!5	 9 
 
 	
 
r   r]   c                 H   K   | j                  ||||       d{   S 7 w)r_   r-   r.   r/   r]   Nr`   r+   r-   r.   r/   r]   s        r   recommend_batch_pointsz%AsyncSearchApi.recommend_batch_pointsH  s6      ;;+#$;	 < 
 
 	
 
r   ra   c                 H   K   | j                  ||||       d{   S 7 w)rc   r-   r.   r/   ra   Nrd   r+   r-   r.   r/   ra   s        r   recommend_point_groupsz%AsyncSearchApi.recommend_point_groupsY  s6      ;;+#%=	 < 
 
 	
 
r   re   c                 H   K   | j                  ||||       d{   S 7 w)r_   r-   r.   r/   re   Nrg   r+   r-   r.   r/   re   s        r   recommend_pointszAsyncSearchApi.recommend_pointsj  s6      55+#/	 6 
 
 	
 
r   rh   c                 H   K   | j                  ||||       d{   S 7 w)rj   r-   r.   r/   rh   Nrk   r+   r-   r.   r/   rh   s        r   search_batch_pointsz"AsyncSearchApi.search_batch_points{  r   r   rl   c                 H   K   | j                  ||||       d{   S 7 w)rn   r-   r.   r/   rl   Nrq   r+   r-   r.   r/   rl   s        r   search_matrix_offsetsz$AsyncSearchApi.search_matrix_offsets  s6      ::+#"7	 ; 
 
 	
 
r   c                 H   K   | j                  ||||       d{   S 7 w)rs   r   Nru   r   s        r   search_matrix_pairsz"AsyncSearchApi.search_matrix_pairs  6      88+#"7	 9 
 
 	
 
r   rv   c                 H   K   | j                  ||||       d{   S 7 w)rx   r-   r.   r/   rv   Nry   r+   r-   r.   r/   rv   s        r   search_point_groupsz"AsyncSearchApi.search_point_groups  r   r   rz   c                 H   K   | j                  ||||       d{   S 7 w)r|   r-   r.   r/   rz   Nr}   r+   r-   r.   r/   rz   s        r   search_pointszAsyncSearchApi.search_points  s6      22+#)	 3 
 
 	
 
r   r~   'r   r   r   r?   rA   r   r   r   rB   r   r   rJ   r   r   rO   r   r   rT   r   r   rZ   r   r   r   r   r   r   r   r   r   r   ro   r   rt   r   r   r   r   r   r   r   r   r   r     (    *.9=

 &&
 	

 !" 6 6
 
		
( *..2

 &&
 	

 ++
 
		
( *.37

 &&
 	

 00
 
		
( *.(,

 &&
 	

 ~~
 
		
( *.59

 &&
 	

  22
 
		
( *.;?

 &&
 	

 "#!8!8
 
		
( *.=A

 &&
 	

 #$":":
 
		
( *.04

 &&
 	

 --
 
		
( *.59

 &&
 	

  22
 
		
( *.7;

 &&
 	

  !44
 
		
( *.7;

 &&
 	

  !44
 
		
( *.7;

 &&
 	

  !44
 
		
( *.*.

 &&
 	

 
 
		
r   r   c                      e Zd Z	 	 	 ddedej
                  dedej                  dej                  f
dZ		 	 	 ddedej
                  dedej                  dej                  f
d	Z	 	 	 ddedej
                  ded
ej                  dej                  f
dZ	 	 	 ddedej
                  dedej                   dej"                  f
dZ	 	 	 ddedej
                  dedej&                  dej(                  f
dZ	 	 	 ddedej
                  dedej,                  dej                  f
dZ	 	 	 ddedej
                  dedej0                  dej(                  f
dZ	 	 	 ddedej
                  dedej4                  dej                  f
dZ	 	 	 ddedej
                  dedej8                  dej                  f
dZ	 	 	 ddedej
                  dedej<                  dej>                  f
dZ 	 	 	 ddedej
                  dedej<                  dejB                  f
dZ"	 	 	 ddedej
                  dedejF                  dej(                  f
dZ$	 	 	 ddedej
                  dedejJ                  dej                  f
dZ&y) SyncSearchApiNr-   r.   r/   r0   r   c                 ,    | j                  ||||      S )r2   r   r   r   s        r   r   z#SyncSearchApi.discover_batch_points  s(     44+##9	 5 
 	
r   rF   c                 ,    | j                  ||||      S )rH   r   r   r   s        r   r   zSyncSearchApi.discover_points  s(     ..+#-	 / 
 	
r   rL   c                 ,    | j                  ||||      S )rN   r   r   r   s        r   r   z SyncSearchApi.query_batch_points  s(     11+# 3	 2 
 	
r   rQ   c                 ,    | j                  ||||      S )rS   r   r   r   s        r   r   zSyncSearchApi.query_points  s(     +++#'	 , 
 	
r   rV   c                 ,    | j                  ||||      S )rX   r   r   r   s        r   r   z!SyncSearchApi.query_points_groups  (     22+#!5	 3 
 	
r   r]   c                 ,    | j                  ||||      S )r_   r   r   r   s        r   r   z$SyncSearchApi.recommend_batch_points'  s(     55+#$;	 6 
 	
r   ra   c                 ,    | j                  ||||      S )rc   r   r   r   s        r   r   z$SyncSearchApi.recommend_point_groups8  s(     55+#%=	 6 
 	
r   re   c                 ,    | j                  ||||      S )r_   r   r   r   s        r   r   zSyncSearchApi.recommend_pointsI  s(     //+#/	 0 
 	
r   rh   c                 ,    | j                  ||||      S )rj   r   r   r   s        r   r   z!SyncSearchApi.search_batch_pointsZ  r   r   rl   c                 ,    | j                  ||||      S )rn   r   r   r   s        r   r   z#SyncSearchApi.search_matrix_offsetsk  s(     44+#"7	 5 
 	
r   c                 ,    | j                  ||||      S )rs   r   r   r   s        r   r   z!SyncSearchApi.search_matrix_pairs|  (     22+#"7	 3 
 	
r   rv   c                 ,    | j                  ||||      S )rx   r   r   r   s        r   r   z!SyncSearchApi.search_point_groups  r   r   rz   c                 ,    | j                  ||||      S )r|   r   r   r   s        r   r   zSyncSearchApi.search_points  s(     ,,+#)	 - 
 	
r   r~   r   r   r   r   r   r     r   r   r   )NNTNTT) typingr   r   r   r   r   r   pydanticr	   pydantic.mainpydantic.versionr
   PYDANTIC_VERSIONqdrant_client.http.modelsr   rA   
startswithr   r   r   r?   	SetIntStrDictIntStrAnyfiler   r$   r%   qdrant_client.http.api_clientr&   r(   r   r   r   r   r   <module>r      s   @ @  # 8 ' 1)))$/{+c3h 	U38_c)*+9 +S +C +C + 04	9m+, 	
   , 7|
 |
~\
Z \
~\
J \
r   