
    LKiO                        S SK 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JrJrJr  S SK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  S S	KJrJrJ r J!r!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/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8  S SK9J:r:  S SK;J<r<  S SK=J>r>  S SK?J@r@JArA  S SKBJCrCJDrDJErEJFrFJGrGJHrHJIrIJJrJJKrKJLrL  S SKMJNrN  S SKOrO " S S\5      rPg)    )ListOptionalSequenceTupleUnioncast)UUID)	overrides)CreateCollectionConfiguration+create_collection_configuration_to_json_strUpdateCollectionConfiguration+update_collection_configuration_to_json_strCollectionMetadata)Schema)DEFAULT_DATABASEDEFAULT_TENANTSystemlogger)SysDB)NotFoundErrorUniqueConstraintErrorInternalError)from_proto_collectionfrom_proto_segmentto_proto_update_metadatato_proto_segmentto_proto_segment_scope)CreateCollectionRequestCreateDatabaseRequestCreateSegmentRequestCreateTenantRequestCountCollectionsRequestCountCollectionsResponseDeleteCollectionRequestDeleteDatabaseRequestDeleteSegmentRequestGetCollectionsRequestGetCollectionsResponseGetCollectionSizeRequestGetCollectionSizeResponse GetCollectionWithSegmentsRequest!GetCollectionWithSegmentsResponseGetDatabaseRequestGetSegmentsRequestGetTenantRequestListDatabasesRequestUpdateCollectionRequestUpdateSegmentRequest)	SysDBStub) RetryOnRpcErrorClientInterceptor)OtelInterceptor)OpenTelemetryGranularitytrace_method)

CollectionCollectionAndSegmentsDatabaseMetadataOptionalArgumentSegmentSegmentScopeTenantUnspecifiedUpdateMetadata)EmptyNc                     ^  \ rS rSr% Sr\\S'   \R                  \S'   \	\S'   \
\S'   \
\S'   S\4U 4S	 jjr\S5U 4S jj5       r\S5U 4S jj5       r\S5U 4S jj5       r\\4S\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       r\S\S\S
S4S j5       r\   S6S\S\\   S\\	   S\\    S
\\   4
S  jj5       r!\\"" 5       4S\S\S!\#\\$      S
S4S" jj5       r%\SSS#\\&4S\S\	S$\\'   S%\(S&\\   S!\\)   S'\\
   S(\*S\	S)\	S
\+\,\*4   4S* jj5       r-\\\&4S\S\	S)\	S
S4S+ jj5       r.\SS\\&SS4S\\   S\\	   S\	S)\	S\\
   S\\
   S
\\,   4S, jj5       r/\\S4S\	S)\\	   S
\
4S- jj5       r0\S\S
\
4S. j5       r1\2" S/\3Rh                  5      \S0\S
\54S1 j5       5       r6\\"" 5       \"" 5       \"" 5       \"" 5       4S\S\#\	   S'\#\\
      S!\#\\$      S%\#\\7      S
S4S2 jj5       r8S5S3 jr9S4r:U =r;$ )7	GrpcSysDBD   zA gRPC implementation of the SysDB. In the distributed system, the SysDB is also
called the 'Coordinator'. This implementation is used by Chroma frontend servers
to call a remote SysDB (Coordinator) service._sys_db_stub_channel_coordinator_url_coordinator_port_request_timeout_secondssystemc                    > UR                   R                  S5      U l        UR                   R                  S5      U l        UR                   R                  S5      U l        [
        TU ]  U5      $ )Nchroma_coordinator_hostchroma_server_grpc_port$chroma_sysdb_request_timeout_seconds)settingsrequirerH   rI   rJ   super__init__)selfrK   	__class__s     ^/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/db/impl/grpc/client.pyrS   GrpcSysDB.__init__O   s_     & 7 78Q R!'!8!89R!S(.(?(?2)
% w''    returnNc                 0  > [         R                  " U R                   SU R                   3S/S9U l        [        5       [        5       /n[         R                  " U R                  /UQ76 U l        [        U R                  5      U l	        [        TU ]-  5       $ )N:)zgrpc.max_concurrent_streamsi  )options)grpcinsecure_channelrH   rI   rG   r5   r4   intercept_channelr3   rF   rR   start)rT   interceptorsrU   s     rV   r`   GrpcSysDB.startX   s    --$$%Qt'='=&>?:;
 ()+K+MN..t}}L|L%dmm4w}rX   c                 T   > U R                   R                  5         [        TU ]  5       $ N)rG   closerR   stoprT   rU   s    rV   rf   GrpcSysDB.stopc   s    w|~rX   c                 f   > U R                   R                  [        5       5        [        TU ]  5       $ rd   )rF   
ResetStaterB   rR   reset_staterg   s    rV   rk   GrpcSysDB.reset_stateh   s'    $$UW-w"$$rX   idnametenantc                 p    [        UR                  X#S9nU R                  R                  X@R                  S9ng ! [
        R                   ag  n[        R                  " SU SU SU SU 35        UR                  5       [
        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)Nrm   rn   ro   timeoutzFailed to create database name z and database id  for tenant  due to error: )r   hexrF   CreateDatabaserJ   r]   RpcErrorr   infocode
StatusCodeALREADY_EXISTSr   r   )rT   rm   rn   ro   requestresponsees          rV   create_databaseGrpcSysDB.create_databasem   s    	"+rvvDPG((77!>!> 8 H }} 	"KK1$7HLY_X``opqors vvx4??999+--/!	"s   7: B5A"B00B5c           	          [        XS9nU R                  R                  X0R                  S9n[	        [        UR                  R                  S9UR                  R                  UR                  R                  S9$ ! [        R                   ad  n[        R                  " SU SU SU 35        UR                  5       [        R                  R                   :X  a
  [#        5       e[%        5       eS nAff = f)Nrn   ro   rr   rv   rq   zFailed to get database rt   ru   )r-   rF   GetDatabaserJ   r:   r	   databaserm   rn   ro   r]   rx   r   ry   rz   r{   	NOT_FOUNDr   r   )rT   rn   ro   r}   r~   r   s         rV   get_databaseGrpcSysDB.get_database~   s    	"(dBG((44!>!> 5 H H--001&&++((// 
 }} 	"KK)$|F8?STRUV vvx4??444#o%/!	"s   A9A< <C4AC//C4c           	      L    [        XS9nU R                  R                  X0R                  S9  g ! [        R
                   a`  n[        R                  " SU SU SU 35        UR                  5       [        R                  R                  :X  a
  [        5       e[        eS nAff = f)Nr   rr   zFailed to delete database rt   ru   )r%   rF   DeleteDatabaserJ   r]   rx   r   ry   rz   r{   r   r   r   )rT   rn   ro   r}   r   s        rV   delete_databaseGrpcSysDB.delete_database   s    	 +EG,,!>!> -  }} 	 KK,TF,vhoVWUXY vvx4??444#o%	 s   ,/ B#ABB#limitoffsetc           	          [        XUS9nU R                  R                  X@R                  S9n/ nUR                   HB  nUR                  [        [        UR                  S9UR                  UR                  S95        MD     U$ ! [        R                   a+  n[        R                  " SU SU 35        [        5       eS nAff = f)N)r   r   ro   rr   r   rq   z$Failed to list databases for tenant ru   )r0   rF   ListDatabasesrJ   	databasesappendr:   r	   rm   rn   ro   r]   rx   r   ry   r   )	rT   r   r   ro   r}   r~   resultsproto_databaser   s	            rV   list_databasesGrpcSysDB.list_databases   s    	"*fUG((66!>!> 7 H ')G"*"4"4N$5$56+00-44 #5 N}} 	"KK6vhoaSQ  /!		"s   BB C&B??Cc                 N    [        US9nU R                  R                  X R                  S9ng ! [        R
                   aa  n[        R                  " SU SU 35        UR                  5       [        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)Nrn   rr   zFailed to create tenant ru   )r!   rF   CreateTenantrJ   r]   rx   r   ry   rz   r{   r|   r   r   rT   rn   r}   r~   r   s        rV   create_tenantGrpcSysDB.create_tenant   s    		")t4G((55!>!> 6 H }} 	"KK24&sKLvvx4??999+--/!		"s   ,/ B$ABB$c                     [        US9nU R                  R                  X R                  S9n[	        UR
                  R                  S9$ ! [        R                   aa  n[        R                  " SU SU 35        UR                  5       [        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)Nr   rr   zFailed to get tenant ru   )r/   rF   	GetTenantrJ   r?   ro   rn   r]   rx   r   ry   rz   r{   r   r   r   r   s        rV   
get_tenantGrpcSysDB.get_tenant   s    	"&D1G((22!>!> 3 H __))  }} 	"KK/v_QCHIvvx4??444#o%/!		"s   AA C AB;;C segmentc                 d    [        U5      n[        US9nU R                  R                  X0R                  S9ng ! [
        R                   aa  n[        R                  " SU SU 35        UR                  5       [
        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)N)r   rr   zFailed to create segment 	, error: )r   r    rF   CreateSegmentrJ   r]   rx   r   ry   rz   r{   r|   r   r   )rT   r   proto_segmentr}   r~   r   s         rV   create_segmentGrpcSysDB.create_segment   s    	",W5M*%G ((66!>!> 7 H }} 	"KK3G9IaSIJvvx4??999+--/!		"s   7: B/AB**B/
collectionc           	      ~    [        UR                  UR                  S9nU R                  R                  X0R                  S9ng ! [
        R                   ad  n[        R                  " SU SU SU 35        UR                  5       [
        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)N)rm   r   rr   z!Failed to delete segment with id  for collection ru   )r&   rv   rF   DeleteSegmentrJ   r]   rx   r   ry   rz   r{   r   r   r   )rT   r   rm   r}   r~   r   s         rV   delete_segmentGrpcSysDB.delete_segment   s    	"*66%>>G ((66!>!> 7 H }} 	"KK3B47G
|Sbcdbef vvx4??444#o%/!	"s   AA B<AB77B<typescopec                     [        U(       a  UR                  OS UU(       a  [        U5      OS UR                  S9nU R                  R	                  XPR
                  S9n/ nUR                   H  n[        U5      n	UR                  U	5        M!     U$ ! [        R                   a4  n
[        R                  " SU SU SU SU SU
 3
5        [        5       eS n
A
ff = f)N)rm   r   r   r   rr   zFailed to get segment id z, type z, scope r   ru   )r.   rv   r   rF   GetSegmentsrJ   segmentsr   r   r]   rx   r   ry   r   )rT   r   rm   r   r   r}   r~   r   r   r   r   s              rV   get_segmentsGrpcSysDB.get_segments   s    	"(266T7<,U3$%>>	G ((44!>!> 5 H &(G!)!2!2,];w' "3 N}} 	"KK+B4wtfHUGK[\f[ggvwxvyz  /!		"s   BB C'/CCmetadatac           	          S nU[        5       :w  a  [        [        [        S 4   U5      n[	        UR
                  UR
                  U(       a  [        U5      OS S9nUc  UR                  S5        SUl        U R                  R                  XPR                  S9  g ! [        R                   a.  n[        R                  " SU SU SU 35        [!        5       eS nAff = f)N)rm   r   r   r   Trr   z!Failed to update segment with id r   r   )r@   r   r   rA   r2   rv   r   
ClearFieldreset_metadatarF   UpdateSegmentrJ   r]   rx   r   ry   r   )rT   r   rm   r   write_metadatar}   r   s          rV   update_segmentGrpcSysDB.update_segment  s    	"!N;=(!%eND,@&A8!L*66%>>! 2.AG "":.)-&++!>!> ,  }} 	"KK3B47G
|S\]^\_`  /!		"s   BB C/)CCFschemaconfigurationr   	dimensionget_or_creater   c                 X    [        UR                  U[        U[        [        U5      5      U(       a  [        U5      OS UUU	U
U Vs/ s H  n[        U5      PM     snS9	nU R                  R                  XR                  S9n[        UR                  5      nXR                  4$ s  snf ! [        R                   aj  n[        R                   " SU SU SU
 SU	 SU 3
5        UR#                  5       [        R$                  R&                  :X  a
  [)        5       e[+        5       eS nAff = f)N)	rm   rn   configuration_json_strr   r   r   ro   r   r   rr   zFailed to create collection id , name  for database  and tenant ru   )r   rv   r   r   r   r   r   rF   CreateCollectionrJ   r   r   createdr]   rx   r   errorrz   r{   r|   r   r   )rT   rm   rn   r   r   r   r   r   r   ro   r   r   r}   r~   r   r   s                   rV   create_collectionGrpcSysDB.create_collection:  s0   	"-66'R!4(:H#E( @H1(;T#+!CKL8*738LG ((99!>!> : H /x/B/BCJ//// M }} 	"LL1"WTF.QYPZZfgmfnn}~  ~A  B vvx4??999+--/!	"s,   AB+ B&A	B+ &B+ +D)?A%D$$D)c                 *    [        UR                  UUS9nU R                  R                  X@R                  S9ng ! [
        R                   a  n[        R                  " SU SU SU SU 35        [        [
        R                  U5      n[        R                  " SUR                  5        S[
        R                  R                   35        UR                  5       [
        R                  R                  :X  a
  [        5       e[        5       eS nAff = f)	N)rm   ro   r   rr   zFailed to delete collection id r   r   ru   zError code: z, NotFoundError: )r$   rv   rF   DeleteCollectionrJ   r]   rx   r   r   r   Callrz   r{   r   r   r   )rT   rm   ro   r   r}   r~   r   s          rV   delete_collectionGrpcSysDB.delete_collectionc  s    	"-66!G
 ((99!>!> : H }} 
	"LL1"^H:\Z`Yaapqrpst TYY"ALLqvvxj(9$//:S:S9TU vvx4??444#o%/!
	"s   8; DB>DDc                     S nUb  [        UR                  UUS9nUb  Uc  Uc  [        S5      e[        UUUUUS9nUc  Uc  [        UUUUS9nU R                  R	                  XpR
                  S9n/ n	UR                   H  n
U	R                  [        U
5      5        M     U	$ ! [        R                   a4  n[        R                  " SU SU SU S	U S
U 3
5        [        5       eS nAff = f)N)rm   r   r   zmIf name is specified, tenant and database must also be specified in order to uniquely identify the collection)rn   ro   r   r   r   )ro   r   r   r   rr   z"Failed to get collections with id r   z	, tenant z, database ru   )r'   rv   
ValueErrorrF   GetCollectionsrJ   collectionsr   r   r]   rx   r   r   r   )rT   rm   rn   ro   r   r   r   r}   r~   r   r   r   s               rV   get_collectionsGrpcSysDB.get_collections  s0   '	"G~/vv!
 >h&6$ H  0!%! zdl/!%!	 04/@/@/O/O!>!> 0P 0H )+G&22
4Z@A 3N}} 	"LL4RDvYvhVabjakkz{|z}~  /!		"s   B B# #C+7/C&&C+c                 V    Ub  US:X  a0  [        US9nU R                  R                  U5      nUR                  $ [        UUS9nU R                  R                  U5      nUR                  $ ! [        R
                   a(  n[        R                  " SU 35        [        5       eS nAff = f)N )ro   )ro   r   z*Failed to count collections due to error: )	r"   rF   CountCollectionscountr]   rx   r   r   r   )rT   ro   r   r}   r~   r   s         rV   count_collectionsGrpcSysDB.count_collections  s    	"8r>1@595F5F5W5W6  ~~%1!% 6:5F5F5W5W6  ~~%}} 	"LLEaSIJ/!	"s   8A, 0A, ,B( #B##B(c                      [        UR                  S9nU R                  R                  U5      nUR                  $ ! [
        R                   a+  n[        R                  " SU SU 35        [        5       eS nAff = f)Nrm   Failed to get collection z size due to error: )
r)   rv   rF   GetCollectionSizetotal_records_post_compactionr]   rx   r   r   r   )rT   rm   r}   r~   r   s        rV   get_collection_sizeGrpcSysDB.get_collection_size  ss    	"."&&9G262C2C2U2U3H 999}} 	"LL4RD8LQCPQ/!	"s   9< A;&A66A;z"SysDB.get_collection_with_segmentscollection_idc           	          [        UR                  S9nU R                  R                  U5      n[	        [        UR                  5      UR                   Vs/ s H  n[        U5      PM     snS9$ s  snf ! [        R                   aa  nUR                  5       [        R                  R                  :X  a
  [        5       e[        R                   " SU SU 35        [#        5       eS nAff = f)Nr   )r   r   r   z  and its segments due to error: )r+   rv   rF   GetCollectionWithSegmentsr9   r   r   r   r   r]   rx   rz   r{   r   r   r   r   r   )rT   r   r}   r~   r   r   s         rV   get_collection_with_segments&GrpcSysDB.get_collection_with_segments  s    	"6-:K:KLG!!;;GD  )01D1DEEMEVEVWEV',W5EVW W}} 	"vvx4??444#o%LL+M?:Z[\Z]^  /!	"s+   AA6 A1
,A6 1A6 6C+
AC&&C+c           	          S nU[        5       :w  a  [        [        U5      nS nU[        5       :w  a  [        [        [        S 4   U5      nS nU[        5       :w  a  [        [        [
        S 4   U5      nS n	U[        5       :w  a  [        [        [        S 4   U5      n	[        UR                  UUU(       a  [        U5      OS U	(       a  [        U	5      OS S9n
Uc  U
R                  S5        SU
l        U R                  R                  XR                  S9ng ! [         R"                   a  n[        [         R$                  U5      n[&        R(                  " SU SU SU 35        UR+                  5       [         R,                  R.                  :X  a
  [1        5       eUR+                  5       [         R,                  R2                  :X  a
  [5        5       e[7        5       eS nAff = f)N)rm   rn   r   r   r   r   Trr   zFailed to update collection id r   ru   )r@   r   strr   intrA   r   r1   rv   r   r   r   r   rF   UpdateCollectionrJ   r]   rx   r   r   r   rz   r{   r   r   r|   r   r   )rT   rm   rn   r   r   r   
write_namewrite_dimensionr   write_configurationr}   r~   r   s                rV   update_collectionGrpcSysDB.update_collection  s   0	"J{}$!#t_
"OKM)"&uS$Y'7"C!N;=(!%eND,@&A8!L"&-&*7=>'# .66)! 2.A ' (S'( G "":.)-&((99!>!> : H }} 		"TYY"ALL1"WTF/RSQTU vvx4??444#o%vvx4??999+--/!		"s   DD G+B/GGc                 H    U R                   R                  [        5       SS9  g )NT)wait_for_ready)rF   rj   rB   )rT   s    rV   reset_and_wait_for_ready"GrpcSysDB.reset_and_wait_for_ready-  s    $$UWT$BrX   )rG   rI   rH   rJ   rF   )rY   N)NNN)<__name__
__module____qualname____firstlineno____doc__r3   __annotations__r]   Channelr   r   r   rS   r
   r`   rf   rk   r   r	   r   r:   r   r   r   r   r   r   r?   r   r=   r   r   r>   r   r@   r<   rA   r   r   r   r   r;   boolr   r8   r   r   r   r   r   r7   r6   	OPERATIONr9   r   r   r   r   __static_attributes____classcell__)rU   s   @rV   rD   rD   D   s<   5 ll!!(v (     % % 1?""!"+."	" "  4B " "c "x " "& 7E  C    $       $ $$	"}" " 	"
 
(	" "6 
"# 
"$ 
" 
" "s "v " " "g "$ " " " "4 "D " ""  ""(,"" TN" sm	"
 %" 
'	" "8 
 @K}	"" " #8N#;<	"
 
" "@  (,#'#$(&"&" &"  	&"
 5&" 7#&" 8$&" C=&" &" &" &" 
z4	 &" &"P  %(	"" " 	"
 
" "6  ""$(# $0"TN0" sm0" 	0"
 0" }0" 0" 
*	0" 0"d  %"&"" 3-" 
	" "2 	"d 	"s 	" 	" ,.F.P.P "!"	" "(  '2m5@]?J} M:":" s#:" $HSM2	:"
 #8N#;<:" (23
:" 
:" :"xC CrX   rD   )Qtypingr   r   r   r   r   r   uuidr	   r
   %chromadb.api.collection_configurationr   r   r   r   r   chromadb.api.typesr   chromadb.configr   r   r   r   chromadb.db.systemr   chromadb.errorsr   r   r   chromadb.proto.convertr   r   r   r   r   chromadb.proto.coordinator_pb2r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   #chromadb.proto.coordinator_pb2_grpcr3   chromadb.proto.utilsr4   %chromadb.telemetry.opentelemetry.grpcr5    chromadb.telemetry.opentelemetryr6   r7   chromadb.typesr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   google.protobuf.empty_pb2rB   r]   rD    rX   rV   <module>r     s    ? ?    & L L $ O O      . : A A   , jC jCrX   