Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
client.cpython-313.pyc385 linesDownload Raw Back to __pycache__
1�

2��j`��d�SSKJrJr SSKJr SSKJr SSKJr SSK	r	SSK3JrJrJ
r
 SSKJrJrJrJr SSKJr SS	KJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r' SS4K(J)r) SSK*J+r+ SSK,J-r-J.r. SS
K,J/r/J0r0 SSK1J2r2 SSK3J4r4J5r5 SSK6J7r7J8r8J9r9J:r: "SS\\5r;"SS\\5r<g)�)�Optional�Sequence)�
TracebackType)�UUID)�overrideN)�AdminAPI�	ClientAPI�	ServerAPI)�CreateCollectionConfiguration�UpdateCollectionConfiguration�.validate_embedding_function_conflict_on_create�+validate_embedding_function_conflict_on_get)�SharedSystemClient)�CollectionMetadata�5DataLoader�	Documents�6Embeddable�EmbeddingFunction�7Embeddings�	GetResult�IDs�Include�Loadable�	Metadatas�QueryResult�Schema�URIs�IncludeMetadataDocuments�!IncludeMetadataDocumentsDistances�DefaultEmbeddingFunction�DeleteResult)�UserIdentity)�maybe_set_tenant_and_database)�Settings�System)�DEFAULT_TENANT�DEFAULT_DATABASE)�8Collection)�ChromaAuthError�ChromaError)�Database�Tenant�Where�
WhereDocumentc�`^�\rSrSr%Sr\r\\S'\	r9\\S'\\S'\\S'Sr
\\S'\\	\"54S\\S\\S	\S10S4U4Sjjjr\\\\	4S
\S\S\S11S4Sjj55r\S12\4Sj5r\S13\4Sj5r\SIS\\S\\S14\\4Sjj5r\S15\4Sj5r\SSS\"5SS4S\S\\S\\ S\\!S\\"\#S\\$\%S\S16\4Sjj5r&\\"5S4S\S\\"\#S\\$\%S17\4Sjj5r'\\"5S4S\(S\\"\#S\\$\%S18\4Sjj5r)\SSS\"5S4S\S\\S\\ S\\!S\\"\#S\\$\%S19\4S jj5r*\SJS\(S!\\S"\\!S#\\+S20S421S$jj5r,\S\S22S4S%j5r-\SJS&\.S'\(S(\/S)\\0S*\\1S+\\2S23\4S,jj5r3\SKS'\(S&\.S(\\/S)\\0S*\\1S+\\2S24\4S-jj5r4\SJS'\(S&\.S(\/S)\\0S*\\1S+\\2S25\4S.jj5r5\S'\(S26\4S/j5r6\SLS'\(S1\S27\74S2jj5r8\SSSSS\94S'\(S&\\.S3\\:S\\S\\S4\\;S5\<S28\74S6jj5r=SJS'\(S&\\.S3\\:S4\\;S\\S29\>4S7jjr?\SS0SS\@4S'\(S8\/S&\\.S9\S3\\:S4\\;S5\<S30\A4S:jj5rB\S31\4S;j5rC\S32\4S<j5rD\S33\4S=j5rE\S34\4S>j5rF\\	4S\S\S35S4S?jj5rG\S\S36S4S@j5rHSMSAjrISNSBjrJSC\\K\LSD\\LSE\\MS37S4SFjrNS\S\S38S4SGjrOSHrPU=rQ$)O�Client�,a�A client for Chroma. This is the main entrypoint for interacting with Chroma.39A client internally stores its tenant and database and proxies calls to a40Server API instance of Chroma. It treats the Server API and corresponding System41as a singleton, so multiple clients connecting to the same resource will share the42same API instance.43 44Client implementations should be implement their own API-caching strategies.45�tenant�database�_server�
_admin_clientF�_closed�settings�returnNc��>�[TU]US9 UbXlUbX lURR[5UlUR5n[UURUUS9upVUcUc[S5eUcUc[S5eU(aXPlU(aX`l[RUR5UlURURURS9 UR!5 g!["a] [%US5(a*[&R("URR*5 [&R("UR*5 ef=f)N�r7)�4overwrite_singleton_tenant_database_access_from_auth�user_provided_tenant�user_provided_databasez]Could not determine a tenant from the current authentication method. Please provide a tenant.zkCould not determine a database name from the current authentication method. Please provide a database name.�r2r3r5)�super�__init__r2r3�_system�instancer46r4�get_user_identityr#�;chroma_overwrite_singleton_tenant_database_access_from_authr)�AdminClient�from_systemr5�_validate_tenant_database�_submit_client_start_event�	Exception�hasattrr�_release_system�_identifier)�selfr2r3r7�
user_identity�maybe_tenant�maybe_database�	__class__s       ��YD:\code\apps\devtools\python\user_packages\Python313\site-packages\chromadb/api/client.pyr@�Client.__init__?sZ���	���(��+�-	��!�$���#� (�
� �<�<�0�0��;�D�L� �2�2�4�M�+H��EM�FJ�FJ�%+�'/�	,�(�L��#���%�s����%�(�*:�%�B����*��� .�
�"-�!8�!8����!F�D���*�*�$�+�+��
�
�*�V��+�+�-���	��t�_�-�-�"�2�2�4�3E�3E�3Q�3Q�R��.�.�t�/?�/?�@��	�s
�C2D�A'E*�systemc�T�[R"U5 U"X#URS9nU$)N)r2r3r7�r�_populate_data_from_systemr7)�clsrTr2r3rBs     rRrF�Client.from_systemus'��	�5�5�f�=��f�&�/�/�R����c���URR5$![Ra [	S5e[47anUeSnAf[an[	[U55eSnAff=f)N�ACould not connect to a Chroma server. Are you sure it is running?)r4rC�httpx�ConnectError�48ValueErrorr*rI�str)rM�es  rRrC�Client.get_user_identity�sg��49	%��<�<�1�1�3�3���!�!�	��S��
��	��G���	%��S��V�$�$��	%�s!��(A,�A�
A,�A'�'A,c�6�URR5$)z2Return the server time in nanoseconds since epoch.)r4�	heartbeat�rMs rRrd�Client.heartbeat�s���|�|�%�%�'�'rZ�limit�offsetc��URRXURURS9Vs/sHn[	URUS9PM sn$s snf)z�List collections for the current tenant and database, with pagination.50 51Returns:52    Sequence[Collection]: Collection objects for the current tenant.53r>)�client�model)r4�list_collectionsr2r3r()rMrgrhrks    rRrl�Client.list_collections�s[�����6�6��d�k�k�D�M�M�7��54���
�d�l�l�%�8��55�	56��57s�Ac�^�URRURURS9$)z9Return the number of collections in the current database.r>)r4�count_collectionsr2r3res rRro�Client.count_collections�s-���|�|�-�-��;�;����.�58�	59rZ�name�schema�
configuration�metadata�embedding_function�data_loader�
get_or_createc60���Uc0nURS5n[XX5 UbUcXSS'URRUUUURUR61UUS9n	[
URU	UUS9$)a�Create a collection with optional configuration and metadata.62 63If using a schema, do not provide `embedding_function`. Instead,64provide the `embedding_function` as part of the schema.65 66Args:67    name: Collection name.68    schema: Optional collection schema for indexes and encryption.69    configuration: Optional collection configuration.70    metadata: Optional collection metadata.71    embedding_function: Optional embedding function for the collection.72    data_loader: Optional data loader for documents with URIs.73    get_or_create: Whether to return an existing collection if present.74 75Returns:76    Collection: The created collection.77 78Raises:79    ValueError: If the embedding function conflicts with configuration.80ru)rqrrrtr2r3rwrs�rjrkrurv)�getr
r4�create_collectionr2r3r()81rMrqrrrsrtrurvrw�configuration_efrks82          rRr{�Client.create_collection�s���B� ��M�(�,�,�-A�B��6��	83��)�.>�.F�2D�.�/����.�.�����;�;��]�]�'�'�/�84����<�<��1�#�	85�	86rZc���URRUURURS9nURRS5n[
X%5 [URUUUS9$)aHGet a collection by name.87 88Args:89    name: Collection name.90    embedding_function: Optional embedding function for the collection.91    data_loader: Optional data loader for documents with URIs.92 93Returns:94    Collection: The requested collection.95 96Raises:97    ValueError: If the embedding function conflicts with configuration.98�rqr2r3rury)r4�get_collectionr2r3�configuration_jsonrzrr()rMrqrurvrk�persisted_ef_configs      rRr��Client.get_collection�sr��,���+�+���;�;��]�]�,�99��100$�6�6�:�:�;O�P��3��	101���<�<��1�#�	102�	103rZ�idc���URRUURURS9nURRS5n[
X%5 [URUUUS9$)aSGet a collection by its ID.104 105Args:106    id: The UUID of the collection.107    embedding_function: Optional embedding function for the collection.108    data_loader: Optional data loader for documents with URIs.109 110Returns:111    Collection: The requested collection.112 113Raises:114    ValueError: If the embedding function conflicts with configuration.115��
collection_idr2r3rury)r4�get_collection_by_idr2r3r�rzrr()rMr�rurvrkr�s      rRr��Client.get_collection_by_idsr��,���1�1���;�;��]�]�2�116��117$�6�6�:�:�;O�P��3��	118���<�<��1�#�	119�	120rZc	�4�Uc0nURS5n[XW5 UbUcXSS'URRUUUURUR121US9nURRS5n	[XY5 [URUUUS9$)a�Get an existing collection or create a new one.122 123If the collection does not exist, it will be created. If the collection124already exists, the schema, configuration, and metadata arguments125will be ignored.126 127Args:128    name: Collection name.129    schema: Optional collection schema for indexes and encryption.130    configuration: Optional collection configuration.131    metadata: Optional collection metadata.132    embedding_function: Optional embedding function for the collection.133    data_loader: Optional data loader for URI-backed data.134 135Returns:136    Collection: The existing or newly created collection.137 138Raises:139    ValueError: If the embedding function does not match the collection's embedding function.140ru)rqrrrtr2r3rsry)	rzr
r4�get_or_create_collectionr2r3r�rr()141rMrqrrrsrtrurvr|rkr�s142          rRr��Client.get_or_create_collection>s���@� ��M�(�,�,�-A�B��6��	143��)�.>�.F�2D�.�/����5�5�����;�;��]�]�'�
6�144��$�6�6�:�:�;O�P��3��	145���<�<��1�#�	146�	147rZ�new_name�new_metadata�new_configurationc	�f�URRUURURUUUS9$)N)r�r2r3r�r�r�)r4�_modifyr2r3)rMr�r�r�r�s     rRr��Client._modifys:���|�|�#�#���;�;��]�]��%�/�
$�148�	149rZc�`�URRUURURS9$)Nr)r4�delete_collectionr2r3�rMrqs  rRr��Client.delete_collection�s1��150�|�|�-�-���;�;��]�]�.�151�	152rZ�idsr��153embeddings�	metadatas�	documents�urisc�j�URRUURURUUUUUS9$)N)r�r2r3r�r�r�r�r�)r4�_addr2r3)rMr�r�r�r�r�r�s       rRr��Client._add�s@���|�|� � ���;�;��]�]�'�!����!�	154�		155rZc�j�URRUURURUUUUUS9$�N)r�r2r3r�r�r�r�r�)r4�_updater2r3�rMr�r�r�r�r�r�s       rRr��Client._update��@���|�|�#�#�'��;�;��]�]��!����$�	156�		157rZc�j�URRUURURUUUUUS9$r�)r4�_upsertr2r3r�s       rRr��Client._upsert�r�rZc�`�URRUURURS9$)Nr�)r4�_countr2r3)rMr�s  rRr��
Client._count�s/���|�|�"�"�'��;�;��]�]�#�158�	159rZ�160�nc�b�URRUUURURS9$)N)r�r�r2r3)r4�_peekr2r3)rMr�r�s   rRr��Client._peek�s2���|�|�!�!�'���;�;��]�]�	"�161�	162rZ�where�where_document�includec�l�URRUURURUUUUUUS9	$)N)	r�r2r3r�r�rgrhr�r�)r4�_getr2r3)rMr�r�r�rgrhr�r�s        rRr��Client._get�sC���|�|� � �'��;�;��]�]�����)��!�163164�165	166rZc167�h�URRUURURUUUUS9$)N)r�r2r3r�r�r�rg)r4�_deleter2r3)rMr�r�r�r�rgs      rRr��Client._deletes=���|�|�#�#�'��;�;��]�]���)��$�168�	169rZ�query_embeddings�	n_resultsc�l�URRUUURURUUUUUS9	$)N)	r�r�r2r3r�r�r�r�r�)r4�_queryr2r3)rMr�r�r�r�r�r�r�s        rRr��
Client._querysC���|�|�"�"�'���;�;��]�]�-���)��#�170171�172	173rZc�6�URR5$�N)r4�resetres rRr��Client.reset/s���|�|�!�!�#�#rZc�6�URR5$r�)r4�get_versionres rRr��Client.get_version3s���|�|�'�'�)�)rZc�6�URR5$r�)r4�get_settingsres rRr��Client.get_settings7s���|�|�(�(�*�*rZc�6�URR5$r�)r4�get_max_batch_sizeres rRr��Client.get_max_batch_size;s���|�|�.�.�0�0rZc�:�URXS9 XlX lg�Nr>�rGr2r3)rMr2r3s   rR�174set_tenant�Client.set_tenantCs���&�&�f�&�H��� �
rZc�D�URURUS9 Xlgr�r�)rMr3s  rR�set_database�Client.set_databaseIs���&�&�d�k�k�H�&�M� �
rZc���UR(agSUl[US5(a*[R"URR1755 [R"UR1765 g)aNClose the client and release all resources.177 178This method decrements the reference count for the underlying System.179When the last client using a shared System calls close(), the System180is stopped and all resources (database connections, etc.) are released.181 182This is particularly important for PersistentClient to avoid SQLite183file locking issues.184 185Note: If multiple clients share the same System (e.g., multiple PersistentClient186instances with the same path), the System will only be stopped when the last187client is closed. This allows safe use of context managers with multiple clients.188 189Example:190    >>> client = chromadb.PersistentClient(path="./chroma_db")191    >>> # ... use client ...192    >>> client.close()193 194    Or using context manager:195    >>> with chromadb.PersistentClient(path="./chroma_db") as client:196    ...     # ... use client ...197NTr5)r6rJrrKr5rLres rR�close�Client.closeNsT��0�<�<������4��)�)��.�.�t�/A�/A�/M�/M�N�	�*�*�4�+;�+;�<rZc��U$)zContext manager entry.�res rR�	__enter__�Client.__enter__rs���rZ�exc_type�exc_val�exc_tbc�$�UR5 g)zContext manager exit.N)r�)rMr�r�r�s    rR�__exit__�Client.__exit__vs
��	
�198�199�rZc�F�URRUS9 URRX!S9 g![Ra [	S5e[200anUeSnAf[a [	SUS35ef=f![Ra [	S5ef=f)N�rqr\zCould not connect to tenant z. Are you sure it exists?�rqr2)r5�201get_tenantr]r^r_r*rI�get_database)rMr2r3ras    rRrG� Client._validate_tenant_databases���	����)�)�v�)�6�	����+�+��+�I���!�!�	��S��
��	��G���	��.�v�h�6O�P��
�	���!�!�	��S��
�	�s �6�B�(A=�A � A=� B )r5r6r4r3r2)NN)NNN)NNNN)r�)r8N)r8r0)R�__name__�202__module__�__qualname__�__firstlineno__�__doc__r&r2r`�__annotations__r'r3r203rr6�boolr$rr@�classmethodrr%rFr"rC�intrdrr(rlror rrrrrrrr{r�rr�r�rr�r�rrrrrr�r�r�r�rr�rr-r.rr�r!r�rrr�r�r�r�r�r�r�r�r��type�
BaseExceptionrr�rG�__static_attributes__�
__classcell__�rQs@rRr0r0,s�����!�F�C� �$�H�c�$�
�����G�T��204!/�"2�%�Z�	4���
�4��3�-�4��	4�205206�4�4�l�
�%�(�	������	�207208������%�<�%��%��(�3�(��(��CG�
209��c�]�
210�3;�C�=�
211�	�*�	�
212��
213��214�3�215��216��$(�AE�15�
%�&�6:�#�<217��<218��� �<219� � =�>�	<220�221�-�.�<222�%��j�)�223�
<224��j��2�3�<225��<226�227�<228��<229�|�
%�&�6:�
%230��%231�%��j�)�232�%233��j��2�3�
%234�235�%236��%237�N�
%�&�6:�
%238��%239�%��j�)�240�%241��j��2�3�
%242�243�%244��%245�N�$(�AE�15�
%�&�6:�>246��>247��� �>248� � =�>�	>249�250�-�.�>251�%��j�)�252�
>253��j��2�3�>254�255�>256��>257�@�#'�59�EI�258��259��3�-�260��1�2�	261�262$�$A�B�263�264�
265��266� �267��268�269�270��271��*.�)-�#�272�
�273��274��	275�276�I�&�277��I�&�
278��t�n�279�280�281��282�(�283,0�)-�)-�#�284��285��286��Z�(�	287�288�I�&�289��I�&�
290��t�n�291�292�293��294�(�*.�)-�#�295��296��297��	298�299�I�&�300��I�&�
301��t�n�302�303�304��305�(�306�D�307�S�308��309��310�4�311�C�312��313��314��"�!%�#� $�26�3�315��316��c�]�317����	318�319��}�320���
�
321�!��/�322��323�324�325��326�4"&�26�#�
327��328��c�]�329����	330�331!��/�332���}�
333�334�335�$�336"��!%�26�<�337��338�%�339��c�]�	340�341�342����
343�!��/�344��345�346�347��348�,�$�t�$��$��*�S�*��*��+�h�+��+��1�C�1��1��6F�!��!��!�4�!��!�349�!�S�!�T�!��!�"=�H���4�
�.�/���-�(����'�	�350351�����s��t��rZr0c�d^�\rSrSr%Sr\\S'\"54S\SS4U4Sjjjr\	\3524S\S	\SS4S353jj5r\	\3544S\S	\S\
4Sjj5r\	\3554S\S	\SS4Sjj5r\	SS\3564S
\\S\\S	\S\\
4Sjj5r\	S\SS4Sj5r\	S\S\4Sj5r\\	S\SS4Sj55rSrU=r$)rEi�z0Admin client for managing tenants and databases.r4r7r8Nc�l>�[TU]U5 URR[5Ulgr�)r?r@rArBr357r4)rMr7rQs  �rRr@�AdminClient.__init__�s&���
����"��|�|�,�,�Y�7��rZrqr2c�4�URRXS9$)zjCreate a database in a tenant.358 359Args:360    name: Database name.361    tenant: Tenant that owns the database.362r�)r4�create_database�rMrqr2s   rRr��AdminClient.create_database�����|�|�+�+��+�E�ErZc�4�URRXS9$)z�Get a database by name.363 364Args:365    name: Database name.366    tenant: Tenant that owns the database.367 368Returns:369    Database: The database record.370r�)r4r�r�s   rRr��AdminClient.get_database�s���|�|�(�(�d�(�B�BrZc�4�URRXS9$)zfDelete a database by name.371 372Args:373    name: Database name.374    tenant: Tenant that owns the database.375r�)r4�delete_databaser�s   rRr��AdminClient.delete_database�r�rZrgrhc�6�URRXUS9$)N)r2)r4�list_databases)rMrgrhr2s    rRr�AdminClient.list_databases�s���|�|�*�*�5��*�H�HrZc�4�URRUS9$�Nr�)r4�
create_tenantr�s  rRr�AdminClient.create_tenant�s���|�|�)�)�t�)�4�4rZc�4�URRUS9$r)r4r�r�s  rRr��AdminClient.get_tenant�s���|�|�&�&�D�&�1�1rZrTc�R�[R"U5 U"URS9nU$)Nr:rV)rXrTrBs   rRrF�AdminClient.from_system�s%��	�5�5�f�=�����0���rZ)r4)r�r�r�r�r�r376r�r$r@rr&r`r�r+r�r�rr�rrrr,r�r�r%rFr�r�r�s@rRrErE�s����:�
��,4�J�8��8�4�8�8��7E�F�C�F��F�$�F��F��4B�377C��378C�c�379C�x�380C��381C��7E�F�C�F��F�$�F��F�� $� $�$�	I���}�I���
�I��	I�382383�(�	�I��I��5�#�5�$�5��5��2�s�2�v�2��2��
����384����rZrE)=�typingrr�typesr�uuidr�	overridesrr]�chromadb.apirr	r385�%chromadb.api.collection_configurationrrr
r�!chromadb.api.shared_system_clientr�chromadb.api.typesrrrrrrrrrrrrrrrrr r!�
chromadb.authr"�chromadb.auth.utilsr#�chromadb.configr$r%r&r'�chromadb.api.models.Collectionr(�chromadb.errorsr)r*�chromadb.typesr+r,r-r.r0rEr�rZrR�<module>rs���%�����7�7���A������('�=�,�<�5�8�A�A�g	�
��g	�XC�$�h�CrZ
codekingpro/portable-devtools · Team Ai