
    LKi}              	          S SK JrJrJrJrJrJr  S SKrS SKJ	r	J
r
JrJr  S SKJrJr  S SKJr  S SKrS SKJr   " S S\S	S
9r " S S\S	S
9r " S S\SS
9rS\S\4S jrS\\\4   S\4S jrS\S\4S jrS\S\\\4   4S jr " S S\S	S
9rS\\\4   S\4S jr " S S\S	S
9rS\\\4   S\4S jr " S S \S	S
9r S!\
S\ 4S" jr!S!\\\4   S\ 4S# jr"S\\\4   S\ 4S$ jr# SJS\ S!\\
   S\4S% jjr$ SJS\ S!\\
   S\\\4   4S& jjr% SJS\S'\\   S\4S( jjr& " S) S*\S	S
9r'S\\\4   S\'4S+ jr( " S, S-\S	S
9r)S\\\4   S\)4S. jr* " S/ S0\S	S
9r+S!\
S\+4S1 jr,S!\S\+4S2 jr-S\+S\4S3 jr.S\+S\\\4   4S4 jr/S5\S\+4S6 jr0S\\\4   S\+4S7 jr1S8\S9\'S\4S: jr2S;\S<\)S\4S= jr3S>\S?\S\4S@ jr4SA\SB\+S\4SC jr5SD\\   SE\\   SS4SF jr6SD\\   SG\\\\4      SS4SH jr7      SKSI jr8g)L    )	TypedDictDictAnyOptionalcastget_argsN)SpaceCollectionMetadataUpdateMetadataEmbeddingFunction)known_embedding_functionsregister_embedding_function)	cpu_count)Schemac                   f    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S	'   S
rg)HNSWConfiguration   spaceef_constructionmax_neighbors	ef_searchnum_threads
batch_sizesync_thresholdresize_factor N	__name__
__module____qualname____firstlineno__r	   __annotations__intfloat__static_attributes__r       g/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/api/collection_configuration.pyr   r      /    LNOr&   r   F)totalc                   p    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S	'   \\S
'   Srg)SpannConfiguration   search_nprobewrite_nprober   r   r   r   reassign_neighbor_countsplit_thresholdmerge_thresholdr   Nr   r   r    r!   r#   r"   r	   r%   r   r&   r'   r+   r+      6    LN  r&   r+   c                   F    \ rS rSr% \\   \S'   \\   \S'   \\   \S'   Sr	g)CollectionConfiguration*   hnswspannembedding_functionr   N)
r   r   r    r!   r   r   r"   r+   r   r%   r   r&   r'   r5   r5   *   s&    
$
%%&'' !233r&   r5   Tconfig_json_strreturnc                 D    [         R                  " U 5      n[        U5      $ N)jsonloads'load_collection_configuration_from_json)r:   config_json_maps     r'   +load_collection_configuration_from_json_strrB   0   s     jj1O2?CCr&   rA   c           	         U R                  S5      b  U R                  S5      b  [        S5      eS nS nS nU R                  S5      b  [        [        U S   5      nU R                  S5      b  [        [        U S   5      nU R                  S5      bQ  U S   nUS   S:X  a  [
        R                  " S[        SS	9  S nO( US
   n [        U   n UR                  US   5      nOS n[        UUUS9$ ! [         a    [        SU 35      ef = f! [         a    [        SU S35      ef = f! [         a  n[        SUS
    SUS    SU 35      eS nAff = f)Nr8   r7   &hnsw and spann cannot both be providedr9   typelegacy legacy embedding function config   
stacklevelnamez-Embedding function name not found in config: zEmbedding function zO not found. Add @register_embedding_function decorator to the class definition.configz#Could not build embedding function z from config z: r7   r8   r9   )get
ValueErrorr   r   r+   warningswarnDeprecationWarningKeyErrorr   build_from_config	Exceptionr5   )rA   hnsw_configspann_config	ef_configefef_namees          r'   r@   r@   8   s    	G$0'3ABBKLI 6".,of.EF7#/.0HI /0<#$89	V(MM2"
 B#F+
.w7
)))H*=> " '   CI;O    )'  3B  C    9)F:K9LMZcdlZmYnnpqrpst s0   >C0 	D D) 0D	D&)
E3EErL   c                 @    [         R                  " [        U 5      5      $ r=   )r>   dumps collection_configuration_to_json)rL   s    r'   $collection_configuration_to_json_strr_   r   s    ::6v>??r&   c                    [        U [        5      (       a4  U R                  S5      nU R                  S5      nU R                  S5      nOT U R                  S5      R                  n U R                  S5      R                  n U R                  S5      R                  nS nUb   [        [        U5      nUb   [        [        U5      nUc  S nSS0nUbR   UR                  5       (       a  SS0nO7UR                  5       SUR                  5       S	.n[        [        U5      5         UUUS.$ ! [
         a    S n Nf = f! [
         a    S n Nf = f! [
         a    S n Nf = f! [         a  n[        SU 35      eS nAff = f! [         a  n[        SU 35      eS nAff = f! [         a-  n[        R                   " S
U 3["        SS9  S nSS0n S nANS nAff = f)Nr7   r8   r9   not a valid hnsw config: not a valid spann config: rE   rF   knownrK   rE   rL   "legacy embedding function config: rH   rI   rM   )
isinstancedictrN   get_parametervaluerO   r   r   rU   r+   	is_legacyrK   
get_configr   rE   rP   rQ   rR   )rL   rV   rW   rY   rX   r[   s         r'   r^   r^   v   s   &$jj(zz'*ZZ,-	 ..v6<<K	 !//8>>L	%%&:;AAB (,I	>0+>K 	? 2LAL 
zX&		~	+||~~#X.	 GGI# mmo	
 ,DH5 ' _  	K	  	 L	   	B	  	>8<==	>
  	?9!=>>	?$  	+MM4QC8"
 B*I	+s   D, 'D> E $E" 8F F" /6F" ,D;:D;>EEEE"
E?,E::E?
FFF"
G,#GGc                   f    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S	'   S
rg)CreateHNSWConfiguration   r   r   r   r   r   r   r   r   r   Nr   r   r&   r'   rm   rm      r(   r&   rm   json_mapc                 0   0 nSU ;   a+  U S   nU[        [        5      ;   a  X!S'   O[        SU 35      eSU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   S	U ;   a  U S	   US	'   U$ )
Nr   not a valid space: r   r   r   r   r   r   r   r   r	   rO   ro   rL   space_values      r'   !json_to_create_hnsw_configurationru      s     ')F(w'(5/))7O2;-@AAH$$,->$? !(""*?";h&{3{  ( 7}x'5|8##+,<#= (""*?";Mr&   c                   p    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S	'   \\S
'   Srg)CreateSpannConfiguration   r-   r.   r   r   r   r   r/   r0   r1   r   Nr2   r   r&   r'   rw   rw      r3   r&   rw   c                     0 nSU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a+  U S   nU[        [        5      ;   a  X!S'   O[        SU 35      eSU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   U$ )Nr-   r.   r   rq   r   r   r   rr   rs   s      r'   "json_to_create_spann_configurationrz      s     (*F(""*?";!!).!9~(w'(5/))7O2;-@AAH$$,->$? !h&{3{(""*?";Mr&   c                   F    \ rS rSr% \\   \S'   \\   \S'   \\   \S'   Sr	g)CreateCollectionConfiguration   r7   r8   r9   r   N)
r   r   r    r!   r   rm   r"   rw   r   r%   r   r&   r'   r|   r|      &    
*
++,-- !233r&   r|   metadatac                     [        U 5      $ )FCreate a CreateCollectionConfiguration from legacy collection metadata)9create_collection_configuration_from_legacy_metadata_dict)r   s    r'   ?create_collection_configuration_from_legacy_collection_metadatar     s     EXNNr&   c           	          SSSSSSSSS	.n0 nU R                  5        H  u  p4X1;   d  M  XBX   '   M     [        U5      n[        U5      n[        US
9$ )r   r   r   r   r   r   r   r   r   )
hnsw:spacezhnsw:construction_efzhnsw:Mhnsw:search_efhnsw:num_threadshnsw:batch_sizehnsw:sync_thresholdhnsw:resize_factorr7   )itemsru   populate_create_hnsw_defaultsr|   r   
old_to_newro   rK   ri   rV   s         r'   r   r   
  so    
  1!%)'/-	J H~~').Z%& ( 4H=K/<K(k::r&   c                    U R                  S5      b  U R                  S5      b  [        S5      e[        5       nU R                  S5      b  [        U S   5      US'   U R                  S5      b  [	        U S   5      US'   U R                  S5      bM  U S   nUS   S:X  a  [
        R                  " S[        SS	9  U$ [        US
      nUR                  US   5      US'   U$ )Nr7   r8   rD   r9   rE   rF   rG   rH   rI   rK   rL   )
rN   rO   r|   ru   rz   rP   rQ   rR   r   rT   )ro   resultrX   rY   s       r'   .load_create_collection_configuration_from_jsonr   #  s     ||F'HLL,A,MABB*,F ||F':8F;KLv||G(<Xg=NOw ||()512	V(MM2" M +9V+<=B+-+?+?	(@S+TF'(Mr&   c                 @    [         R                  " [        X5      5      $ )zFConvert a CreateCollection configuration to a JSON-serializable string)r>   r]   'create_collection_configuration_to_json)rL   r   s     r'   +create_collection_configuration_to_json_strr   B  s    
 ::=fOPPr&   c           	         SnU R                  S5      nU R                  S5      nUb   [        [        U5      nUb   [        [
        U5      nUb  Ub  [	        S5      eU R                  S5      c  SnSS	0nUUUS
.$  [        [        U R                  S5      5      nUR                  5       (       a  SS	0nGO-Uc/  Uc,  Ub  UR                  S5      c  [        UR                  5       S9nUb%  UR                  S5      c  UR                  5       US'   Ub%  UR                  S5      c  UR                  5       US'   Ubq  UR                  S5      UR                  5       ;  aN  [        R                  " SUR                  S5       SUR                  5        SUR                  5        3[        SS9  Ubq  UR                  S5      UR                  5       ;  aN  [        R                  " SUR                  S5       SUR                  5        SUR                  5        3[        SS9  Uc  Uc  Ub  UR                  S5      bq  UR                  S5      UR                  5       ;  aN  [        R                  " SUR                  S5       SUR                  5        SUR                  5        3[        SS9  UR                  5       SUR                  5       S.n[        [!        U5      5         UUUS
.$ ! [         a  n[	        SU 35      eSnAff = f! [         a  n[	        SU 35      eSnAff = f! [         a-  n[        R                  " SU 3["        SS9  SnSS	0n SnANxSnAff = f)zDConvert a CreateCollection configuration to a JSON-serializable dictNr7   r8   ra   rb   rD   r9   rE   rF   rM   r   )r   r   zspace z is not supported by z. Supported spaces: rH   rI   rc   rd   re   )rN   r   rm   rU   rO   rw   r   rj   default_spacesupported_spacesrP   rQ   rK   UserWarningrk   r   rE   rR   )rL   r   rX   rV   rW   r[   rY   s          r'   r   r   K  s   
 (,I**V$K::g&L	>6DK 	? 8,GL <#;ABBzz&'/X&	!"+
 	
B'#VZZ0D%EF<<>>*I "|';#x||L'A'I"9@P@P@R"SK &;??7+C+K')'7'7'9G$'L,<,<W,E,M(*(8(8(:W% &??7+23F3F3HHMM !9 ::OPRPWPWPY{Znoq  pC  pC  pE  oF  G##$
 '##G,B4G4G4IIMM !1!1'!: ;;PQSQXQXQZP[[opr  qD  qD  qF  pG  H##$ # ((LL.:<<-R5H5H5JJMM l!; <<QRTRYRYR[Q\\pqs  rE  rE  rG  qH  I##$ 	--/I
 (R1 ' q  	>8<==	>
  	?9!=>>	?T  '04	

 X&	'sM   K* L
 =8L* 7H,L* *
L4LL

L'L""L'*
M!4#MM!rY   c                    U R                  S5      c  U(       a  UR                  5       OSU S'   U R                  S5      c  SU S'   U R                  S5      c  SU S'   U R                  S5      c  SU S'   U R                  S5      c  [        5       U S'   U R                  S	5      c  SU S	'   U R                  S
5      c  SU S
'   U R                  S5      c  SU S'   U $ )z7Populate a CreateHNSW configuration with default valuesr   l2r   d   r      r   r   r   r   i  r   g333333?)rN   r   r   )rL   rY   s     r'   r   r     s     zz'"02"**,wzz#$,$' !zz/"*"$zz+&!{zz- ( )}zz,'"|zz"#+#' zz/"*"%Mr&   c                   H    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   Srg)	UpdateHNSWConfigurationi  r   r   r   r   r   r   N)r   r   r    r!   r#   r"   r$   r%   r   r&   r'   r   r     s    NOr&   r   c                     0 nSU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   SU ;   a  U S   US'   U$ )Nr   r   r   r   r   r   ro   rL   s     r'   !json_to_update_hnsw_configurationr     s     ')Fh&{3{  ( 7}x'5|8##+,<#= (""*?";Mr&   c                   *    \ rS rSr% \\S'   \\S'   Srg)UpdateSpannConfigurationi  r-   r   r   N)r   r   r    r!   r#   r"   r%   r   r&   r'   r   r     s    Nr&   r   c                 B    0 nSU ;   a  U S   US'   SU ;   a  U S   US'   U$ )Nr-   r   r   r   s     r'   "json_to_update_spann_configurationr     s<     (*F(""*?";h&{3{Mr&   c                   F    \ rS rSr% \\   \S'   \\   \S'   \\   \S'   Sr	g)UpdateCollectionConfigurationi  r7   r8   r9   r   N)
r   r   r    r!   r   r   r"   r   r   r%   r   r&   r'   r   r     r~   r&   r   c                     SSSSSS.n0 nU R                  5        H  u  p4X1;   d  M  XBX   '   M     [        U5      n[        US9$ )zGCreate an UpdateCollectionConfiguration from legacy collection metadatar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s         r'   ?update_collection_configuration_from_legacy_collection_metadatar     \    
 &)'/-J H~~').Z%& ( 4H=K(k::r&   c                     SSSSSS.n0 nU R                  5        H  u  p4X1;   d  M  XBX   '   M     [        U5      n[        US9$ )zCCreate an UpdateCollectionConfiguration from legacy update metadatar   r   r   r   r   r   r   r   r   s         r'   ;update_collection_configuration_from_legacy_update_metadatar     r   r&   c                 D    [        U 5      n[        R                  " U5      $ )zFConvert an UpdateCollectionConfiguration to a JSON-serializable string)'update_collection_configuration_to_jsonr>   r]   )rL   	json_dicts     r'   +update_collection_configuration_to_json_strr   !  s     8?I::i  r&   c                 H   U R                  S5      nU R                  S5      nU R                  S5      nUc  Uc  Uc  0 $ Ub   [        [        U5      nUb   [        [
        U5      nSnUbp  UR                  5       (       a  SS0nOXUR                  UR                  5       5        UR                  5       S	UR                  5       S
.n[        [        U5      5        OSnUUUS.$ ! [         a  n[	        SU 35      eSnAff = f! [         a  n[	        SU 35      eSnAff = f)zDConvert an UpdateCollectionConfiguration to a JSON-serializable dictr7   r8   r9   Nra   rb   rE   rF   rc   rd   rM   )rN   r   r   rU   rO   r   rj   validate_configrk   rK   r   rE   )rL   rV   rW   rY   r[   rX   s         r'   r   r   )  s7    **V$K::g&L	(	)B|3
		>6DK 	? 8,GL (,I	~<<>>*Ir}}/	--/I
 (R1	 ' 1  	>8<==	>  	?9!=>>	?s0   C$ D $
D.C<<D
D!DD!json_strc                 D    [         R                  " U 5      n[        U5      $ r=   )r>   r?   .load_update_collection_configuration_from_json)r   ro   s     r'   2load_update_collection_configuration_from_json_strr   U  s     zz(#H9(CCr&   c                    U R                  S5      b  U R                  S5      b  [        S5      e[        5       nU R                  S5      b  [        U S   5      US'   U R                  S5      b  [	        U S   5      US'   U R                  S5      bQ  U S   S   S:X  a  [
        R                  " S[        SS	9  U$ [        U S   S
      nUR                  U S   S   5      US'   U$ )z7Convert a JSON dict to an UpdateCollectionConfigurationr7   r8   rD   r9   rE   rF   rG   rH   rI   rK   rL   )
rN   rO   r   r   r   rP   rQ   rR   r   rT   )ro   r   rY   s      r'   r   r   ]  s     ||F'HLL,A,MABB*,F ||F':8F;KLv||G(<Xg=NOw ||()5()&1X=MM2" M +84H+I&+QRB+-+?+?-.x8,F'( Mr&   existing_hnsw_configupdate_hnsw_configc                 l    [        U 5      n/ SQnU H  nXA;   d  M
  X   X$'   M     [        [        U5      $ )z6Overwrite a HNSWConfiguration with a new configuration)r   r   r   r   r   )rg   r   r   )r   r   r   update_fieldsfields        r'   overwrite_hnsw_configurationr   ~  sB    
 &'FM &.5FM  !6**r&   existing_spann_configupdate_spann_configc                 l    [        U 5      nSS/nU H  nXA;   d  M
  X   X$'   M     [        [        U5      $ )z7Overwrite a SpannConfiguration with a new configurationr-   r   )rg   r   r+   )r   r   r   r   r   s        r'   overwrite_spann_configurationr     sH    
 '(FM
 '/6FM  "F++r&   existing_embedding_functionupdate_embedding_functionc                    U R                  5       (       d  UR                  5       (       a  [        R                  " S[        SS9  U $ U R	                  5       UR	                  5       :w  a.  [        SU R	                  5        SUR	                  5        S35      eUR                  U R                  5       UR                  5       5        U$ )z7Overwrite an EmbeddingFunction with a new configurationz.cannot update legacy embedding function configrH   rI   z6Cannot update embedding function: incompatible types ( vs ))rj   rP   rQ   rR   rK   rO   validate_config_updaterk   )r   r   s     r'   overwrite_embedding_functionr     s     #,,..2K2U2U2W2W<	

 +* #'')-F-K-K-MM+002348Q8V8V8X7YYZ\
 	
 44#..02K2V2V2X %$r&   existing_configupdate_configc                 r   UR                  S5      nUR                  S5      nUb  Ub  [        S5      eU R                  S5      nUb  Ub  [        XC5      nU R                  S5      nUb  Ub  [        XR5      nU R                  S5      nUR                  S5      nUb  Ub  [	        Xg5      nOUn[        UUUS9$ )z<Overwrite a CollectionConfiguration with a new configurationr8   r7   rD   r9   rM   )rN   rO   r   r   r   r5   )r   r   update_spannupdate_hnswupdated_hnsw_configupdated_spann_configupdated_embedding_function	update_efs           r'   "overwrite_collection_configurationr     s    
 !$$W-L##F+KK$;ABB *--f5&;+B:

 +..w7'L,D<  

 "1!4!45I!J!!"67I%1)E**& *3&" "5 r&   r9   configuration_efc                     U bf  Ubc  U R                  5       S:w  aO  U R                  5       UR                  5       :w  a-  [        SU R                  5        SUR                  5        35      eg)aP  
Validates that there are no conflicting embedding functions between function parameter
and collection configuration.

Args:
    embedding_function: The embedding function provided as a parameter
    configuration_ef: The embedding function from collection configuration

Returns:
    bool: True if there is a conflict, False otherwise
Ndefaultz]Multiple embedding functions provided. Please provide only one. Embedding function conflict: r   )rK   rO   )r9   r   s     r'   .validate_embedding_function_conflict_on_creater     s    $ %*:*F##%2"'')-=-B-B-DDo  qC  qH  qH  qJ  pK  KO  P`  Pe  Pe  Pg  Oh  i  r&   persisted_ef_configc                     Ubz  U bw  U R                  5       S:w  ac  UR                  S5      bQ  UR                  S5      U R                  5       :w  a.  [        SU R                  5        SUR                  S5       35      eg)zv
Validates that there are no conflicting embedding functions between function parameter
and collection configuration.
Nr   rK   zAn embedding function already exists in the collection configuration, and a new one is provided. If this is intentional, please embed documents separately. Embedding function conflict: new: z vs persisted: )rK   rN   rO   )r9   r   s     r'   +validate_embedding_function_conflict_on_getr     s     &+=+I##%2#''/;#''/3E3J3J3LL Q  Rd  Ri  Ri  Rk  Ql  l{  |O  |S  |S  TZ  |[  {\  ]  r&   c                     U R                   R                  b!  U R                   R                  R                  c  [        S5      eSnX R                  ;  a  [        SU S35      eU R                  U   nUR                  b  UR                  R                  c  [        SU S35      eU R                   R                  R                  UR                  R                  4 GH-  nSU;   a  US   b  UR
                  R                  c  [        S5      eUR
                  R                  nUS   nSU;   a
  US   Ul        S	U;   a
  US	   Ul        S
U;   a
  US
   Ul	        SU;   a
  US   Ul
        SU;   a
  US   Ul        OiSU;   ac  US   b]  UR
                  R                  c  [        S5      eUR
                  R                  nUS   nSU;   a
  US   Ul        SU;   a
  US   Ul        SU;   d  GM  US   c  GM  US   UR
                  l        GM0     U $ )z
Updates a schema with configuration changes.
Only updates fields that are present in the configuration update.

Args:
    schema: The existing Schema object
    configuration: The configuration updates to apply

Returns:
    Updated Schema object
z2Schema is missing defaults.float_list.vector_indexz
#embeddingzSchema is missing keys[]z].float_list.vector_indexr7   z1Trying to update HNSW config but schema has SPANNr   r   r   r   r   r8   z1Trying to update SPANN config but schema has HNSWr-   r9   )defaults
float_listvector_indexrO   keysrL   r7   r   r   r   r   r   r8   r-   r9   )	schemaconfigurationembedding_keyembedding_value_typesr   rV   r   rW   r   s	            r'   +update_schema_from_collection_configurationr   !  s5   " 	""*??%%22:MNN MKK'2=/CDD"KK6((0 ++88@%m_4MN
 	
 	""//((55 ]"}V'<'H""''/ !TUU&--22K'/K k)(3K(@%+*5m*D'{*)4\)B&;.-89I-J*+-,7,H)%-*@*L""((0 !TUU'..44L(1L ,.-9/-J*l*)5k)B& !M123?5BCW5XL2WZ Mr&   r=   )r   r   r   r   r;   r   )9typingr   r   r   r   r   r   r>   chromadb.api.typesr	   r
   r   r   "chromadb.utils.embedding_functionsr   r   multiprocessingr   rP   r   r   r+   r5   strrB   r@   r_   r^   rm   ru   rw   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   <module>r      s   A A   &  %	 	% 	4it 4DDD7#s(^77t@1H @S @;-D ;cSVh ;|iu 38n6	y 	38n.4IU 4O O"O;38n;";238n"B .2Q)Q)*Q 	Q .2g)g)*g 
#s(^gV HL#)12C)D.iu 38n"y 
38n4IU 4; ;";&;;";&!)!!)))	#s(^)XDD"D38n"B+++AX++*,-,1, ,&%!2%0% %8(,(0( (V !2301 
@ !23!$sCx.1 
(QQ%DQQr&   