� ���g+;����ddlmZddlZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZGd�d e��ZGd �d e��Ze eeeed fZGd �de ��ZGd�d��ZGd�d��Z e dd ���Z!Gd�d ed ��Z"Gd�de"��Z#Gd�de#��Z$e$Z%Gd�de"��Z&Gd�de&��Z'e'Z(Gd�de"��Z)dS) �)�abstractmethodN)�override) �Any�ClassVar�Dict�List�Optional�Protocol�Union�TypeVar�cast)�Self)� cpu_count)�JSONSerializablec��eZdZdZdS)�StaticParameterErrorz?Represents an error that occurs when a static parameter is set.N��__name__� __module__� __qualname__�__doc__���j/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/chromadb/api/configuration.pyrrs������I�I��Drrc��eZdZdZdS)�InvalidConfigurationErrorz@Represents an error that occurs when a configuration is invalid.Nrrrrrrs������J�J��Drr�ConfigurationInternalc�2�eZdZdZededefd���ZdS)�ParameterValidatorz+Represents an abstract parameter validator.�value�returnc��t���)z)Returns whether the given value is valid.)�NotImplementedError)�selfr s r�__call__zParameterValidator.__call__)s��"�#�#�#rN)rrrrr�ParameterValue�boolr%rrrrr&sF������5�5��$�n�$��$�$�$��^�$�$�$rrc�T�eZdZUdZeed<eed<eed<eed<dedededefd�Z dS)�ConfigurationDefinitionz-Represents the definition of a configuration.�name� validator� is_static� default_valuec�>�||_||_||_||_dS�N�r*r+r,r-)r$r*r+r,r-s r�__init__z ConfigurationDefinition.__init__7s'���� �"���"���*����rN) rrrr�str�__annotations__rr'r&r1rrrr)r)/s��������7�7� �I�I�I�!�!�!�!��O�O�O�!�!�!�!� +�� +�&� +�� +� &� +� +� +� +� +� +rr)c�T�eZdZUdZeed<eed<dedefd�Zdefd�Zde de fd�Z d S) �ConfigurationParameterz*Represents a parameter of a configuration.r*r c�"�||_||_dSr/�r*r )r$r*r s rr1zConfigurationParameter.__init__Js���� ��� � � rr!c�(�d|j�d|j�d�S)NzConfigurationParameter(z, �)r7�r$s r�__repr__zConfigurationParameter.__repr__Ns��C���C�C�d�j�C�C�C�Cr�_ConfigurationParameter__valuec�z�t|t��stS|j|jko|j|jkSr/)� isinstancer5�NotImplementedr*r )r$r<s r�__eq__zConfigurationParameter.__eq__Qs8���'�#9�:�:� "�!� !��y�G�L�(�H�T�Z�7�=�-H�HrN) rrrrr2r3r&r1r;�objectr'r@rrrr5r5Ds��������4�4� �I�I�I� �����S�������D�#�D�D�D�D�I�f�I��I�I�I�I�I�Irr5�T)�boundc��eZdZUdZeeefed<eeee fed<dde e efd�Z defd�Z d edefd �Zedd ���Zde efd �Zd edefd�Zd edeeeeefddfd�Zedefd���Zeededefd�����Zedeeeffd���Zeedeeefdefd�����Z dS)rz@Represents an abstract configuration, used internally by Chroma.� parameter_map� definitionsN� parametersc�X�i|_|��E|D�]A}|j|jvrtd|j�����|j|j}t |jt ��rrt���|j�dd����}|�td|j�����|� |j��|_t |jt|j ����std|j�����|j }||j��std|j�����||j|j<��C|j� ��D],\}}||jvrt||j ���|j|<�-|���dS)zbInitializes a new instance of the Configuration class. Respecting defaults and validators.N�Invalid parameter name: �_typezInvalid configuration type: zInvalid parameter value: r7)rEr*rF� ValueErrorr>r �dict�globals�get� from_json�typer-r+�itemsr5�configuration_validator)r$rG� parameter� definition� child_type�parameter_validatorr*s rr1zConfigurationInternal.__init__bs��� ��� � !�'� ?� ?� ��>��)9�9�9�$�%P� ��%P�%P�Q�Q�Q�!�-�i�n�=� ��i�o�t�4�4�L�!(�����y��/B�/B�7�D�/Q�/Q�!R�!R�J�!�)�(�L�9�?�L�L����'1�&:�&:�9�?�&K�&K�I�O�!�)�/�4� �8P�3Q�3Q�R�R�T�$�%R���%R�%R�S�S�S�&0�&:�#�*�*�9�?�;�;�T�$�%R���%R�%R�S�S�S�5>��"�9�>�2�2� $� 0� 6� 6� 8� 8� � � �D�*��4�-�-�-�+A��Z�%=�,�,�,��"�4�(�� �$�$�&�&�&�&�&rr!c�<�d|j����d�S)NzConfiguration(r9)rE�valuesr:s rr;zConfigurationInternal.__repr__�s"��>�� 2� 9� 9� ;� ;�>�>�>�>r�_ConfigurationInternal__valuec�Z�t|t��stS|j|jkSr/)r>rr?rE)r$rYs rr@zConfigurationInternal.__eq__�s,���'�#8�9�9� "�!� !��!�W�%:�:�:rc��dS)z�Perform custom validation when parameters are dependent on each other. Raises an InvalidConfigurationError if the configuration is invalid. Nrr:s rrRz-ConfigurationInternal.configuration_validator�s �� �rc�N�t|j�����S)z,Returns the parameters of the configuration.)�listrErXr:s r�get_parametersz$ConfigurationInternal.get_parameters�s���D�&�-�-�/�/�0�0�0rr*c��||jvrtd|�d|jj�����t t |j�|����}|S)zIReturns the parameter with the given name, or except if it doesn't exist.rIz for configuration )rErK� __class__rr r5rN)r$r*� param_values r� get_parameterz#ConfigurationInternal.get_parameter�sc�� �t�)� )� )��]�4�]�]�D�N�D[�]�]��� ��1�4�3E�3I�3I�$�3O�3O�P�P� ��rr c��||jvrtd|�����|j|}|j|}|jrt d|�����|�|��std|�d|�����||_dS)z:Sets the parameter with the given name to the given value.rIzCannot set static parameter: zInvalid value for parameter z: N)rFrKrEr,rr+r )r$r*r rTrSs r� set_parameterz#ConfigurationInternal.set_parameter�s��� �t�'� '� '��>��>�>�?�?� ?��%�d�+� ��&�t�,� � � � O�&�'M�t�'M�'M�N�N� N��#�#�E�*�*� M��K�D�K�K�E�K�K�L�L� L�� ���rc�N�tj|�����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�� tj|��}n%#tj$rtd|�����wxYw|�|��S)�3Returns a configuration from the given JSON string.z1Unable to decode configuration from JSON string: )rf�loads�JSONDecodeErrorrKrO)�clsrj� config_jsons r� from_json_strz#ConfigurationInternal.from_json_str�sg�� ��*�X�.�.�K�K���#� � � ��N�H�N�N��� � �����}�}�[�)�)�)s��"9c�j�d�|j���D��}|jj|d<|S)zKReturns the JSON compatible dictionary representation of the configuration.c��i|]@\}}|t|jt��r|j���n|j��ASr)r>r rrh)�.0r*rSs r� <dictcomp>z1ConfigurationInternal.to_json.<locals>.<dictcomp>�s[�� � � � ��i� ��)�/�+@�A�A�!�)�/�)�)�+�+�+��� � � rrJ)rErQr`r)r$� json_dicts rrhzConfigurationInternal.to_json�sH�� � �$(�#5�#;�#;�#=�#=�  � � � �"�^�4� �'���r�json_mapc�&�|j|�dd��kr td|j�d|d�����g}|���D]0\}}|dkr� |�t ||������1||���S)rlrJNz,Trying to instantiate configuration of type z from JSON with type r7�rG)rrNrKrQ�appendr5)rorwrGr*r s rrOzConfigurationInternal.from_json�s��� �<�8�<�<���6�6� 6� 6��u�s�|�u�u�bj�kr�bs�u�u��� �� �#�>�>�+�+� N� N�K�D�%��w���� � � �4�$�e�L�L�L� M� M� M� M��s�j�)�)�)�)rr/�r!N)!rrrrrr2r5r3rr)r rr1r;rAr'r@rrRr^rbr �int�floatrdrri� classmethodrrqrrhrOrrrrrZs#�������J�J���3�3�4�4�4�4��$�s�$;�;�<�=�=�=�=� '� '�8�D�1G�,H�#I� '� '� '� '�D?�#�?�?�?�?�;�f�;��;�;�;�;� � � � ��^� �1��%;� <�1�1�1�1��#��*@�����  �#�  �e�C��e�T�4I�.J�  �t�  �  �  �  ��*�S�*�*�*��X�*�� �*�S�*�T�*�*�*��X��[�*�� ��c�3�h�� � � ��X� �� � *��c�3�h�� *�D� *� *� *��X��[� *� *� *rc �`�eZdZdZedd�dd���edd�dd ���ed d �d d ���ed d�d e�����edd�dd���edd�dd���edd�dd ���edd�dd���d�Zed d���Ze de e e fde fd���ZdS)!�HNSWConfigurationInternalzxInternal representation of the HNSW configuration. Used for validation, defaults, serialization and deserialization.�spacec�4�t|t��o|dvS)N)�l2�ip�cosine)r>r2�r s r�<lambda>z"HNSWConfigurationInternal.<lambda>�s!��J�u�c�$:�$:�%0��/�/�rTr�r0�ef_constructionc�8�t|t��o|dkS�N��r>r|r�s rr�z"HNSWConfigurationInternal.<lambda>����J�u�c�$:�$:�$I�u��z�r�d� ef_searchc�8�t|t��o|dkSr�r�r�s rr�z"HNSWConfigurationInternal.<lambda>�r�rF� num_threadsc�8�t|t��o|dkSr�r�r�s rr�z"HNSWConfigurationInternal.<lambda>�r�r�Mc�8�t|t��o|dkSr�r�r�s rr�z"HNSWConfigurationInternal.<lambda>�r�r�� resize_factorc�8�t|t��o|dkSr�)r>r}r�s rr�z"HNSWConfigurationInternal.<lambda>s��J�u�e�$<�$<�$K��!��r�333333�?� batch_sizec�8�t|t��o|dkSr�r�r�s rr�z"HNSWConfigurationInternal.<lambda>r�r�sync_thresholdc�8�t|t��o|dkSr�r�r�s rr�z"HNSWConfigurationInternal.<lambda>r�r��)r�r�r�r�r�r�r�r�r!Nc��|j�d��}|j�d��}|rG|rGtt|j��tt|j��krt d���dSdSdS)Nr�r�z7batch_size must be less than or equal to sync_threshold)rErNr r|r r)r$r�r�s rrRz1HNSWConfigurationInternal.configuration_validators����'�+�+�L�9�9� ��+�/�/�0@�A�A�� � �� ��S�*�*�+�+�d�3��8L�.M�.M�M�M�+�I��� �  � � � �N�Mr�paramsc ���ddddddddd �}g}|���D]E\}}||vrtd |�����|�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:spacezhnsw:construction_efzhnsw:search_efzhnsw:Mzhnsw:num_threadszhnsw:resize_factorzhnsw:batch_sizezhnsw:sync_thresholdz$Invalid legacy HNSW parameter name: r7)rQrKrzr5)ror�� old_to_newrGr*r s r�from_legacy_paramsz,HNSWConfigurationInternal.from_legacy_params"s���"�$5�)�� -�"1�+�#3�  �  � �� �!�<�<�>�>� � �K�D�%��:�%�%� �!N��!N�!N�O�O�O� � � �&�J�t�,<�E�J�J�J� � � � ��s�:���rr{)rrrrr)rrFrrRr~rr2rrr�rrrr�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���  � � �Y2�2�K�h� � � ��X� ����S�#�X���4�����[���rr�c�f��eZdZdZddde��ddddfdeded ed ed ed ed edef�fd� Z�xZ S)�HNSWConfigurationInterfacez�HNSW 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��td|���td|���td|���td|���td|���td|���td|���td |���g} t���| � ��dS) Nr�r7r�r�r�r�r�r�r�ry)r5�superr1) r$r�r�r�r�r�r�r�r�rGr`s �rr1z#HNSWConfigurationInterface.__init__Gs���� #��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) rrrrrr2r|r}r1� __classcell__�r`s@rr�r�Bs���������� �"��$�9�;�;��"��"�0�0��0��0�� 0� � 0� � 0��0��0��0�0�0�0�0�0�0�0�0�0rr�c�^�eZdZdZdedd�de�����iZed d���ZdS) �CollectionConfigurationInternalz�Internal representation of the collection configuration. Used for validation, defaults, and serialization / deserialization.�hnsw_configurationc�,�t|t��Sr/)r>r�r�s rr�z(CollectionConfigurationInternal.<lambda>ks��J�u�6O�$P�$P�rTr0r!Nc��dSr/rr:s rrRz7CollectionConfigurationInternal.configuration_validatorq��� �rr{) rrrrr)r�rFrrRrrrr�r�dsy������K�K� �5�5�%�P�P��3�3�5�5�  � � ��K�� � � ��X� � � rr�c�4��eZdZdZdeef�fd� Z�xZS)� CollectionConfigurationInterfacez3Configuration parameters for creating a collection.r�c���|�t��}td|���g}t���|���dS)z�Initializes a new instance of the CollectionConfiguration class. Args: hnsw_configuration: The HNSW configuration to use for the collection. Nr�r7ry)r�r5r�r1)r$r�rGr`s �rr1z)CollectionConfigurationInterface.__init__}sS��� � %�!:�!<�!<� � "�(<�DV� W� W� W� � � �����J��/�/�/�/�/r)rrrrr r�r1r�r�s@rr�r�zsP�������=�=� 0�8�4M�+N� 0� 0� 0� 0� 0� 0� 0� 0� 0� 0rr�c�J�eZdZdedd�dd���iZed d���ZdS) �$EmbeddingsQueueConfigurationInternal�automatically_purgec�,�t|t��Sr/)r>r'r�s rr�z-EmbeddingsQueueConfigurationInternal.<lambda>�s��J�u�d�$;�$;�rFTr0r!Nc��dSr/rr:s rrRz<EmbeddingsQueueConfigurationInternal.configuration_validator�r�rr{)rrrr)rFrrRrrrr�r��sb�������6�6�&�;�;���  � � ��K�� � � ��X� � � rr�)*�abcrrf� overridesr�typingrrrrr r r r r �typing_extensionsr�multiprocessingr�chromadb.serder� ExceptionrrKrr2r|r}r'r&rr)r5rBrr�r��HNSWConfigurationr�r��CollectionConfigurationr�rrr�<module>r�s�������� � � � ������� � � � � � � � � � � � � � � � � � � � � � �#�"�"�"�"�"�%�%�%�%�%�%�+�+�+�+�+�+�  � � � � �9� � � �  � � � � � � � � � �s�C���.E�E�F��$�$�$�$�$��$�$�$�+�+�+�+�+�+�+�+�*I�I�I�I�I�I�I�I�& �G�C�.�/�/�/��*�*�*�*�*�,�-D�E�*�*�*�D_�_�_�_�_� 5�_�_�_�L0�0�0�0�0�!:�0�0�0�>/�� � � � � �&;� � � �, 0� 0� 0� 0� 0�'F� 0� 0� 0�";��  �  �  �  �  �+@�  �  �  �  �  r
Memory