
    LKiN                     T   S SK JrJr  S SKJr  S SKJr  S SKrS SKJ	r	J
r
Jr  S SKJrJrJrJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJr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*J+r+  S SK)J,r,J-r-  S SK.J/r/  S SK0J1r1J2r2  S SK3J4r4J5r5J6r6J7r7   " S S\\
5      r8 " S S\\	5      r9g)    )OptionalSequence)UUID)overrideN)AdminAPI	ClientAPI	ServerAPI)CreateCollectionConfigurationUpdateCollectionConfiguration.validate_embedding_function_conflict_on_create+validate_embedding_function_conflict_on_get)SharedSystemClient)CollectionMetadata
DataLoader	Documents
EmbeddableEmbeddingFunction
Embeddings	GetResultIDsIncludeLoadable	MetadatasQueryResultSchemaURIsIncludeMetadataDocuments!IncludeMetadataDocumentsDistancesDefaultEmbeddingFunction)UserIdentity)maybe_set_tenant_and_database)SettingsSystem)DEFAULT_TENANTDEFAULT_DATABASE)
Collection)ChromaAuthErrorChromaError)DatabaseTenantWhereWhereDocumentc                     ^  \ rS rSr% Sr\r\\S'   \	r
\\S'   \\S'   \\S'   \\	\" 5       4S\\   S\\   S\SS	4U 4S
 jjjr\\\\	4S\S\S\SS 4S jj5       5       r\S\4S j5       r\S\4S j5       r\ SAS\\   S\\   S\\   4S jj5       r\S\4S j5       r\S	S	S	\" 5       S	S4S\S\\   S\\   S\\   S\\ \!      S\\"\#      S\$S\4S jj5       r%\\" 5       S	4S\S\\ \!      S\\"\#      S\4S jj5       r&\S	S	S	\" 5       S	4S\S\\   S\\   S\\   S\\ \!      S\\"\#      S\4S jj5       r'\   SBS\(S\\   S \\   S!\\)   SS	4
S" jj5       r*\S\SS	4S# j5       r+\   SBS$\,S%\(S&\-S'\\.   S(\\/   S)\\0   S\$4S* jj5       r1\    SCS%\(S$\,S&\\-   S'\\.   S(\\/   S)\\0   S\$4S+ jj5       r2\   SBS%\(S$\,S&\-S'\\.   S(\\/   S)\\0   S\$4S, jj5       r3\S%\(S\4S- j5       r4\SDS%\(S/\S\54S0 jj5       r6\S	S	S	S	S	\74S%\(S$\\,   S1\\8   S\\   S\\   S2\\9   S3\:S\54S4 jj5       r;  SAS%\(S$\\,   S1\\8   S2\\9   SS	4
S5 jjr<\S	S.S	S	\=4S%\(S6\-S$\\,   S7\S1\\8   S2\\9   S3\:S\>4S8 jj5       r?\S\$4S9 j5       r@\S\4S: j5       rA\S\4S; j5       rB\S\4S< j5       rC\\	4S\S\SS	4S= jj5       rD\S\SS	4S> j5       rES\S\SS	4S? jrFS@rGU =rH$ )EClient*   a  A client for Chroma. This is the main entrypoint for interacting with Chroma.
A client internally stores its tenant and database and proxies calls to a
Server API instance of Chroma. It treats the Server API and corresponding System
as a singleton, so multiple clients connecting to the same resource will share the
same API instance.

Client implementations should be implement their own API-caching strategies.
tenantdatabase_server_admin_clientsettingsreturnNc                   > [         TU ]  US9  Ub  Xl        Ub  X l        U R                  R                  [        5      U l        U R                  5       n[        UUR                  UUS9u  pVUc  Uc  [        S5      eUc  Uc  [        S5      eU(       a  XPl        U(       a  X`l        [        R                  U R                  5      U l        U R                  U R                  U R                  S9  U R!                  5         g )Nr4   )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.r0   r1   )super__init__r0   r1   _systeminstancer	   r2   get_user_identityr!   ;chroma_overwrite_singleton_tenant_database_access_from_authr'   AdminClientfrom_systemr3   _validate_tenant_database_submit_client_start_event)selfr0   r1   r4   user_identitymaybe_tenantmaybe_database	__class__s          U/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/api/client.pyr=   Client.__init__<   s    	(+ K$M ||,,Y7..0'DAI  BF  BF!'#+	(
$ FN!o  !h&6!}  &K*M )44T\\B&&dkkDMM&R'')    systemc                 T    [         R                  " U5        U " X#UR                  S9nU$ )N)r0   r1   r4   r   _populate_data_from_systemr4   )clsrN   r0   r1   r?   s        rK   rC   Client.from_systemi   s'     	55f=f&//RrM   c                      U R                   R                  5       $ ! [        R                   a    [	        S5      e[
         a  nUeS nAf[         a  n[	        [        U5      5      eS nAff = f)NACould not connect to a Chroma server. Are you sure it is running?)r2   r@   httpxConnectError
ValueErrorr(   	Exceptionstr)rF   es     rK   r@   Client.get_user_identityw   sg    
	%<<1133!! 	S   	G 	%SV$$	%s!    (A,AA,A''A,c                 6    U R                   R                  5       $ )z2Return the server time in nanoseconds since epoch.)r2   	heartbeatrF   s    rK   r^   Client.heartbeat   s     ||%%''rM   limitoffsetc                     U R                   R                  XU R                  U R                  S9 Vs/ s H  n[	        U R                   US9PM     sn$ s  snf )zList collections for the current tenant and database, with pagination.

Returns:
    Sequence[Collection]: Collection objects for the current tenant.
r;   )clientmodel)r2   list_collectionsr0   r1   r&   )rF   ra   rb   re   s       rK   rf   Client.list_collections   s[     66dkkDMM 7 
 dll%8
 	
 
s   Ac                 ^    U R                   R                  U R                  U R                  S9$ )z9Return the number of collections in the current database.r;   )r2   count_collectionsr0   r1   r_   s    rK   ri   Client.count_collections   s-     ||--;; . 
 	
rM   Fnameschemaconfigurationmetadataembedding_functiondata_loaderget_or_createc           
          Uc  0 nUR                  S5      n[        XX5        Ub  Uc  XSS'   U R                  R                  UUUU R                  U R
                  UUS9n	[        U R                  U	UUS9$ )a  Create a collection with optional configuration and metadata.

If using a schema, do not provide `embedding_function`. Instead,
provide the `embedding_function` as part of the schema.

Args:
    name: Collection name.
    schema: Optional collection schema for indexes and encryption.
    configuration: Optional collection configuration.
    metadata: Optional collection metadata.
    embedding_function: Optional embedding function for the collection.
    data_loader: Optional data loader for documents with URIs.
    get_or_create: Whether to return an existing collection if present.

Returns:
    Collection: The created collection.

Raises:
    ValueError: If the embedding function conflicts with configuration.
ro   )rk   rl   rn   r0   r1   rq   rm   rd   re   ro   rp   )getr   r2   create_collectionr0   r1   r&   )
rF   rk   rl   rm   rn   ro   rp   rq   configuration_efre   s
             rK   ru   Client.create_collection   s    B  M(,,-AB6	
 ).>.F2D./..;;]]'' / 
 <<1#	
 	
rM   c                     U R                   R                  UU R                  U R                  S9nUR                  R                  S5      n[        X%5        [        U R                   UUUS9$ )aH  Get a collection by name.

Args:
    name: Collection name.
    embedding_function: Optional embedding function for the collection.
    data_loader: Optional data loader for documents with URIs.

Returns:
    Collection: The requested collection.

Raises:
    ValueError: If the embedding function conflicts with configuration.
rk   r0   r1   ro   rs   )r2   get_collectionr0   r1   configuration_jsonrt   r   r&   )rF   rk   ro   rp   re   persisted_ef_configs         rK   rz   Client.get_collection   sr    , ++;;]] , 

 $66::;OP3	
 <<1#	
 	
rM   c           	      4   Uc  0 nUR                  S5      n[        XW5        Ub  Uc  XSS'   U R                  R                  UUUU R                  U R
                  US9nUR                  R                  S5      n	[        XY5        [        U R                  UUUS9$ )a  Get an existing collection or create a new one.

If the collection does not exist, it will be created. If the collection
already exists, the schema, configuration, and metadata arguments
will be ignored.

Args:
    name: Collection name.
    schema: Optional collection schema for indexes and encryption.
    configuration: Optional collection configuration.
    metadata: Optional collection metadata.
    embedding_function: Optional embedding function for the collection.
    data_loader: Optional data loader for URI-backed data.

Returns:
    Collection: The existing or newly created collection.

Raises:
    ValueError: If the embedding function does not match the collection's embedding function.
ro   )rk   rl   rn   r0   r1   rm   rs   )	rt   r   r2   get_or_create_collectionr0   r1   r{   r   r&   )
rF   rk   rl   rm   rn   ro   rp   rv   re   r|   s
             rK   r   Client.get_or_create_collection
  s    @  M(,,-AB6	
 ).>.F2D./55;;]]' 6 
 $66::;OP3	
 <<1#	
 	
rM   idnew_namenew_metadatanew_configurationc           	      f    U R                   R                  UU R                  U R                  UUUS9$ )N)r   r0   r1   r   r   r   )r2   _modifyr0   r1   )rF   r   r   r   r   s        rK   r   Client._modifyK  s:     ||##;;]]%/ $ 
 	
rM   c                 `    U R                   R                  UU R                  U R                  S9$ )Nry   )r2   delete_collectionr0   r1   rF   rk   s     rK   r   Client.delete_collection\  s1    
 ||--;;]] . 
 	
rM   idscollection_id
embeddings	metadatas	documentsurisc                 j    U R                   R                  UU R                  U R                  UUUUUS9$ )N)r   r0   r1   r   r   r   r   r   )r2   _addr0   r1   )rF   r   r   r   r   r   r   s          rK   r   Client._addk  s@     ||  ;;]]'! ! 	
 		
rM   c                 j    U R                   R                  UU R                  U R                  UUUUUS9$ N)r   r0   r1   r   r   r   r   r   )r2   _updater0   r1   rF   r   r   r   r   r   r   s          rK   r   Client._update  @     ||##';;]]! $ 	
 		
rM   c                 j    U R                   R                  UU R                  U R                  UUUUUS9$ r   )r2   _upsertr0   r1   r   s          rK   r   Client._upsert  r   rM   c                 `    U R                   R                  UU R                  U R                  S9$ )N)r   r0   r1   )r2   _countr0   r1   )rF   r   s     rK   r   Client._count  s/    ||""';;]] # 
 	
rM   
   nc                 b    U R                   R                  UUU R                  U R                  S9$ )N)r   r   r0   r1   )r2   _peekr0   r1   )rF   r   r   s      rK   r   Client._peek  s2    ||!!';;]]	 " 
 	
rM   wherewhere_documentincludec                 l    U R                   R                  UU R                  U R                  UUUUUUS9	$ )N)	r   r0   r1   r   r   ra   rb   r   r   )r2   _getr0   r1   )rF   r   r   r   ra   rb   r   r   s           rK   r   Client._get  sC     ||  ';;]]) ! 

 
	
rM   c           	      h    U R                   R                  UU R                  U R                  UUUS9  g )N)r   r0   r1   r   r   r   )r2   _deleter0   r1   )rF   r   r   r   r   s        rK   r   Client._delete  s5     	';;]]) 	 	
rM   query_embeddings	n_resultsc                 l    U R                   R                  UUU R                  U R                  UUUUUS9	$ )N)	r   r   r0   r1   r   r   r   r   r   )r2   _queryr0   r1   )rF   r   r   r   r   r   r   r   s           rK   r   Client._query  sC     ||""';;]]-) # 

 
	
rM   c                 6    U R                   R                  5       $ N)r2   resetr_   s    rK   r   Client.reset  s    ||!!##rM   c                 6    U R                   R                  5       $ r   )r2   get_versionr_   s    rK   r   Client.get_version  s    ||''))rM   c                 6    U R                   R                  5       $ r   )r2   get_settingsr_   s    rK   r   Client.get_settings  s    ||((**rM   c                 6    U R                   R                  5       $ r   )r2   get_max_batch_sizer_   s    rK   r   Client.get_max_batch_size  s    ||..00rM   c                 :    U R                  XS9  Xl        X l        g Nr;   rD   r0   r1   )rF   r0   r1   s      rK   
set_tenantClient.set_tenant  s    &&f&H rM   c                 D    U R                  U R                  US9  Xl        g r   r   )rF   r1   s     rK   set_databaseClient.set_database  s    &&dkkH&M rM   c                 F    U R                   R                  US9   U R                   R                  X!S9  g ! [        R                   a    [	        S5      e[
         a  nUeS nAf[         a    [	        SU S35      ef = f! [        R                   a    [	        S5      ef = f)Nrk   rU   zCould not connect to tenant z. Are you sure it exists?rk   r0   )r3   
get_tenantrV   rW   rX   r(   rY   get_database)rF   r0   r1   r[   s       rK   rD    Client._validate_tenant_database  s    	))v)6	+++I !! 	S   	G 	.vh6OP 	 !! 	S 	s    6 B  (A=A  A=  B )r3   r2   r1   r0   )NN)NNN)NNNN)r   )I__name__
__module____qualname____firstlineno____doc__r$   r0   rZ   __annotations__r%   r1   r	   r   r"   r   r=   classmethodr   r#   rC   r    r@   intr^   r   r&   rf   ri   r   r   r
   r   r   r   r   r   boolru   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   r   r   r   rD   __static_attributes____classcell__rJ   s   @rK   r.   r.   *   s8    !FC $Hc$
 !/"2%Z	+*+* 3-+* 	+*
 
+* +*Z  %(	  	
 
   %< % % (3 ( ( CG
c]
3;C=
	*	
 
 
3 
 
  $(AE15 %&6:#<
<
  <
   =>	<

 -.<
 %j)
<
 j23<
 <
 
<
 <
|  %&6:%
%
 %j)
%
 j23%
 
%
 %
N  $(AE15 %&6:>
>
  >
   =>	>

 -.>
 %j)
>
 j23>
 
>
 >
@  #'59EI

 3-
 12	

 $$AB
 

 
  

 

 
  *.)-#

 
 	

 I&
 I&
 tn
 

 
( 
 ,0)-)-#

 
 Z(	

 I&
 I&
 tn
 

 
(  *.)-#

 
 	

 I&
 I&
 tn
 

 
( 
D 
S 
 
 
4 
C 
 
 
  "!%# $263

 c]
 	

 }
 
 !/
 
 

 
4 "&26

 c]
 	

 !/
 

  
 "!%26<

 %
 c]	

 
 
 !/
 
 

 
, $t $ $ *S * * +h + + 1C 1 1 6F ! ! !4 ! !
 !S !T ! ! s t  rM   r.   c                   d  ^  \ rS rSr% Sr\\S'   \" 5       4S\SS4U 4S jjjr\	\
4S\S	\SS4S
 jj5       r\	\
4S\S	\S\4S jj5       r\	\
4S\S	\SS4S jj5       r\	SS\
4S\\   S\\   S	\S\\   4S jj5       r\	S\SS4S j5       r\	S\S\4S j5       r\\	S\SS 4S j5       5       rSrU =r$ )rB   i1  z0Admin client for managing tenants and databases.r2   r4   r5   Nc                 l   > [         TU ]  U5        U R                  R                  [        5      U l        g r   )r<   r=   r>   r?   r	   r2   )rF   r4   rJ   s     rK   r=   AdminClient.__init__6  s&    "||,,Y7rM   rk   r0   c                 4    U R                   R                  XS9$ )zjCreate a database in a tenant.

Args:
    name: Database name.
    tenant: Tenant that owns the database.
r   )r2   create_databaserF   rk   r0   s      rK   r   AdminClient.create_database:       ||+++EErM   c                 4    U R                   R                  XS9$ )zGet a database by name.

Args:
    name: Database name.
    tenant: Tenant that owns the database.

Returns:
    Database: The database record.
r   )r2   r   r   s      rK   r   AdminClient.get_databaseD  s     ||((d(BBrM   c                 4    U R                   R                  XS9$ )zfDelete a database by name.

Args:
    name: Database name.
    tenant: Tenant that owns the database.
r   )r2   delete_databaser   s      rK   r   AdminClient.delete_databaseQ  r   rM   ra   rb   c                 6    U R                   R                  XUS9$ )N)r0   )r2   list_databases)rF   ra   rb   r0   s       rK   r   AdminClient.list_databases[  s     ||**5*HHrM   c                 4    U R                   R                  US9$ Nr   )r2   create_tenantr   s     rK   r   AdminClient.create_tenantd  s    ||))t)44rM   c                 4    U R                   R                  US9$ r   )r2   r   r   s     rK   r   AdminClient.get_tenanth  s    ||&&D&11rM   rN   c                 R    [         R                  " U5        U " UR                  S9nU$ )Nr7   rP   )rR   rN   r?   s      rK   rC   AdminClient.from_systeml  s%     	55f=0rM   )r2   )r   r   r   r   r   r	   r   r"   r=   r   r$   rZ   r   r)   r   r   r   r   r   r   r   r*   r   r   r#   rC   r   r   r   s   @rK   rB   rB   1  s   :,4J 8 84 8 8 7E FC F F$ F F 4B 
C 
Cc 
Cx 
C 
C 7E FC F F$ F F   $ $$	I}I I 	I
 
(	I I 5# 5$ 5 5 2s 2v 2 2  
  rM   rB   ):typingr   r   uuidr   	overridesr   rV   chromadb.apir   r   r	   %chromadb.api.collection_configurationr
   r   r   r   !chromadb.api.shared_system_clientr   chromadb.api.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   chromadb.authr    chromadb.auth.utilsr!   chromadb.configr"   r#   r$   r%   chromadb.api.models.Collectionr&   chromadb.errorsr'   r(   chromadb.typesr)   r*   r+   r,   r.   rB    rM   rK   <module>r     s}    %    7 7  A    & ' = , < 5 8 A AB BNC$h CrM   