
    LKiP                     j   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	  S SK
r
S SKJrJrJrJr  S SKJrJrJrJrJrJr  S SKJs  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+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9  S S	K:J;r;J<r<  S SK=r=S S
K>J?r?  S SK@JArAJBrBJCrCJDrD   " S S\;\5      rEg)    )futures)AnyDictListcast)UUID)	overridesN)DEFAULT_DATABASEDEFAULT_TENANT	ComponentSystem)from_proto_metadatafrom_proto_update_metadatafrom_proto_segmentfrom_proto_segment_scopeto_proto_collectionto_proto_segment)CreateCollectionRequestCreateCollectionResponseCreateDatabaseRequestCreateDatabaseResponseCreateSegmentRequestCreateSegmentResponseCreateTenantRequestCreateTenantResponseCountCollectionsRequestCountCollectionsResponseDeleteCollectionRequestDeleteCollectionResponseDeleteSegmentRequestDeleteSegmentResponseGetCollectionsRequestGetCollectionsResponseGetCollectionSizeRequestGetCollectionSizeResponse GetCollectionWithSegmentsRequest!GetCollectionWithSegmentsResponseGetDatabaseRequestGetDatabaseResponseGetSegmentsRequestGetSegmentsResponseGetTenantRequestGetTenantResponseResetStateResponseUpdateCollectionRequestUpdateCollectionResponseUpdateSegmentRequestUpdateSegmentResponse)SysDBServiceradd_SysDBServicer_to_server)Empty)
CollectionMetadataSegmentSegmentScopec                   D  ^  \ rS rSr% Sr\R                  \S'   \\S'   0 r	\
\\4   \S'   0 r\
\\\   4   \S'   0 r\
\\
\\
\\4   4   4   \S'   0 r\
\\
\\4   4   \S'   S	\4U 4S
 jjr\S*U 4S jj5       r\S*U 4S jj5       r\S*U 4S jj5       r\" SS9S\S\R4                  S\4S j5       r\" SS9S\S\R4                  S\4S j5       r\" SS9S\ S\R4                  S\!4S j5       r"\" SS9S\#S\R4                  S\$4S j5       r%\" SS9S\&S\R4                  S\'4S j5       r(S\S\R4                  S\'4S jr)\" SS9S\*S\R4                  S\+4S j5       r,\" SS9S\-S\R4                  S\.4S j5       r/\" SS9S\0S\R4                  S\14S j5       r2\" SS9S\3S\R4                  S\44S j5       r5\" SS9S\6S\R4                  S\74S j5       r8\" SS9S\9S\R4                  S\:4S  j5       r;\" SS9S\<S\R4                  S\=4S! j5       r>\" SS9S\?S\R4                  S\@4S" j5       rA\" SS9S\BS\R4                  S\C4S# j5       rD\" SS9S\ES\R4                  S\F4S$ j5       rG\" SS9S\HS\R4                  S\I4S% j5       rJS&\KS'\LR                  SS4S( jrNS)rOU =rP$ )+GrpcMockSysDB;   zA mock sysdb implementation that can be used for testing the grpc client. It stores
state in simple python data structures instead of a database._server_server_port	_segments_collection_to_segments$_tenants_to_databases_to_collections_tenants_to_database_to_idsystemc                 b   > UR                   R                  S5      U l        [        TU ]  U5      $ )Nchroma_server_grpc_port)settingsrequirer>   super__init__)selfrC   	__class__s     ^/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/db/impl/grpc/server.pyrI   GrpcMockSysDB.__init__H   s+    "OO334MNw''    returnNc                 (  > [         R                  " [        R                  " SS95      U l        [        X R                  5        U R                  R                  SU R                   35        U R                  R                  5         [        TU ]!  5       $ )N
   )max_workersz[::]:)
grpcserverr   ThreadPoolExecutorr=   r4   add_insecure_portr>   startrH   rJ   rK   s    rL   rW   GrpcMockSysDB.startL   sf    {{7#=#="#MN#D,,7&&t/@/@.A'BCw}rN   c                 V   > U R                   R                  S 5        [        TU ]  5       $ N)r=   stoprH   rX   s    rL   r\   GrpcMockSysDB.stopT   s!    $w|~rN   c                    > 0 U l         0 U l        0 U R                  [        '   0 U R                  [           [        '   0 U R                  [        '   [        SS9U R                  [           [        '   [        TU ]  5       $ )Nr   )int)r?   rA   r   r
   rB   r   rH   reset_staterX   s    rL   r`   GrpcMockSysDB.reset_stateY   sq    461DF11.AVX11.ABRS:<''7LPUVK''78HIw"$$rN   F)check_signaturerequestcontextc                    UR                   nUR                  nX0R                  ;  a.  UR                  [        R
                  R                  SU S35        X@R                  U   ;   a.  UR                  [        R
                  R                  SU S35        0 U R                  U   U'   [        UR                  S9U R                  U   U'   [        5       $ )NTenant 
 not found	Database  already existshex)tenantnamerA   abortrS   
StatusCode	NOT_FOUNDALREADY_EXISTSr   idrB   r   )rJ   rc   rd   rl   databases        rL   CreateDatabaseGrpcMockSysDB.CreateDatabased   s     <<BBBMM$//33wvhj5QR@@HHMM..)H:_0U GI11&9(C<@WZZ<P''/9%''rN   c                    UR                   nUR                  nX0R                  ;  a.  UR                  [        R
                  R                  SU S35        X@R                  U   ;  a.  UR                  [        R
                  R                  SU S35        U R                  U   U   n[        [        R                  " UR                  XCS9S9$ )Nrf   rg   rh   )rr   rm   rl   )rs   )rl   rm   rA   rn   rS   ro   rp   rB   r)   protoDatabaserk   )rJ   rc   rd   rl   rs   rr   s         rL   GetDatabaseGrpcMockSysDB.GetDatabaset   s     <<BBBMM$//33wvhj5QRDDVLLMM$//33y
*5UV,,V4X>"^^rvvHL
 	
rN   c                     UR                   nX0R                  ;   a.  UR                  [        R                  R
                  SU S35        0 U R                  U'   0 U R                  U'   [        5       $ )Nrf   ri   )rm   rA   rn   rS   ro   rq   rB   r   rJ   rc   rd   rl   s       rL   CreateTenantGrpcMockSysDB.CreateTenant   sh     >>>MM..'&0Q =?11&924''/#%%rN   c                     UR                   nX0R                  ;  a.  UR                  [        R                  R
                  SU S35        [        [        R                  " US9S9$ )Nrf   rg   )rm   )rl   )	rm   rA   rn   rS   ro   rp   r-   rw   Tenantr|   s       rL   	GetTenantGrpcMockSysDB.GetTenant   sS     BBBMM$//33wvhj5QR <<V,
 	
rN   c                 N    [        UR                  5      nU R                  X25      $ r[   )r   segmentCreateSegmentHelper)rJ   rc   rd   r   s       rL   CreateSegmentGrpcMockSysDB.CreateSegment   s#     %W__5''99rN   r   c                     US   R                   U R                  ;   a1  UR                  [        R                  R
                  SUS    S35        XR                  US   R                   '   [        5       $ )Nrr   Segment ri   )rk   r?   rn   rS   ro   rq   r   )rJ   r   rd   s      rL   r   !GrpcMockSysDB.CreateSegmentHelper   sd     4=.MM..74=/9 -4wt}(()$&&rN   c                     UR                   nX0R                  ;   a  U R                  U	 [        5       $ UR                  [        R
                  R                  SU S35        g )Nr   rg   )rr   r?   r!   rn   rS   ro   rp   )rJ   rc   rd   id_to_deletes       rL   DeleteSegmentGrpcMockSysDB.DeleteSegment   sP     zz>>)|,(**MM))Xl^:+NrN   c                 h   UR                  S5      (       a  [        UR                  S9OS nUR                  S5      (       a  UR                  OS nUR                  S5      (       a  [	        UR
                  5      OS n[        UR                  S9n/ nU R                  R                  5        H\  nU(       a  US   U:w  a  M  U(       a  US   U:w  a  M'  U(       a  US   U:w  a  M9  U(       a  US   U:w  a  MK  UR                  U5        M^     [        U Vs/ s H  n[        U5      PM     snS9$ s  snf )Nrr   rj   typescope
collection)segments)HasFieldr   rr   r   r   r   r   r?   valuesappendr+   r   )	rJ   rc   rd   	target_idtarget_typetarget_scopetarget_collectionfound_segmentsr   s	            rL   GetSegmentsGrpcMockSysDB.GetSegments   s    -4,<,<T,B,BDWZZ(	&-&6&6v&>&>gllD (( %W]]3 	
 !W%7%78~~,,.GWT]i7wv+= 0L @ W\%:>O%O!!'* / #?MN~G&w/~N
 	
Ns   D/c                    [        UR                  5      nUR                  U R                  ;  a/  UR	                  [
        R                  R                  SU S35        g U R                  UR                     nUR                  S5      (       aF  [        [        [        [        4   US   5      nUS   c  0 US'   U R                  XQR                  5        UR                  S5      (       a  UR                  (       a  0 US'   [!        5       $ )Nr   rg   metadatareset_metadata)r   rr   rk   r?   rn   rS   ro   rp   r   r   r   strr   _merge_metadatar   r   r2   )rJ   rc   rd   id_to_updater   targets         rL   UpdateSegmentGrpcMockSysDB.UpdateSegment   s     GJJ'4>>1MM))Xl^:+N nn\%5%56G
++d38ngj.AB:&.*,GJ'$$V-=-=> 011g6L6L&(
#(**rN   c                    UR                   nUR                  nUR                  nX@R                  ;  a.  UR	                  [
        R                  R                  SU S35        XPR                  U   ;  a.  UR	                  [
        R                  R                  SU S35        U R                  R                  5        H  u  nnUR                  5        H  u  pUR                  U	;   d  M  XaR                  :w  d  XR                  :w  a?  UR	                  [
        R                  R                  SUR                   SU SU 35        Mt  UR                  (       a  M  UR	                  [
        R                  R                  SUR                   SU SU 35        M     M     U R                  U   U   n
U
R                  5        Vs/ s H  oS   U:X  d  M  UPM     nn[        U5      S::  d   e[        U5      S	:  aW  UR                  (       a  US	   n[        [        U5      S
S9$ UR	                  [
        R                  R                  SU S35        [         R"                  " UR$                  5      n['        UR                  S9n[)        UUR                   US [+        UR,                  5      UR.                  UUS	S9	n/ nUR0                   H  n[3        U5      nUS   R4                  U R6                  ;   aS  U H  nU R9                  [;        US9U5        M     UR	                  [
        R                  R                  SUS    S35        U R=                  UU5        UR?                  US   R4                  5        M     UXR                  '   U SU SUR                   3nUU R@                  U'   [        [        U5      SS9$ s  snf )Nrf   rg   rh   Collection z already exists in tenant z
 database rm      r   F)r   createdri   rj   )	rr   rm   configuration_jsonserialized_schemar   	dimensionrs   rl   versionrr   )rr   r   :T)!rm   rl   rs   rA   rn   rS   ro   rp   itemsrr   rq   get_or_creater   lenr   r   jsonloadsconfiguration_json_strr   r6   r   r   r   r   r   rk   r?   r   r    r   r   r@   )rJ   rc   rd   collection_namerl   rs   search_tenant	databasessearch_databasesearch_collectionscollectionscmatchesexisting_collectionr   rr   new_collectionsegments_addedsegment_protor   scollection_unique_keys                         rL   CreateCollectionGrpcMockSysDB.CreateCollection   so    ",,##BBBMM$//33wvhj5QRDDVLLMM$//33y
*5UV 66<<>
7@7H3::!33%7*.>.>> OO::)'**5OP]^hixhyz %222   OO::)'**5OP]^hixhyz 8I ?( ??GQ)002S2i?6R12S7|q   w<!$$&-aj#/23FG!  MM..o.o>
 "ZZ(F(FGgjj!#1"()9)9:''

 $--M(7Gt}  DNN2'A&&';q'A7K (OO22wt}o_= $$Wg6!!'$-"3"34 . #1JJ#)(!H:Qwzzl C>L$$%:;'*>:
 	
c Ts   O O c                 T   UR                   nUR                  nUR                  nX@R                  ;  a.  UR	                  [
        R                  R                  SU S35        XPR                  U   ;  a.  UR	                  [
        R                  R                  SU S35        U R                  U   U   nX6;   aB  Xc	 U SU SU 3nU R                  U   nU(       a  U H  n	U R                  U		 M     [        5       $ UR	                  [
        R                  R                  SU S35        g )Nrf   rg   rh   r   r   )rr   rl   rs   rA   rn   rS   ro   rp   r@   r?   r   )
rJ   rc   rd   collection_idrl   rs   r   r   segment_ids
segment_ids
             rL   DeleteCollectionGrpcMockSysDB.DeleteCollectionH  s     

##BBBMM$//33wvhj5QRDDVLLMM$//33y
*5UV??GQ'*'-haz=/$J!667LMK"-Jz2 #.+--MM))[z+RrN   c           
         UR                  S5      (       a  [        UR                  S9OS nUR                  S5      (       a  UR                  OS n0 nU R                  R                  5        H  u  pgUR                  5        Hl  u  pUR                  S:w  a  XaR                  :w  a  M&  UR                  S:w  a  XR                  :w  a  MG  UR                  U	5        [        SU SU SU	 35        Mn     M     / n
UR                  5        H8  nU(       a  US   U:w  a  M  U(       a  US   U:w  a  M'  U
R                  U5        M:     [        U
 Vs/ s H  n[        U5      PM     snS9$ s  snf )	Nrr   rj   rm    Tenant: , Database: , Collections: )r   )r   r   rr   rm   rA   r   rl   rs   updateprintr   r   r#   r   )rJ   rc   rd   r   target_nameallCollectionsrl   r   rs   r   found_collectionsr   s               rL   GetCollectionsGrpcMockSysDB.GetCollectionsa  sT    -4,<,<T,B,BDWZZ(	&-&6&6v&>&>gllD!%!J!J!P!P!RF)2):%>>R'Fnn,D##r)h:J:J.J%%k2vhl8*OK=Y *; "S (//1JZ-:z&1[@$$Z0 2 &BSBSJ#J/BS
 	
s   E&c                     [        UR                  UR                  S9nU R                  X5      n[	        [        UR                  5      S9$ )N)rl   rs   )count)r"   rl   rs   r   r   r   r   )rJ   rc   rd   r   s       rL   CountCollectionsGrpcMockSysDB.CountCollections  sF     (>>%%
 ))';'c+2I2I.JKKrN   c                     [        SS9$ )Nr   )total_records_post_compaction)r%   rJ   rc   rd   s      rL   GetCollectionSizeGrpcMockSysDB.GetCollectionSize  s     )*+
 	
rN   c           
         0 nU R                   R                  5        HC  u  pEUR                  5        H*  u  pgUR                  U5        [        SU SU SU 35        M,     ME     UR	                  UR
                  S 5      nUc8  UR                  [        R                  R                  SUR
                   S35        UR                   SUR                   SUR
                   3n	U R                  U	    V
s/ s H  n
U R                  U
   PM     nn
U Vs1 s H  oS   iM	     sn[        R                  [        R                   [        R"                  1:w  a0  UR                  [        R                  R$                  SU S	U 35        ['        [)        U5      U Vs/ s H  n[+        U5      PM     snS
9$ s  sn
f s  snf s  snf )Nr   r   r   zCollection with id rg   r   r   z#Incomplete segments for collection z: )r   r   )rA   r   r   r   getrr   rn   rS   ro   rp   rl   rs   r@   r?   r9   METADATARECORDVECTORINTERNALr'   r   r   )rJ   rc   rd   r   rl   r   rs   r   r   r   rr   r   r   s                rL   GetCollectionWithSegments'GrpcMockSysDB.GetCollectionWithSegments  s    !%!J!J!P!P!RF)2):%%%k2vhl8*OK=Y *; "S $''

D9
MM))-@J+W   !:#6#6"7qE 	
 223HI
I NN2I 	 
 -55HGH5!!:
 

 MM((5j\H:N
 1*:6?GHxG&w/xH
 	

 6 Is   4F2F7F<
c                 .   [        UR                  5      n0 nU R                  R                  5        H2  u  pVUR                  5        H  u  pxUR                  U;   d  M  UnM     M4     UR                  U;  a/  UR                  [        R                  R                  SU S35        g XCR                     n	UR                  S5      (       a  UR                  U	S'   UR                  S5      (       a  UR                  U	S'   UR                  S5      (       aL  [        UR                  5      n
S nU
b$  0 nU
R                  5        H  u  pUc  M
  XU'   M     XS'   [        5       $ UR                  S5      (       a  UR                  (       a  0 U	S'   [        5       $ )Nr   rg   rm   r   r   r   )r   rr   rA   r   rk   rn   rS   ro   rp   r   rm   r   r   r   r   r0   )rJ   rc   rd   r   r   rl   r   rs   maybe_collectionsr   update_metadatacleaned_metadatakeyvalues                 rL   UpdateCollectionGrpcMockSysDB.UpdateCollection  s~    GJJ'!%!J!J!P!P!RF/8/@+##'88"3K 0A "S
 ;.MM))[j+Q %%5%56J''%,\\
6",,*1*;*;
;'
++
 #=W=M=M"N#' ".')$&5&;&;&=
 ,49S1 '> *::&
 ,--	 !!"233))-/Jz*+--rN   c                 6    U R                  5         [        5       $ r[   )r`   r.   r   s      rL   
ResetStateGrpcMockSysDB.ResetState  s     	!##rN   r   sourcec                     [        [        [        [        4   U5      n[        [        [        [        4   [	        U5      5      nUR                  U5        UR                  5        H  u  pVUb  M
  XQ;   d  M  X5	 M     g r[   )r   r   r   r   r   r   r   )rJ   r   r   target_metadatasource_metadatar   r   s          rL   r   GrpcMockSysDB._merge_metadata  sb    tCH~v6tCH~/I&/QR/)//1JC}#( 2rN   )r?   r=   r>   rA   )rO   N)Q__name__
__module____qualname____firstlineno____doc__rS   Server__annotations__r_   r?   r   r   r8   r@   r   rA   r6   rB   r   r   rI   r	   rW   r\   r`   r   ServicerContextr   rt   r(   r)   ry   r   r   r}   r,   r-   r   r   r   r   r   r    r!   r   r*   r+   r   r1   r2   r   r   r   r   r   r   r   r"   r#   r   r   r   r   r$   r%   r   r&   r'   r   r/   r0   r   r5   r.   r   r7   rw   UpdateMetadatar   __static_attributes____classcell__)rK   s   @rL   r;   r;   ;   s   E [[$&ItCL!&46T#tCy.16 	 )$T#tCO,,--+  >@S$sDy/%9 :?(v (     % % u%(,(7;7K7K(	( &( u%
)
484H4H
	
 &
 u%
&*
&595I5I
&	
& &
& u%
'
262F2F
	
 &
 u%:+:6:6J6J:	: &:	'	')-)=)=	'		' u%
+
6:6J6J
	
 &
 u%
)
484H4H
	
 &
6 u%+++6:6J6J+	+ &+& u%X
.X
9=9M9MX
	!X
 &X
t u%.9=9M9M	! &0 u%
,
7;7K7K
	
 &
< u%L.L9=9M9ML	!L &L u%
/
:>:N:N
	"
 &
 u%#
7#
BFBVBV#
	*#
 &#
J u%'..'.9=9M9M'.	!'. &'.R u%$$'+';';$	$ &$)h )8L8L )QU ) )rN   r;   )F
concurrentr   typingr   r   r   r   uuidr   r	   r   chromadb.configr
   r   r   r   chromadb.proto.convertr   r   r   r   r   r   chromadb.proto.chroma_pb2rw   
chroma_pb2chromadb.proto.coordinator_pb2r   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/   r0   r1   r2   #chromadb.proto.coordinator_pb2_grpcr3   r4   rS   google.protobuf.empty_pb2r5   chromadb.typesr6   r7   r8   r9   r;    rN   rL   <module>r     s     ( (    O O  * )                 B  + F Fv)M9 v)rN   