
    ZiE;                        d dl mZ d dlZd dlmZ d dlmZmZmZ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  G d d	e          Z G d
 de          Zeeeeedf         Z G d de          Z G d d          Z G d d          Z  edd          Z! G d ded                   Z" G d de"          Z# G d de#          Z$e$Z% G d de"          Z& G d de&          Z'e'Z( G d de"          Z)dS )     )abstractmethodN)override)	AnyClassVarDictListOptionalProtocolUnionTypeVarcast)Self)	cpu_count)JSONSerializablec                       e Zd ZdZdS )StaticParameterErrorz?Represents an error that occurs when a static parameter is set.N__name__
__module____qualname____doc__     W/root/projects/butler/venv/lib64/python3.11/site-packages/chromadb/api/configuration.pyr   r      s        IIDr   r   c                       e Zd ZdZdS )InvalidConfigurationErrorz@Represents an error that occurs when a configuration is invalid.Nr   r   r   r   r   r      s        JJDr   r   ConfigurationInternalc                   2    e Zd ZdZededefd            ZdS )ParameterValidatorz+Represents an abstract parameter validator.valuereturnc                     t                      )z)Returns whether the given value is valid.)NotImplementedError)selfr    s     r   __call__zParameterValidator.__call__)   s     "###r   N)r   r   r   r   r   ParameterValueboolr%   r   r   r   r   r   &   sF        55$n $ $ $ $ ^$ $ $r   r   c                   T    e Zd ZU dZeed<   eed<   eed<   eed<   dedededefdZ	dS )ConfigurationDefinitionz-Represents the definition of a configuration.name	validator	is_staticdefault_valuec                 >    || _         || _        || _        || _        d S Nr*   r+   r,   r-   )r$   r*   r+   r,   r-   s        r   __init__z ConfigurationDefinition.__init__7   s'     	""*r   N)
r   r   r   r   str__annotations__r   r'   r&   r1   r   r   r   r)   r)   /   s         77
III!!!!OOO!!!!
+
+ &
+ 	
+
 &
+ 
+ 
+ 
+ 
+ 
+r   r)   c                   T    e Zd ZU dZeed<   eed<   dedefdZdefdZde	de
fdZd	S )
ConfigurationParameterz*Represents a parameter of a configuration.r*   r    c                 "    || _         || _        d S r/   r*   r    )r$   r*   r    s      r   r1   zConfigurationParameter.__init__J   s    	


r   r!   c                 (    d| j          d| j         dS )NzConfigurationParameter(z, )r7   r$   s    r   __repr__zConfigurationParameter.__repr__N   s    CCCdjCCCCr   _ConfigurationParameter__valuec                 z    t          |t                    st          S | j        |j        k    o| j        |j        k    S r/   )
isinstancer5   NotImplementedr*   r    )r$   r<   s     r   __eq__zConfigurationParameter.__eq__Q   s8    '#9:: 	"!!yGL(HTZ7=-HHr   N)r   r   r   r   r2   r3   r&   r1   r;   objectr'   r@   r   r   r   r5   r5   D   s         44
IIIS     D# D D D DIf I I I I I I Ir   r5   T)boundc                      e Zd ZU dZeeef         ed<   eeee	f                  ed<   dde
ee                  fdZdefdZd	edefd
Zedd            Zdee         fdZdedefdZdedeeeeef         ddfdZedefd            Zeededefd                        Zedeeef         fd            Zeedeeef         defd                        Z dS )r   z@Represents an abstract configuration, used internally by Chroma.parameter_mapdefinitionsN
parametersc                 X   i | _         |E|D ]A}|j        | j        vrt          d|j                   | j        |j                 }t	          |j        t                    rrt                                          |j                            dd                    }|t          d|j                   |	                    |j                  |_        t	          |j        t          |j                            st          d|j                   |j        } ||j                  st          d|j                   || j         |j        <   C| j                                        D ],\  }}|| j         vrt          ||j                  | j         |<   -|                                  dS )zbInitializes a new instance of the Configuration class. Respecting defaults and
        validators.NInvalid parameter name: _typezInvalid configuration type: zInvalid parameter value: r7   )rE   r*   rF   
ValueErrorr>   r    dictglobalsget	from_jsontyper-   r+   itemsr5   configuration_validator)r$   rG   	parameter
definition
child_typeparameter_validatorr*   s          r   r1   zConfigurationInternal.__init__b   s     !' ? ?	>)999$%P	%P%PQQQ!-in=
iot44 L!(y/B/B7D/Q/Q!R!RJ!)(L9?LL   '1&:&:9?&K&KIO!)/4
8P3Q3QRR T$%R%R%RSSS&0&:#**9?;; T$%R%R%RSSS5>"9>22 $ 0 6 6 8 8 	 	D*4---+AZ%=, , ,"4( 	$$&&&&&r   r!   c                 <    d| j                                          dS )NzConfiguration(r9   )rE   valuesr:   s    r   r;   zConfigurationInternal.__repr__   s"    > 2 9 9 ; ;>>>>r   _ConfigurationInternal__valuec                 Z    t          |t                    st          S | j        |j        k    S r/   )r>   r   r?   rE   )r$   rY   s     r   r@   zConfigurationInternal.__eq__   s,    '#899 	"!!!W%:::r   c                     dS )zPerform custom validation when parameters are dependent on each other.

        Raises an InvalidConfigurationError if the configuration is invalid.
        Nr   r:   s    r   rR   z-ConfigurationInternal.configuration_validator   s	     	r   c                 N    t          | j                                                  S )z,Returns the parameters of the configuration.)listrE   rX   r:   s    r   get_parametersz$ConfigurationInternal.get_parameters   s    D&--//000r   r*   c                     || j         vrt          d| d| j        j                   t	          t
          | j                             |                    }|S )zIReturns the parameter with the given name, or except if it doesn't exist.rI   z for configuration )rE   rK   	__class__r   r   r5   rN   )r$   r*   param_values      r   get_parameterz#ConfigurationInternal.get_parameter   sc    t)))]4]]DND[]]   143E3I3I$3O3OPPr   r    c                    || j         vrt          d|           | j         |         }| j        |         }|j        rt	          d|           |                    |          st          d| d|           ||_        dS )z:Sets the parameter with the given name to the given value.rI   zCannot set static parameter: zInvalid value for parameter z: N)rF   rK   rE   r,   r   r+   r    )r$   r*   r    rT   rS   s        r   set_parameterz#ConfigurationInternal.set_parameter   s    t'''>>>???%d+
&t,	 	O&'Mt'M'MNNN##E** 	MKDKKEKKLLL	r   c                 N    t          j        |                                           S )z5Returns the JSON representation of the configuration.)jsondumpsto_jsonr:   s    r   to_json_strz!ConfigurationInternal.to_json_str   s     z$,,..)))r   json_strc                     	 t          j        |          }n%# t           j        $ r t          d|           w xY w|r|                     |          n	 |             S )3Returns a configuration from the given JSON string.z1Unable to decode configuration from JSON string: )rf   loadsJSONDecodeErrorrK   rO   )clsrj   config_jsons      r   from_json_strz#ConfigurationInternal.from_json_str   sw    	*X..KK# 	 	 	NHNN  	 .9Cs}}[)))cceeCs    "9c                 j    d | j                                         D             }| j        j        |d<   |S )zKReturns the JSON compatible dictionary representation of the configuration.c                     i | ]@\  }}|t          |j        t                    r|j                                        n|j        AS r   )r>   r    r   rh   ).0r*   rS   s      r   
<dictcomp>z1ConfigurationInternal.to_json.<locals>.<dictcomp>   s[     
 
 
  i )/+@AA!)/))+++
 
 
r   rJ   )rE   rQ   r`   r   )r$   	json_dicts     r   rh   zConfigurationInternal.to_json   sH    
 
 $(#5#;#;#=#=	
 
 
	 "^4	'r   json_mapc                 &   | j         |                    dd          k    r t          d| j          d|d                    g }|                                D ]0\  }}|dk    r|                    t          ||                     1 | |          S )rl   rJ   Nz,Trying to instantiate configuration of type z from JSON with type r7   rG   )r   rN   rK   rQ   appendr5   )ro   rw   rG   r*   r    s        r   rO   zConfigurationInternal.from_json   s     <8<<6666us|uubjkrbsuu   
#>>++ 	N 	NKD%w4$eLLLMMMMsj))))r   r/   r!   N)!r   r   r   r   r   r2   r5   r3   r   r)   r	   r   r1   r;   rA   r'   r@   r   rR   r^   rb   r   intfloatrd   r   ri   classmethodr   rq   r   rh   rO   r   r   r   r   r   Z   s)        JJ 334444$s$;;<==== '  '8D1G,H#I  '  '  '  'D?# ? ? ? ?;f ; ; ; ; ;
    ^1%; < 1 1 1 1# *@    
 # 
 eCeT4I.J 
 t 
  
  
  
  *S * * * X* DS DT D D D X [D 
c3h 
 
 
 X
 *c3h *D * * * X [* * *r   c                   `   e Zd ZdZ edd dd           edd dd	           ed
d dd	           edd d e                       edd dd           edd dd           edd dd	           edd dd          dZed d            Ze	de
eef         defd            ZdS )!HNSWConfigurationInternalzxInternal representation of the HNSW configuration.
    Used for validation, defaults, serialization and deserialization.spacec                 4    t          | t                    o| dv S )N)l2ipcosine)r>   r2   r    s    r   <lambda>z"HNSWConfigurationInternal.<lambda>   s!    Juc$:$: %0// r   Tr   r0   ef_constructionc                 8    t          | t                    o| dk    S N   r>   r|   r   s    r   r   z"HNSWConfigurationInternal.<lambda>       Juc$:$:$Iuz r   d   	ef_searchc                 8    t          | t                    o| dk    S r   r   r   s    r   r   z"HNSWConfigurationInternal.<lambda>   r   r   Fnum_threadsc                 8    t          | t                    o| dk    S r   r   r   s    r   r   z"HNSWConfigurationInternal.<lambda>   r   r   Mc                 8    t          | t                    o| dk    S r   r   r   s    r   r   z"HNSWConfigurationInternal.<lambda>   r   r      resize_factorc                 8    t          | t                    o| dk    S r   )r>   r}   r   s    r   r   z"HNSWConfigurationInternal.<lambda>  s    Jue$<$<$K! r   333333?
batch_sizec                 8    t          | t                    o| dk    S r   r   r   s    r   r   z"HNSWConfigurationInternal.<lambda>  r   r   sync_thresholdc                 8    t          | t                    o| dk    S r   r   r   s    r   r   z"HNSWConfigurationInternal.<lambda>  r   r     )r   r   r   r   r   r   r   r   r!   Nc                    | j                             d          }| j                             d          }|rG|rGt          t          |j                  t          t          |j                  k    rt          d          d S d S d S )Nr   r   z7batch_size must be less than or equal to sync_threshold)rE   rN   r   r|   r    r   )r$   r   r   s      r   rR   z1HNSWConfigurationInternal.configuration_validator  s    '++L99
+//0@AA 		 S**++d38L.M.MMM+I  	 	 	 	 NMr   paramsc           	          ddddddddd	}g }|                                 D ]E\  }}||vrt          d
|           |                    t          ||         |                     F | |          S )zhReturns an HNSWConfiguration from a metadata dict containing legacy HNSW parameters. Used for migration.r   r   r   r   r   r   r   r   )z
hnsw:spacezhnsw:construction_efzhnsw:search_efzhnsw:Mzhnsw:num_threadszhnsw:resize_factorzhnsw:batch_sizezhnsw:sync_thresholdz$Invalid legacy HNSW parameter name: r7   )rQ   rK   rz   r5   )ro   r   
old_to_newrG   r*   r    s         r   from_legacy_paramsz,HNSWConfigurationInternal.from_legacy_params"  s     "$5) -"1+#3	
 	

 
!<<>> 	 	KD%:%% !N!N!NOOO&Jt,<EJJJ    s:r   r{   )r   r   r   r   r)   r   rF   r   rR   r~   r   r2   r   r   r   r   r   r   r   r      s       I I )(0 0
 
 
 32"II	
 
 
 -,II	
 
 
 /.II#)++	
 
 
 %$II	
 
 
 10 KK	
 
 
 .-II	
 
 
 21!II	
 
 
Y2 2Kh    X S#X 4    [  r   r   c                   f     e Zd ZdZddd e            ddddfdeded	ed
ededededef fdZ xZ	S )HNSWConfigurationInterfacezHNSW index configuration parameters.
    See https://docs.trychroma.com/guides#changing-the-distance-function for more information.
    r   r   r   r   r   r   r   r   r   r   r   r   r   c	                 P   t          d|          t          d|          t          d|          t          d|          t          d|          t          d|          t          d|          t          d	|          g}	t                                          |	
           d S )Nr   r7   r   r   r   r   r   r   r   ry   )r5   superr1   )r$   r   r   r   r   r   r   r   r   rG   r`   s             r   r1   z#HNSWConfigurationInterface.__init__G  s     #u==="(9QQQ"9EEE"[III"1555"}MMM"JGGG"(8OOO	

 	J/////r   )
r   r   r   r   r   r2   r|   r}   r1   __classcell__r`   s   @r   r   r   B  s          "$9;;""0 00 0 	0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0r   r   c                   ^    e Zd ZdZd edd d e                      iZed	d            ZdS )
CollectionConfigurationInternalzInternal representation of the collection configuration.
    Used for validation, defaults, and serialization / deserialization.hnsw_configurationc                 ,    t          | t                    S r/   )r>   r   r   s    r   r   z(CollectionConfigurationInternal.<lambda>k  s    Ju6O$P$P r   Tr0   r!   Nc                     d S r/   r   r:   s    r   rR   z7CollectionConfigurationInternal.configuration_validatorq      r   r{   )	r   r   r   r   r)   r   rF   r   rR   r   r   r   r   r   d  sy        K K 	55%PP3355	
 
 
K    X  r   r   c                   4     e Zd ZdZdee         f fdZ xZS ) CollectionConfigurationInterfacez3Configuration parameters for creating a collection.r   c                     |t                      }t          d|          g}t                                          |           dS )zInitializes a new instance of the CollectionConfiguration class.
        Args:
            hnsw_configuration: The HNSW configuration to use for the collection.
        Nr   r7   ry   )r   r5   r   r1   )r$   r   rG   r`   s      r   r1   z)CollectionConfigurationInterface.__init__}  sS    
 %!:!<!<"(<DVWWW

 	J/////r   )r   r   r   r   r	   r   r1   r   r   s   @r   r   r   z  sP        ==
084M+N 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0r   r   c                   J    e Zd Zd edd dd          iZed	d            ZdS )
$EmbeddingsQueueConfigurationInternalautomatically_purgec                 ,    t          | t                    S r/   )r>   r'   r   s    r   r   z-EmbeddingsQueueConfigurationInternal.<lambda>  s    Jud$;$; r   FTr0   r!   Nc                     d S r/   r   r:   s    r   rR   z<EmbeddingsQueueConfigurationInternal.configuration_validator  r   r   r{   )r   r   r   r)   rF   r   rR   r   r   r   r   r     sb        66&;;	 
  
  
K    X  r   r   )*abcr   rf   	overridesr   typingr   r   r   r   r	   r
   r   r   r   typing_extensionsr   multiprocessingr   chromadb.serder   	Exceptionr   rK   r   r2   r|   r}   r'   r&   r   r)   r5   rB   r   r   r   HNSWConfigurationr   r   CollectionConfigurationr   r   r   r   <module>r      s               
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 # " " " " " % % % % % % + + + + + +
	 	 	 	 	9 	 	 		 	 	 	 	
 	 	 	 sC.EEF$ $ $ $ $ $ $ $+ + + + + + + +*I I I I I I I I& GC.///* * * * *,-DE * * *D_ _ _ _ _ 5 _ _ _L0 0 0 0 0!: 0 0 0> /     &;   ,0 0 0 0 0'F 0 0 0" ;     +@     r   