
    _j30                        d dl Z d dlmZ d dlmZmZmZmZmZ d dl	Z	d dl
Z
d dlmZ d dl	mZmZ d dlZd dlmZ d dlmZmZ d dlmZmZ d dlmc mc mZ d dlmc mc mZ d dlmZ d d	l m!Z! d d
l"m#Z# d dl$m%Z% dZ& ej'         ej(        d          d          Z) ee) ej*        e)dd           ej+                               ed e e	j        d           e	j        d                              dej,        dej-        de.ddfd                        Z/ ee) ej*        e)ddd dd !           ej+                               ed e e	j        d            e	j        d"                    e	j0        j1        e	j0        j2        e	j0        j3        e	j0        j4        g#          dej,        dej-        de.ddfd$                        Z5deeef         fd%Z6d&ed'ed(e7de7fd)Z8	 	 d7dej,        dej-        de.d,e.d(e7ddfd-Z9	 	 d8d0e:d1e:d2e:dej-        fd3Z; ee) ej+                    4           edd"5          dej,        de.ddfd6                        Z<dS )9    N)randint)castListAnyDictTuple)givensettings)	ClientAPI)
Embeddings	Metadatas)NOT_CLUSTER_ONLYoverride_hypothesis_profile)wait_for_version_increase)create_batches)AdminClient)Settings
   T)with_hnsw_paramscoll)key   i  )min_sizemax_size
collection
record_setshould_compact2   )max_examples   )normalfast)deadlineparentr   r   r   returnc                 (    t          | ||           d S )N	_test_addr   s      a/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/test/property/test_add_mcmr.pytest_add_smallr+      s    " j*n55555          )r   r   num_unique_metadatamin_metadata_sizemax_metadata_size   )r$   r%   suppress_health_checkc                 ,    t          | ||d           d S )NT)batch_ann_accuracyr(   r   s      r*   test_add_mediumr6   3   s"    D j*nNNNNNNr,   c                      t          dd          } t          dd          }t          j        dd|           }t          j        dd|          }||fS )zCreate two clients connected to different regions for MCMR testing.

    Returns:
        A tuple of two ClientAPI instances connected to localhost:8000 and localhost:8001.
    N)chroma_server_hostchroma_server_http_port	localhosti@  )hostportr
   iA  )r   chromadb
HttpClient)	settings1	settings2client1client2s       r*   _create_mcmr_clientsrC   X   sa     D$OOOID$OOOI!{	RRRG!{	RRRGGr,   rA   rB   topologyc                     |                                  }t          |          }| dt          j                     }|                    |           |                     |           |                    |           |S )aD  Create an isolated database for MCMR testing using the topology+database format.

    Args:
        client1: The first client (region 1).
        client2: The second client (region 2).
        topology: The topology identifier for the test.

    Returns:
        The database name in the format '{topology}+{database}'.
    z+test_)get_settingsr   uuiduuid4create_databaseset_database)rA   rB   rD   admin_settingsadmindatabases         r*   _create_isolated_database_mcmrrN   e   s|     ))++N''E00$*,,00H	(###""""""Or,   Ftilt-spanningr5   c                    t                      \  }}t          |||           |                    | j        | j        | j        | j                  }|                    | j        | j                  }t          j	        |          }	t           o|}
t          t          |                                d                   }t          t          |                                d                   }d}t          t          t!          |	d                   dz            }t#          d|            t%          t'          |t          t(          t*                   |	d                   t          t,          |	d                   t          t.          |	d	                   t          t(          t*                   |	d
                                       }t1          |          D ]\  }}t#          dt!          |d                              |dz  dk    r |j        |  n
 |j        |  |
rt#          d           |t!          |d                   z  }||k    rgt#          d|            t#          d|            t#          d| d|            t5          || j        |          }t5          || j        |          }d}t          dt!          |	d                   dz            }||fD ]}t          j        |t          t8          j        |	                     |rd}t=          dt!          |	d                   |          D ]w}t          j        |t          t8          j        |	          || j        t%          t=          |tA          ||z   t!          |	d                                                            xt          j        |t          t8          j        |	          || j                   dS )a  Test adding records to a collection across multiple regions.

    Args:
        collection: The collection configuration.
        record_set: The records to add.
        should_compact: Whether to wait for compaction.
        batch_ann_accuracy: Whether to batch the ANN accuracy checks.
        topology: Topology identifier for MCMR testing.
            Creates two clients connected to localhost:8000 and localhost:8001.
    )namemetadataembedding_functionconfigurationrQ   rS   versionr   idsr   z.starting min_records_between_compaction_waits=
embeddings	metadatas	documentsapirW   rX   rY   rZ   addingr2   zshould wait for compactionz records_since_compaction_wait = z'min_records_between_compaction_waits = zwaiting z >= r   )	n_resultsrS   query_indices)r^   rS   N)!rC   rN   create_collectionrQ   rR   rS   collection_configget_collection
invariantswrap_allr   r   int	get_modelmax$MIN_RECORDS_BETWEEN_COMPACTION_WAITSlenprintlistr   r   strr   r   	enumerateaddr   count
strategies	RecordSetrangeann_accuracymin)r   r   r   r5   rD   rA   rB   coll1coll2normalized_record_setshould_wait_for_compactioncurrent_version1current_version2records_since_compaction_wait$min_records_between_compaction_waitsbatchesbatch_indexbatchr^   r   
batch_sizeis                         r*   r)   r)   }   s;   " ,--GW"7GX>>>%%_$%8 2	 &  E ""_%8 #  E
 '/
;;%5!5!H.C!2!29!=>>C!2!29!=>>$%!+.,c2G2N.O.OSU.U, ,( 
_9]__   T#Y 5e <==J(=l(KLL9&;K&HII49&;K&HII	
 	
 	
 G (00 2 2UhE!H&&&?aEIuEIu% 	2.///)Sq]]:),0TTTV7TVV   d>bdd   h<hhBfhh   $=Z_.>$ $  $=Z_.>$ $  12-
 A1%899R?AAI  tJ$8:OPPQQQ 	J1c"7">??LL 	 	'-/DEE''1'D"&aQ^S9Nu9U5V5V!W!WXX# #    	 #Z)+@AA##-#@	     r,   ȯ  P  	dimensionr   r   c                 X    t          ||          }d t          |          D             }d t          |          D             }d t          |          D             } fdt          |          D             }|t          t          |          ||d}t          t          j        |          S )Nc                 N    g | ]"}t          t          j                              #S  )rl   rG   rH   ).0_s     r*   
<listcomp>z*create_large_recordset.<locals>.<listcomp>   s&    
2
2
23tz||
2
2
2r,   c                     g | ]}d | iS )some_keyr   r   r   s     r*   r   z*create_large_recordset.<locals>.<listcomp>   s    ;;;!*f%;;;r,   c                     g | ]}d | S )z	Document r   r   s     r*   r   z*create_large_recordset.<locals>.<listcomp>   s    666QQ666r,   c                     g | ]}d gz  	S )g      ?r   )r   r   r   s     r*   r   z*create_large_recordset.<locals>.<listcomp>   s     9993%)#999r,   )rW   rX   rY   rZ   )r   rr   r   r   rp   rq   )	r   r   r   sizerW   rY   rZ   rX   r   s	   `        r*   create_large_recordsetr      s    
 8X&&D
2
2eDkk
2
2
2C;;uT{{;;;I66%++666I9999U4[[999J:z22	( (J 
$j111r,   )r   r   )r$   r    c                 Z   d}t                      \  }}t          |||           |                                j        dk    rt	          j        d           t          | j        dd          }|                    | j	        | j
        | j                  }|                    | j	        | j                  }t          j        |          }t          t           |                                d	                   }	t          t           |                                d	                   }
t%          t'          |t          t(          t*                   |d
                   t          t,          |d                   t          t.          |d                   t          t(          t*                   |d                                       }t1          |          D ]#\  }}|dz  dk    r |j        |   |j        |  $t4          sK|rIt7          |d
                   dk    r0t9          || j	        |	d           t9          || j	        |
d           ||fD ]}t          j        |t          t<          j        |                     t          j         |t          t<          j        |                     t          j!        |t          t<          j        |                     t          j"        |t          t<          j        |                     t          j#        |t          t<          j        |                     dS )zTest adding large record sets to a collection across multiple regions.

    Args:
        collection: The collection configuration.
        should_compact: Whether to wait for compaction.
    rO   z'chromadb.api.async_fastapi.AsyncFastAPIzDTODO @jai, come back and debug why CI runners fail with async + synci'  i N  )r   r   r   )rQ   rR   rS   rU   rV   rW   rX   rY   rZ   r[   r2   r   r   i,  )additional_timeN)$rC   rN   rF   chroma_api_implpytestskipr   r   r`   rQ   rR   rS   rb   rc   rd   r   re   rf   rk   r   r   rl   r   r   rm   rn   r   ri   r   ro   rp   rq   	ids_matchmetadatas_matchdocuments_matchembeddings_match)r   r   rD   rA   rB   r   ru   rv   rw   initial_version1initial_version2r}   r~   r   r   s                  r*   test_add_larger      sJ    H+--GW"7GX>>> 	.4	5 	5 	R	
 	
 	
 (&  J
 %%_$%8 &  E
 ""_%8 #  E
 '/
;;C!2!29!=>>C!2!29!=>>T#Y
5 122J
<(@AA9j&=>>49j&=>>	
 	
 	
 G (00  U?aEIuEIu 

 %e,--22 	"Z_&6	
 	
 	
 	
 	"Z_&6	
 	
 	
 	
  
 
tJ$8:OPPQQQT4
(<>S#T#TUUU"$z+-BCC	
 	
 	
 	"$z+-BCC	
 	
 	
 	#$z+-BCC	
 	
 	
 	

 
r,   )FrO   )r   r   )=rG   randomr   typingr   r   r   r   r   
hypothesisr   hypothesis.strategiesrp   str	   r
   r=   chromadb.apir   chromadb.api.typesr   r   chromadb.test.conftestr   r   !chromadb.test.property.strategiestestproperty!chromadb.test.property.invariantsrc   -chromadb.test.utils.wait_for_version_increaser   chromadb.utils.batch_utilsr   chromadb.api.clientr   chromadb.configr   rh   sharedcollectionscollection_st
recordsetsbooleans
Collectionrq   boolr+   HealthChecktoo_slowdata_too_largelarge_base_examplefunction_scoped_fixturer6   rC   rl   rN   r)   re   r   r   r   r,   r*   <module>r      s@          / / / / / / / / / / / / / /      " " " " " " & & & & & & & &  " " " " " " 4 4 4 4 4 4 4 4        7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 S S S S S S 5 5 5 5 5 5 + + + + + + $ $ $ $ $ $') $ 	0*0$GGGVTTT $z$]QMMM2;==  
 
&&"z"333 Z b111    6%6$6 6 
	6 6 6  6 $z$   2;==   
&&"z"222 Z a000  
 	'-16	  	O%	O$	O 	O 
		O 	O 	O  2	O
eIy$89 
 
 
 
  		   8  %#i i%i$i i 	i
 i 
i i i i` 2 222 2 	2 2 2 2( ->>>	4a(((Q
%Q
Q
 
Q
 Q
 Q
 )( ?>Q
 Q
 Q
r,   