
    LKi                        % S SK r S SKJrJrJrJrJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJrJrJr  S SKJr  S SKJr  S S	KJrJr  S
SSSSSS.r\\\4   \S'   / SQrSSSSSSS.r\\\4   \S'   / SQrSSSSSSSSSS.	r\\\4   \S'   S \S!\\\\4   \\\4   4   4S" jr S#\\   S$\\   S%\\\\4      S!\\\4   4S& jr!S#\\   S$\\   S%\\\\4      S!\\\4   4S' jr"S(\#S#\\   S$\\   S%\\\\4      S!\\\4   4
S) jr$S*\\\4   S+\\\4   S(\#S!S4S, jr%S-\\\4   S+\\\4   S(\#S!S4S. jr&S!\\\\\4   4   4S/ jr'S \S!\\\\\4   4   4S0 jr(S1\S2\\\\\4   4   S!S4S3 jr)\	" \RT                  " 5       \RV                  " 5       S49S5\S6\S7\RX                  S!S4S8 j5       r-\	" \RT                  " 5       \R\                  " 5       S99S5\S6\S \\   S!S4S: j5       r/g);    N)AnyDictOptionalSetTuplecast)given)	ClientAPI)CreateCollectionConfiguration)CollectionMetadataEMBEDDING_KEYSchema)
strategies)check_metadata)resetis_spann_disabled_modespaceef_construction	ef_searchmax_neighborssync_thresholdresize_factor)
hnsw:spacezhnsw:construction_efzhnsw:search_efzhnsw:Mzhnsw:sync_thresholdzhnsw:resize_factorHNSW_METADATA_TO_CONFIG)r   r   r   r   r   r   l2d      i  g333333?HNSW_DEFAULTS)	r   search_nprobewrite_nprober   r   r   reassign_neighbor_countsplit_thresholdmerge_threshold@          2      SPANN_DEFAULTSschemareturnc                 @   U R                   R                  nUc   eUR                  nUc   eU R                  [           R                  nUc   eUR                  nUc   e[
        R                  " UR                  5      [
        R                  " UR                  5      4$ )N)defaults
float_listvector_indexkeysr   r   vector_index_to_dictconfig)r*   defaults_floatdefaults_viembedding_floatembedding_vis        d/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/test/property/test_schema.py#_extract_vector_configs_from_schemar8   I   s     __//N%%% --K"""kk-0;;O&&&"//L### 	''(:(:;''(;(;<     metadataconfigurationschema_vector_index_configc                 :   [         R                  5       nSnSnU(       Ga3  UR                  S5      nU(       a`  [        [        [
        [        4   U5      nUR                  [        R                  " U5      5        UR                  S5      b  US   US'   SnSnUR                  S5      nU(       a  [        [        [
        [        4   U5      n	[        R                  " U	5      n
U
R                  5        H  u  pUc  M
  U[        U   :w  d  M  SnM     U	R                  S5      b/  U(       d(  U	R                  S5      [        S   :w  a  SnU	S   US'   SnU(       a\  UR                  S5      b
  US   US'   SnUR                  S5      (       a*  [        R                  " US   5      nUR                  U5        U (       a?  U R                  S5      b-  U R                  S5      [         S   :w  a  U(       a
  U S   US'   SnU(       a@  UR                  S5       b-  UR                  S5      [         S   :w  a  U(       d
  US   US'   SnU(       dP  U(       aI  UR                  S5      b7  US   n[        US	5      (       a!  [        [        U5      R                  5       US'   U$ )
NFTspannr   hnswr    embedding_function_default_spaceembedding_functiondefault_space)r)   copygetr   r   strr   updater   non_none_itemsitemsr   hasattrrB   )r:   r;   r<   expected	space_setshould_try_metadata	spann_cfgspann_cfg_dicthnsw_cfghnsw_cfg_dicthnsw_non_nonekeyvaluespann_schemaefs                  r7   _compute_expected_config_spannrV   \   s|    ""$HI !%%g.	!$sCx.)<NOOJ55nEF!!'*6$27$;! 	&+# $$V, c3h:M&55mDM+113
$-2D)D +0' 4   )5i $$W-w1GG*/'$1'$:! 	!%))'2> :7 CHWI%))'22%44*73L OOL) 	LL&2LL&.*AA$\2	 	#&**+MN&**+MN'"#6.
 	 23?/02'' $S" ; ; =HWOr9   c                    [         R                  5       nSn[        5       nSnU(       Ga5  UR                  S5      nUb  [	        [
        [        [        4   U5      n[        R                  " U5      n	UR                  U	5        U	R                  5        H  u  pUc  M
  U[         U
   :w  d  M  SnM     UR                  U	R                  5       5        U	R                  S5      b'  U(       d   U	R                  S5      [         S   :w  a  SnSnUR                  S5      nUbB  [	        [
        [        [        4   U5      nUR                  S5      b  U(       d  US   US'   SnSnU(       aw  U (       ap  [        R                  5        HX  u  pU R                  U
5      c  M  US:X  a  X
   X>'   SnUR                  U5        M:  X;  d  MA  X
   X>'   UR                  U5        MZ     U(       ar  UR                  S5      b
  US   US'   SnUR                  S5      (       a)  UR                  [        R                  " US   5      5        OUR                  S5      (       a   U(       a$  UR                  S5       b  U(       d
  US   US'   SnU(       dP  U(       aI  UR                  S5      b7  US   n[        US5      (       a!  [	        [        U5      R!                  5       US'   U$ )	NFTr?   r   r>   r@   rA   rB   )r   rC   setrD   r   r   rE   r   r   rG   rF   rH   r0   r   addrI   rB   )r:   r;   r<   rJ   rK   configured_hnsw_keysrL   hnsw_cfg_raw	hnsw_dictrQ   rR   rS   spann_cfg_raw
spann_dictcfg_keyrU   s                   r7   _compute_expected_config_hnswr`      s   
 !!#HI%(U$((0#(,T#s(^\(JI&55i@MOOM*+113
$-2D)D*/' 4 !''(:(:(<=  )5i $$W-w1GG*/' 	%))'2$)-d38nm)LJ~~g&29$.w$7! 	&+#x399;LC||C ('!$,M! 	$((12$,M!$((1 < "%))'2> :7 CHWI%))&11OO))*DV*LM (++G44 	#&**+MN6.
 	 23?/02'' $S" ; ; =HWOr9   spann_activec                 @    U (       a  [        XU5      $ [        XU5      $ )aB  
some assumptions/assertions:
1. we are not testing failure paths. any config built is/should be valid. invalid cases can be tested separately or in e2e tests
ex: if configuration is set, schema is not set. if schema is set, configuration is not set. both hnsw and spann cannot be set at the same time in config or schema
)rV   r`   ra   r:   r;   r<   s       r7   _compute_expected_configrd     s/     -%?
 	
 -%?
 	
r9   actualrJ   c                 :   U(       a  [         O[        nU H  nU R                  U5      nX   n[        U[        5      (       aA  [        U[        5      (       a,  [
        R                  " XVSSS9(       d   U SU SU 35       eMn  XV:X  a  Mu   U SU SU 35       e   g )N&.>rel_tolabs_tol mismatch: expected , got )SPANN_FIELDSHNSW_FIELDSrD   
isinstancefloatmathisclose)re   rJ   ra   fieldsfieldactual_valueexpected_values          r7   _assert_config_valuesrw     s    
 *\{Fzz%(!lE**z.%/P/P<<dD R,^,<F<.QR 
 .R,^,<F<.QR. r9   vector_infoc                 0   U S   US   :X  d   eU(       a  [        [        [        [        [        4      U S   5      nUc   e[
         H  nUS:X  a  M  UR                  U5      nX   n[        U[        5      (       aA  [        U[        5      (       a,  [        R                  " XVSSS9(       d   U SU SU 35       eMv  XV:X  a  M}   U SU SU 35       e   g [        [        [        [        [        4      U S   5      nUc   e[         H  nUS:X  a  M  UR                  U5      nX   n[        U[        5      (       aA  [        U[        5      (       a,  [        R                  " XVSSS9(       d   U SU SU 35       eMv  XV:X  a  M}   U SU SU 35       e   g )Nr   r>   rg   rh   rk   rl   r?   )r   r   r   rE   r   rm   rD   ro   rp   rq   rr   rn   )rx   rJ   ra   rM   rt   ru   rv   rO   s           r7   _assert_schema_valuesrz   ,  s   
 w8G#4444$sCx.1;w3GH	$$$!E$==/L%_N,..:ne3T3T|| $ VW00@|nUV 
 !2VW00@|nUV2 " c3h0+f2EF### E#<<.L%_N,..:ne3T3T|| $ VW00@|nUV 
 !2VW00@|nUV2 !r9   c                  P    SS0SS0SS0SS0SS0SS0SS0S.SS0SS0S.SSS00S.$ )z
Get expected index states for default schema (when schema=None).
Based on Schema._initialize_defaults() and _initialize_keys().
enabledTF)string_invertedint_invertedfloat_invertedbool_invertedsparse_vector	fts_indexr/   )r}   r   r/   )r-   	#documentz
#embedding r   r9   r7   _get_default_schema_indexesr   V  ss     !*40&-($/'.'/#U+&.
 !*51#T*

 Y-
 r9   c                 ,	   0 nU R                   R                  (       ab  U R                   R                  R                  (       a=  SU;  a  0 US'   SU R                   R                  R                  R                  0US   S'   U R                   R                  (       ab  U R                   R                  R
                  (       a=  SU;  a  0 US'   SU R                   R                  R
                  R                  0US   S'   U R                   R                  (       ab  U R                   R                  R                  (       a=  SU;  a  0 US'   SU R                   R                  R                  R                  0US   S'   U R                   R                  (       ab  U R                   R                  R                  (       a=  SU;  a  0 US'   SU R                   R                  R                  R                  0US   S'   U R                   R                  (       a  U R                   R                  R                  (       af  SU;  a  0 US'   U R                   R                  R                  R                  U R                   R                  R                  R                  S.US   S'   U R                  R                  5        GH  u  p#U[        S	4;   a  M  0 nUR                  (       a@  UR                  R                  (       a%  SUR                  R                  R                  0US'   UR                  (       a@  UR                  R
                  (       a%  SUR                  R
                  R                  0US'   UR                  (       a@  UR                  R                  (       a%  SUR                  R                  R                  0US'   UR                  (       a@  UR                  R                  (       a%  SUR                  R                  R                  0US'   UR                  (       a_  UR                  R                  (       aD  UR                  R                  R                  UR                  R                  R                  S.US'   U(       d  GM  XAU'   GM     U$ )
zs
Extract expected index states from input schema.
Returns a dict mapping key -> index_type -> enabled/config info.
r-   r|   r}   r~   r   r   )r|   r2   r   r   )r-   stringstring_inverted_indexr|   	int_valueint_inverted_indexfloat_valuefloat_inverted_indexbooleanbool_inverted_indexr   sparse_vector_indexr2   r0   rH   r   )r*   rJ   rR   value_typeskey_expecteds        r7    _extract_expected_schema_indexesr   o  s    +-H &//"8"8"N"NX%#%HZ v--CCKK3
./   V__%>%>%Q%QX%#%HZ v00CCKK0
^, ""v'B'B'W'WX%#%HZ v22GGOO2
-. 6??#:#:#N#NX%#%HZ v..BBJJ1
_-
 	%%OO))==X%#%HZ 44HHPPoo33GGNN1
_- #KK--/=+..')+"4"4"J"J;--CCKK/L*+   [%:%:%M%M;00CCKK,L( ""{'>'>'S'S;22GGOO.L)* ;#6#6#J#J;..BBJJ-L) $$)B)B)V)V&44HHPP%33GGNN-L)
 <(SME 0H Or9   actual_schemaexpected_indexesc                 "   SU;   Ga  US   nU R                   nSU;   av  US   S   nUR                  nU(       aM  UR                  (       a<  UR                  R                  U:X  d!   SU SUR                  R                   35       eOU(       d   S5       eSU;   av  US   S   nUR                  nU(       aM  UR
                  (       a<  UR
                  R                  U:X  d!   SU SUR
                  R                   35       eOU(       d   S	5       eS
U;   av  US
   S   nUR                  nU(       aM  UR                  (       a<  UR                  R                  U:X  d!   SU SUR                  R                   35       eOU(       d   S5       eSU;   av  US   S   nUR                  nU(       aM  UR                  (       a<  UR                  R                  U:X  d!   SU SUR                  R                   35       eOU(       d   S5       eSU;   Ga$  US   S   nUR                  n	U	c   S5       eU	R                  c   S5       eU	R                  R                  U:X  d!   SU SU	R                  R                   35       eSUS   ;   a  US   S   n
U	R                  R                  nU
R                  b;  UR                  U
R                  :X  d!   SU
R                   SUR                   35       eU
R                  b;  UR                  U
R                  :X  d!   SU
R                   SUR                   35       eSU;   am  US   S   nUR                  nUc   S5       eUR                  c   S5       eUR                  R                  U:X  d!   SU SUR                  R                   35       eSU;   am  US   S   nUR                   nUc   S5       eUR"                  c   S5       eUR"                  R                  U:X  d!   SU SUR"                  R                   35       eUR%                  5        GHa  u  pUS:X  a  M  XR&                  ;   d   S U S!35       eU R&                  U   nSU;   ax  US   S   nUR                  nUc   S"U S#35       eUR                  c   S"U S$35       eUR                  R                  U:X  d$   S"U S%U SUR                  R                   35       eSU;   ax  US   S   nUR                  nUc   S"U S&35       eUR
                  c   S"U S'35       eUR
                  R                  U:X  d$   S"U S(U SUR
                  R                   35       eS
U;   ax  US
   S   nUR                  nUc   S"U S)35       eUR                  c   S"U S*35       eUR                  R                  U:X  d$   S"U S+U SUR                  R                   35       eSU;   ax  US   S   nUR                  nUc   S"U S,35       eUR                  c   S"U S-35       eUR                  R                  U:X  d$   S"U S.U SUR                  R                   35       eSU;   Ga,  US   S   nUS   S   n
UR                  n	U	c   S"U S/35       eU	R                  c   S"U S035       eU	R                  R                  U:X  d$   S"U S1U SU	R                  R                   35       eU	R                  R                  nU
R                  b>  UR                  U
R                  :X  d$   S"U S2U
R                   SUR                   35       eU
R                  b>  UR                  U
R                  :X  d$   S"U S3U
R                   SUR                   35       eSU;   ax  US   S   nUR                  nUc   S"U S#35       eUR                  c   S"U S435       eUR                  R                  U:X  d$   S"U S5U SUR                  R                   35       eSU;   d  GM  US   S   nUR                   nUc   S"U S635       eUR"                  c   S"U S735       eUR"                  R                  U:X  a  GM@   S"U S8U SUR"                  R                   35       e   g)9z<Assert that the actual schema matches expected index states.r-   r}   r|   z4defaults string_inverted enabled mismatch: expected rl   z*defaults string_inverted should be enabledr~   z1defaults int_inverted enabled mismatch: expected z'defaults int_inverted should be enabledr   z3defaults float_inverted enabled mismatch: expected z)defaults float_inverted should be enabledr   z2defaults bool_inverted enabled mismatch: expected z(defaults bool_inverted should be enabledr   Nz#defaults sparse_vector should existz)defaults sparse_vector_index should existz2defaults sparse_vector enabled mismatch: expected r2   z/defaults sparse_vector bm25 mismatch: expected z5defaults sparse_vector source_key mismatch: expected r   zdefaults string should existzdefaults fts_index should existz.defaults fts_index enabled mismatch: expected r/   z defaults float_list should existz"defaults vector_index should existz1defaults vector_index enabled mismatch: expected zExpected key 'z' not found in schemazKey 'z' string should existz$' string_inverted_index should existz-' string_inverted enabled mismatch: expected z' int_value should existz!' int_inverted_index should existz*' int_inverted enabled mismatch: expected z' float_value should existz#' float_inverted_index should existz,' float_inverted enabled mismatch: expected z' boolean should existz"' bool_inverted_index should existz+' bool_inverted enabled mismatch: expected z' sparse_vector should existz"' sparse_vector_index should existz+' sparse_vector enabled mismatch: expected z(' sparse_vector bm25 mismatch: expected z.' sparse_vector source_key mismatch: expected z' fts_index should existz'' fts_index enabled mismatch: expected z' float_list should existz' vector_index should existz*' vector_index enabled mismatch: expected )r-   r   r   r|   r   r   r   r   r   r   r   r   r2   bm25
source_keyr   r.   r/   rH   r0   )r   r   defaults_expecteddefaults_actualexpected_enabledactual_string
actual_intactual_floatactual_boolactual_sparseexpected_configactual_configactual_float_listrR   r   actual_value_typess                   r7   _assert_schema_indexesr     s    %%,Z8'00 1101BCIN+22M!D!D!77??CSSPIJZI[[abo  cF  cF  cN  cN  bO  PPS (U)UU'..0@K(22Jj;;1199=MMGFGWFXX^_i_|_|  `E  `E  _F  GGM (R)RR'0001AB9M*66L A A 55==AQQMHIYHZZ`am  bC  bC  bK  bK  aL  MMQ (T)TT'//0A)L)11K{>>33;;?OOJGHXGYY_`k``  aH  aH  `I  JJO (S)SS'//0A)L+99M ,S.SS,11=;:;= 1199=MMHCDTCUU[\i\}\}  ]F  ]F  \G  HHM ,_=="3O"DX"N - A A H H"''3%**o.B.BBzHI]I]H^^derewewdxyzB"--9%00O4N4NNLNOiOiNjjpq~  rJ  rJ  qK  LLN ++0=iH+22M ,L.LL,''31013 ''//3CCz?@P?QQWXeXoXoXwXwWxyzC ..0@K / : :$0T2TT0!..:434: "..66:JJDBCSBTTZ[l[y[y  \B  \B  [C  DDJ .335*(((UN3%?T*UU(*//4,+,=>yI.55M ,PcU:O.PP,33?Ase?@A? 33;;?OOOseHIYHZZ`an  bE  bE  bM  bM  aN  OOO \)+N;IF+55J)PU3%7O+PP)--9>se<=>9 --559IIFseEFVEWW]^h^{^{  _D  _D  ^E  FFI |++,<=iH-99L+TuSE9S-TT+11=@se>?@= 1199=MMLseGHXGYY_`l  aB  aB  aJ  aJ  `K  LLM l*+O<YG,44K*OeC58N,OO*//;?se=>?; //77;KKIseFGWFXX^_j_~_~  `G  `G  _H  IIK l*+O<YG*?;HEO.<<M ,WcU:V.WW,11=?se=>?= 1199=MMKseFGWFXX^_l  `A  `A  `I  `I  _J  KKM *==DDM##/!&&/*>*>>y3%GH\H\G]]cdqdvdvcwxy>))5!,,0J0JJK3%MoNhNhMiiop}  qI  qI  pJ  KKJ ,&+K8C.55M ,PcU:O.PP,''35se3453 ''//3CC}seBCSBTTZ[h[r[r[z[zZ{|}C \)+N;IF 2 = =$0XE#>W2XX0!..:8se678: "..66:JJGseEFVEWW]^o^|^|  _E  _E  ^F  GGJy 6r9   )nameoptional_fieldsclientr   r   c                 l   UR                   nUR                  nUR                  n[        U 5        U R	                  UUUUS9nUc  UR                   S 0 4;   d   eO[        X6R                   5        UR                  n[        (       + nU(       a  SOSn	U(       a  SOSn
UR                  U	5      nUR                  U
5      nUc
   U	 S35       eUS 0 4;   d
   U
 S35       e[        UUUUR                  S9n[        [        [        [        [        4   U5      X5        U(       a  UR                  S5      b  US   nUb  UR                  S5      nUb  UR                  5       nU(       az  UR                  S5      S	:X  ae  [!        US
5      (       d   S5       eUR                  S
5      UR#                  5       :X  d*   SUR#                  5        SUR                  S
5       35       eUR                  nUc   e[%        U5      u  nnU(       a!  US   b   eUS   b   eUS   c   eUS   c   eO US   b   eUS   b   eUS   c   eUS   c   e['        UX5        ['        UX5        U(       GaN  UR                  S5      Gb:  US   nUGb0  UR(                  R*                  R,                  R.                  R0                  nUb\  [!        US
5      (       aK  UR#                  5       UR#                  5       :X  d)   SUR#                  5        SUR#                  5        35       eUR2                  [4           R*                  R,                  R.                  R0                  nUb^  [!        US
5      (       aL  UR#                  5       UR#                  5       :X  d)   SUR#                  5        SUR#                  5        35       eg g g g g g )N)r   r:   r;   r*   r>   r?   z configuration missingz configuration should be absentrc   rA   typeknownr   z*embedding function should have name methodz+embedding function name mismatch: expected rl   z4defaults embedding function name mismatch: expected z9embedding key embedding function name mismatch: expected )r:   r;   r*   r   create_collectionr   r   rD   rd   schema_vector_inforw   r   r   rE   r   
get_configrI   r   r8   rz   r-   r.   r/   r2   rA   r0   r   )r   r   r   r:   r;   r*   
collectioncoll_configra   
active_keyinactive_keyactive_blockinactive_blockrJ   rU   coll_ef	ef_configschema_resultdefaults_cfgembedding_cfgdefaults_efembedding_efs                         r7   1test_vector_index_configuration_create_collectionr     s    ''H#11M##F	&M))#	 * J ""tRj000x!4!45**K--L(fJ)6wL??:.L __\2N#J
|3I%JJ#
  8 678 
 (!##2#E#E	H $tCH~|<hU **+?@L/0>!oo&:;G"#..0	v!6'!A"F  DCD  %==0BGGI= $$&GGI;fY]]65J4KM=
 %%M$$$"Em"TL-F#+++V$,,,G$000W%111G$,,,W%---F#///V$000,?-@ **+?@L/0>'00;;HHOObbK&7;+G+G"'')RWWY6   "	{&1A1A1C0DF6
 )--m<GGTT[[nnL'GL&,I,I#((*bggi7   "	{&1B1B1D0EG7 -J'  M}r9   r   r*   c                    [        U 5        Uc  [        5       nO[        U5      nU R                  XS9nUR                  nUc   S5       e[        XS5        U R                  U5      nUR                  nUc   S5       e[        XS5        g)z
Test that schema-only components (inverted indexes, sparse vector indexes)
are correctly created and persisted when creating a collection.
Nr   zSchema should not be None)r   r   r   r   r*   r   get_collection)r   r   r*   r   r   r   s         r7   %test_schema_create_and_get_collectionr     s     
&M~68;FC))t)CJ %%M$A&AA$=;&&t,J%%M$A&AA$=;r9   )0rq   typingr   r   r   r   r   r   
hypothesisr	   chromadb.apir
   %chromadb.api.collection_configurationr   chromadb.api.typesr   r   r   chromadb.test.propertyr   !chromadb.test.property.invariantsr   chromadb.test.conftestr   r   r   rE   __annotations__rn   r   rm   r)   r8   rV   r`   boolrd   rw   rz   r   r   r   collection_name&metadata_configuration_schema_strategyCollectionInputCombinationr   schema_strategyr   r   r9   r7   <module>r      s    8 8  " O 
 . < -!+)+ c3h  !tCH~ 
 !
"S#X 

4S>4S>)*&S)*S9:S !)c3h 8S 
#s(^	SlN)*N9:N !)c3h 8N 
#s(^	Nb

)*
 9:
 !)c3h 8	

 
#s(^
*RcNR38nR R 
	R('Vc3h'V38n'V 'V 
	'VTT#tCH~*=%> 2VV	#tCH~
VrGG3S#X./G 
GD 		#	#	%EEG``
`  ::` 
	`	`F 		#	#	%%%'<<
< V< 
	<	<r9   