
    3i3                        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  S SKJrJrJrJr  S SKJr  S SKJrJr  S SK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$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/  S SK0J1r2  S SK3J4r4  S SK5J6r6J7r7J8r8  S SK9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrFJGrGJHrHJIrIJJrJJKrKJLrLJMrM  S SKNJOrOJPrPJQrQJRrRJSrSJTrT  S SK0JUrV  S SKWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^J_r_  S SK`Jara  S SKbJcrcJdrd  S SKeJfrf  S SKgrgS SKhrhS SKiriS SK#Jjrj  \_" S\^S\\4   S9rk\hR                  " \m5      rnS\oSS4S  jrpS!\kS\k4S" jrq " S# S$\5      rr    S,S%\VR                  S&\;S'\X\<   S(\X\=   S)\X\>   S*\X\@   S\Z\VR                  SS4   4S+ jjrug)-    )retrystop_after_attemptretry_if_exception
wait_fixed)	ServerAPI)CreateCollectionConfigurationUpdateCollectionConfiguration'create_collection_configuration_to_json)UserIdentity)DEFAULT_DATABASEDEFAULT_TENANTSettingsSystem)SysDB)QuotaEnforcerAction)RateLimitEnforcer)SegmentManager)Executor)ScanFilterLimitKNN
Projection)	CountPlanGetPlanKNNPlan)add_attributes_to_current_spanOpenTelemetryClientOpenTelemetryGranularitytrace_method)ProductTelemetryClient)Producer)
Collection__version__)InvalidDimensionExceptionNotFoundErrorVersionMismatchError)CollectionMetadataIDs
Embeddings	Metadatas	DocumentsSchemaURIsWhereWhereDocumentInclude	GetResultQueryResultSearchResultvalidate_metadatavalidate_update_metadatavalidate_wherevalidate_where_documentvalidate_batchIncludeMetadataDocuments!IncludeMetadataDocumentsDistances)CollectionAddEventCollectionDeleteEventCollectionGetEventCollectionUpdateEventCollectionQueryEventClientCreateCollectionEventN)OptionalSequence	GeneratorListAnyDictCallableTypeVar)override)UUIDuuid4)wraps)SearchT.)bound
index_namereturnc                    SU  3n[        U 5      S:  d  [        U 5      S:  a  [        U5      e[        R                  " SU 5      (       d  [        U5      eSU ;   a  [        U5      e[        R                  " SU 5      (       a  [        U5      eg )Na  Expected collection name that (1) contains 3-63 characters, (2) starts and ends with an alphanumeric character, (3) otherwise contains only alphanumeric characters, underscores or hyphens (-), (4) contains no two consecutive periods (..) and (5) is not a valid IPv4 address, got    ?   z'^[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]$z..z0^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)len
ValueErrorrematch)rS   msgs     N/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/api/segment.pycheck_index_namer^   X   s    	 l	  :c*o2o88=zJJozo	xxEzRRo S    funcc                 X   ^  [        T 5      S[        S[        S[        4U 4S jj5       nU$ )NargskwargsrT   c                  P   > U S   nUR                   R                  T5      " U 0 UD6$ )Nr   )_rate_limit_enforcer
rate_limit)rb   rc   selfr`   s      r]   wrapperrate_limit.<locals>.wrapperm   s-    Aw((33D94J6JJr_   )rO   rH   )r`   rh   s   ` r]   rf   rf   l   s:    
4[Ks Kc Kc K K Nr_   c                     ^  \ rS rSr% Sr\\S'   \\S'   \\S'   \	\S'   \
\S'   \\S'   \\S	'   \\S
'   \\S'   \\S'   S\4U 4S jjr\S\4S j5       r\" S\R,                  5      \\4S\S\SS4S jj5       5       r\" S\R,                  5      \\4S\S\S\R4                  4S jj5       5       r\" S\R,                  5      \\4S\S\SS4S jj5       5       r\" S\R,                  5      \SS\4S\\   S\\   S\S\\R4                     4S jj5       5       r\" S\R,                  5      \S\SS4S j5       5       r \S\!4S  j5       r"\" S!\R,                  5      \S\S\RF                  4S" j5       5       r$\" S#\R,                  5      \\%SSSS$\\&4S\S%\\'   S&\\(   S'\\)   S(\*S\S)\S\+4S* jj5       5       5       r,\" S+\R,                  5      \\%SSS\\&4S\S%\\'   S&\\(   S'\\)   S\S)\S\+4S, jj5       5       5       r-\" S-\R,                  5      \\%S\\&4S\\   S\S)\S\+4S. jj5       5       5       r.\" S/\R,                  5      \\%SS\\&4S\\   S\\   S\S)\S\\+   4
S0 jj5       5       5       r/\" S1\R,                  5      \\%\\&4S\S)\S\4S2 jj5       5       5       r0\" S3\R,                  5      \\%SSS\\&4S4\1S5\\   S6\\)   S7\\2   S\S)\SS4S8 jj5       5       5       r3\\\&4S9\1S5\S\S)\S\+4
S: jj5       r4\\\&4S9\1S;\5\6   S\S)\S\74
S< jj5       r8\" S=\R,                  5      \\%\\&4S\S\S)\SS4S> jj5       5       5       r9\" S?\R,                  5      \\%SSS\\&4S@\:S9\1SA\;SB\\<   SC\\=   SD\\>   S\S)\S\*4SE jj5       5       5       r?\" SF\R,                  5      \\%SSSS\\&4S9\1S@\:SA\\;   SB\\<   SC\\=   SD\\>   S\S)\S\*4SG jj5       5       5       r@\" SH\R,                  5      \\%SSS\\&4S9\1S@\:SA\;SB\\<   SC\\=   SD\\>   S\S)\S\*4SI jj5       5       5       rA\" SJ\R,                  5      \B" \C" SK 5      \D" SL5      \E" SM5      SNSO9\\%SSSSS\F\\&4S9\1S@\\:   SP\\G   S\\   S\\   SQ\\H   SR\IS\S)\S\J4SS jj5       5       5       5       rK\" ST\R,                  5      \\%SSS\\&4S9\1S@\\:   SP\\G   SQ\\H   S\S)\SS4SU jj5       5       5       rL\" SV\R,                  5      \B" \C" SW 5      \D" SL5      \E" SM5      SNSO9\\%\\&4S9\1S\S)\S\4SX jj5       5       5       5       rM\" SY\R,                  5      \B" \C" SZ 5      \D" SL5      \E" SM5      SNSO9\\%SS[SS\N\\&4S9\1S\\;S@\\:   S]\SP\\G   SQ\\H   SR\IS\S)\S\O4S^ jj5       5       5       5       rP\" S_\R,                  5      \\%S[\\&4S9\1S`\S\S)\S\J4
Sa jj5       5       5       rQ\S\4Sb j5       rR\S{Sc j5       rS\S\*4Sd j5       rT\S\4Se j5       rU\S\4Sf j5       rV\S\\&4Sg\Sh\Si\1Sj\Sk\\W\\X4      S\S)\S\Y\*\4   4Sl jj5       rZ\S$\\&4Sg\Si\1Sm\*S\S)\S\*4Sn jj5       r[\" So\R                  5      Sp\R                  Sq\5\R                     SS4Sr j5       r_Sp\R                  Ss\St\*SS4Su jr`\" Sv\R                  5      S9\1S\R                  4Sw j5       ra\" Sx\R,                  5      S9\1S\b4Sy j5       rcSzrdU =re$ )|
SegmentAPIu   zHAPI implementation utilizing the new segment-based internal architecture	_settings_sysdb_manager	_executor	_producer_product_telemetry_client_opentelemetry_client
_tenant_id	_topic_nsre   systemc                   > [         TU ]  U5        UR                  U l        U R	                  [
        5      U l        U R	                  [        5      U l        U R	                  [        5      U l
        U R	                  [        5      U l        U R	                  [        5      U l        U R	                  [        5      U l        U R	                  ["        5      U l        U R&                  R	                  [(        5      U l        g N)super__init__settingsrm   requirer   rn   r   ro   r   rp   r   _quota_enforcerr"   rr   r   rs   r#   rq   _systemr   re   )rg   rv   	__class__s     r]   rz   SegmentAPI.__init__   s     ll5)^4h/#||M:)-6L)M&%)\\2E%F"h/$(LL$8$89J$K!r_   rT   c                 >    [        [        R                  " 5       5      $ rx   )inttimetime_nsrg   s    r]   	heartbeatSegmentAPI.heartbeat   s    4<<>""r_   zSegmentAPI.create_databasenametenantNc                     [        U5      S:  a  [        S5      eU R                  R                  [        R
                  UUS9  U R                  R                  [        5       UUS9  g )NrV   z0Database name must be at least 3 characters long)actionr   r   )idr   r   )	rX   rY   r}   enforcer   CREATE_DATABASErn   create_databaserN   rg   r   r   s      r]   r   SegmentAPI.create_database   sg     t9q=OPP$$)) 	% 	
 	##w 	$ 	
r_   zSegmentAPI.get_databasec                 4    U R                   R                  XS9$ N)r   r   )rn   get_databaser   s      r]   r   SegmentAPI.get_database   s     {{''T'AAr_   zSegmentAPI.delete_databasec                 6    U R                   R                  XS9  g r   )rn   delete_databaser   s      r]   r   SegmentAPI.delete_database   s     	###=r_   zSegmentAPI.list_databaseslimitoffsetc                 6    U R                   R                  XUS9$ )N)r   r   r   )rn   list_databases)rg   r   r   r   s       r]   r   SegmentAPI.list_databases   s     {{))V)TTr_   zSegmentAPI.create_tenantc                 j    [        U5      S:  a  [        S5      eU R                  R                  US9  g )NrV   z.Tenant name must be at least 3 characters longr   )rX   rY   rn   create_tenantrg   r   s     r]   r   SegmentAPI.create_tenant   s5     t9q=MNN!! 	" 	
r_   c                 *    [        S[        [        /S9$ )N )user_idr   	databases)r   r   r   r   s    r]   get_user_identitySegmentAPI.get_user_identity   s    !'(
 	
r_   zSegmentAPI.get_tenantc                 4    U R                   R                  US9$ )Nr   )rn   
get_tenantr   s     r]   r   SegmentAPI.get_tenant   s     {{%%4%00r_   zSegmentAPI.create_collectionFschemaconfigurationmetadataget_or_createdatabasec                    Ub  [        U5        [        U5        U R                  R                  [        R
                  UUUS9  [        5       n[        UUUS [        U=(       d
    [        5       U5      UUS S9n	U R                  R                  U	R                  U	R                  UU=(       d
    [        5       / U	R                  S UUUS9
u  pU(       a@  U R                  R!                  U
5      nU H  nU R                  R#                  U5        M      O[$        R'                  SU S35        U R(                  R+                  [-        [/        U5      S95        [1        S[/        U5      05        U
$ )Nr   r   r   r   )r   r   r   serialized_schemaconfiguration_jsonr   r   	dimension)
r   r   r   r   segmentsr   r   r   r   r   Collection z/ already exists, returning existing collection.)collection_uuidr   )r7   r^   r}   r   r   CREATE_COLLECTIONrN   CollectionModelr
   r   rn   create_collectionr   r   r   ro   #prepare_segments_for_new_collectioncreate_segmentloggerdebugrr   capturerC   strr   )rg   r   r   r   r   r   r   r   r   modelcollcreatedr   segments                 r]   r   SegmentAPI.create_collection   se    h' 	$$++	 	% 	
 W"F@!>!@(  
 55xx'J+H+J^^' 6 
 }}HHNH#**73 $ LLdV#RS 	&&..' #B	
 	'(93r7'CDr_   z#SegmentAPI.get_or_create_collectionc           
      ,    U R                  UUUUSUUS9$ )NT)r   r   r   r   r   r   r   )r   )rg   r   r   r   r   r   r   s          r]   get_or_create_collection#SegmentAPI.get_or_create_collection  s1     %%' & 
 	
r_   zSegmentAPI.get_collectionc                 l    U R                   R                  XUS9nU(       a  US   $ [        SU S35      e)Nr   r   r   r   r    does not exist.)rn   get_collectionsr(   rg   r   r   r   existings        r]   get_collectionSegmentAPI.get_collection:  sF     ;;..x / 
 A;+dV3C DEEr_   zSegmentAPI.list_collectionc                     U R                   R                  [        R                  UUS9  U R                  R                  XX4S9$ )N)r   r   r   )r   r   r   r   )r}   r   r   LIST_COLLECTIONSrn   r   )rg   r   r   r   r   s        r]   list_collectionsSegmentAPI.list_collectionsL  sO     	$$** 	% 	
 {{**v + 
 	
r_   zSegmentAPI.count_collectionsc                 4    U R                   R                  XS9$ )Nr   r   )rn   count_collections)rg   r   r   s      r]   r   SegmentAPI.count_collections`  s     {{,,F,NNr_   zSegmentAPI._modifyr   new_namenew_metadatanew_configurationc                    U(       a  [        U5        U(       a  [        U5        U R                  U5      nU R                  R	                  [
        R                  UUUS9  U(       a+  U(       a$  U(       a  U R                  R                  UUUUS9  g U(       a"  U(       a  U R                  R                  XUS9  g U(       a"  U(       a  U R                  R                  XUS9  g U(       a"  U(       a  U R                  R                  XUS9  g U(       a  U R                  R                  XS9  g U(       a  U R                  R                  XS9  g U(       a  U R                  R                  XS9  g g )	Nr   )r   r   r   )r   r   )r   r   )r   r   r   )r   )r   )	r^   r8   _get_collectionr}   r   r   UPDATE_COLLECTIONrn   update_collection)rg   r   r   r   r   r   r   _s           r]   _modifySegmentAPI._modifyj  s9    X&$\2   $$$++!	 	% 	
 ):KK))%/	 *  ,KK))"l)S+KK))1B *  /KK))9J *  KK))")<KK))")DKK))")N r_   collection_idc                     [        S5      e)Nz4Collection forking is not implemented for SegmentAPINotImplementedError)rg   r   r   r   r   s        r]   _forkSegmentAPI._fork  s     "B
 	
r_   searchesc                     [        S5      e)Nz(Search is not implemented for SegmentAPIr   )rg   r   r   r   r   s        r]   _searchSegmentAPI._search  s     ""LMMr_   zSegmentAPI.delete_collectionc                    U R                   R                  XUS9nU(       aP  U R                  R                  US   R                  5        U R                   R                  US   R                  X#S9  g [        SU S35      e)Nr   r   r   r   r   )rn   r   ro   delete_segmentsr   delete_collectionrY   r   s        r]   r   SegmentAPI.delete_collection  s|     ;;..x / 
 MM))(1+..9KK))v *  {4&0@ABBr_   zSegmentAPI._addids
embeddings	metadatas	documentsurisc	                    U R                  U5      n	U R                  R                  U[        R                  R
                  5        [        XXEU4SU R                  5       05        [        [        [        R                  R
                  UUUUUS95      n
U R                  X5        U R                  R                  [        R
                  UUUUUUUS9  U R                  R                  X*5        U R                   R#                  [%        ['        U5      [)        U5      Ub  [)        U5      OSUb  [)        U5      OSUb  [)        U5      OSS95        g)Nmax_batch_sizer   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   
add_amountwith_metadatawith_documents	with_urisT)r   ro   hint_use_collectiont	OperationADDr;   get_max_batch_sizelist_records_validate_embedding_record_setr}   r   r   rq   submit_embeddingsrr   r   r>   r   rX   )rg   r   r   r   r   r   r   r   r   r   records_to_submits              r]   _addSegmentAPI._add  s5    ##M2))-IiD9t6689	
 !%##	
 	++DD$$::!' 	% 		
 	((J&&.. #M 2s8*3*?c#hQ+4+@s3xa&*&6#c(A	
 r_   zSegmentAPI._updatec	                    U R                  U5      n	U R                  R                  U[        R                  R
                  5        [        X#XEU4SU R                  5       05        [        [        [        R                  R
                  UUUUUS95      n
U R                  X5        U R                  R                  [        R
                  UUUUUUS9  U R                  R                  X5        U R                   R#                  [%        ['        U5      [)        U5      U(       a  [)        U5      OSU(       a  [)        U5      OSU(       a  [)        U5      OSU(       a  [)        U5      OSS95        g)Nr   r   )r   r   r   r   r   r   r   r   )r   update_amountwith_embeddingsr   r   r   T)r   ro   r   r   r  UPDATEr;   r  r  r  r  r}   r   r   rq   r  rr   r   rA   r   rX   rg   r   r   r   r   r   r   r   r   r   r  s              r]   _updateSegmentAPI._update  s8    ##M2))-9K9KLiD9t6689	
 !""%##	
 	++DD$$==! 	% 	
 	((J&&..! #M 2!#h3=J109c)nq1:s9~'+#d)		
 r_   zSegmentAPI._upsertc	                    U R                  U5      n	U R                  R                  U[        R                  R
                  5        [        X#XEU4SU R                  5       05        [        [        [        R                  R
                  UUUUUS95      n
U R                  X5        U R                  R                  [        R
                  UUUUUUUS9  U R                  R                  X5        g)Nr   r   r   T)r   ro   r   r   r  UPSERTr;   r  r  r  r  r}   r   r   rq   r  r  s              r]   _upsertSegmentAPI._upsert=  s     ##M2))-9K9KLiD9t6689	
 !""%##	
 	++DD$$==!' 	% 		
 	((Jr_   zSegmentAPI._getc                 "    [        U [        5      $ rx   
isinstancer)   es    r]   <lambda>SegmentAPI.<lambda>n      :a9M+Nr_         T)r   waitstopreraisewherewhere_documentincludec
                    [        [        U5      U(       a  [        U5      OSS.5        U R                  U5      n
Ub  [	        U5        Ub  [        U5        U R                  R                  [        R                  UUUUUS9  U(       a  [        U5      OSnU R                  R                  [        [        U5      UU(       a  UOSSU;   a  UOSSU;   a  UOSSU;   a  UOSS95        U R                  R                  [        U
[!        X#U5      [#        U=(       d    SU5      [%        SU;   SU;   SU;   S	SU;   5      5      5      $ )
Nr   r   	ids_count)r   r   r   r#  r$  r   r   r   r   )r   r(  r   include_metadatainclude_documentsinclude_urisr   F)r   r   rX   _scanr9   r:   r}   r   r   GETrr   r   r@   rp   getr   r   r   r   )rg   r   r   r#  r   r   r$  r%  r   r   scan
ids_amounts               r]   _getSegmentAPI._getl  sI   * 	'!$]!3),SX!	
 zz-( 5!%#N3$$::) 	% 	
 "%SX!
&&.. #M 2$$e!/:g/E10;w0F*A+1W+<Z!		
 ~~!!s>2fk5)7* G+7*g%	
 	
r_   zSegmentAPI._deletec           
         [        [        U5      U(       a  [        U5      OSS.5        Ub  [        U5        Ub  [	        U5        Ub  UbD  [        U5      S:X  a5  Ub  Ub/  [        U5      S:X  a   Ub  Ub  [        U5      S:X  a  [        S5      eU R                  U5      nU R                  R                  [        R                  UUUUS9  U R                  R                  U[        R                  R                  5        U(       d  U(       d  U(       d3  U R                  R!                  [#        U[%        X#U5      5      5      S   nOUn[        U5      S:X  a  g ['        [)        [        R                  R                  US95      n	U R+                  UR,                  U	5        U R.                  R1                  X5        U R2                  R5                  [7        [        U5      [        U5      S95        g )Nr   r'  aU  
                You must provide either ids, where, or where_document to delete. If
                you want to delete all data in a collection you can delete the
                collection itself using the delete_collection method. Or alternatively,
                you can get() all the relevant ids and then delete them.
                )r   r   r   r#  r$  r   )	operationr   )r   delete_amount)r   r   rX   r9   r:   rY   r,  r}   r   r   DELETEro   r   r   r  rp   r.  r   r   r  r  r  
collectionrq   r  rr   r   r?   )
rg   r   r   r#  r$  r   r   r/  ids_to_deleter  s
             r]   _deleteSegmentAPI._delete  s    	'!$]!3),SX!	
 5!%#N3 [S_SQ5#4Uq&".3~3F!3K   zz-($$==) 	% 	
 	))-9K9KL^C NN..fS@AM  M}" q{{11}E
 	++DOO=NO((J&&..! #M 2#mBT	
r_   zSegmentAPI._countc                 "    [        U [        5      $ rx   r  r  s    r]   r  r    r  r_   c                     [        S[        U5      05        U R                  R                  [	        U R                  U5      5      5      $ )Nr   )r   r   rp   countr   r,  )rg   r   r   r   s       r]   _countSegmentAPI._count  s9     	']9K'LM~~##Idjj.G$HIIr_   zSegmentAPI._queryc                 "    [        U [        5      $ rx   r  r  s    r]   r  r    r  r_   
   query_embeddings	n_resultsc
                    [        [        U5      U[        U5      S.5        [        U5      n
U(       a  [        U5      OSnU R                  R	                  [        [        U5      U
UUUb  U
OSUb  U
OSSU;   a  U
OSSU;   a  U
OSSU;   a  U
OSSU;   a  U
OSS9
5        Ub  [        U5        Ub  [        U5        U R                  U5      nU H'  nU R                  UR                  [        U5      SS	9  M)     U R                  R                  [        R                  UUUUUS
9  U R                  R!                  [#        U[%        X$5      ['        S XV5      [)        SU;   SU;   SU;   SU;   SU;   5      5      5      $ )N)r   rC  r#  r   r   r   r   	distances)
r   query_amountfiltered_ids_amountrC  with_metadata_filterwith_document_filterinclude_metadatasr*  r+  include_distancesFupdate)r   r   r#  r$  rB  rC  r   )r   r   rX   rr   r   rB   r9   r:   r,  _validate_dimensionr7  r}   r   r   QUERYrp   knnr   r   r   r   )rg   r   rB  r   rC  r#  r$  r%  r   r   rF  r0  r/  	embeddings                 r]   _querySegmentAPI._query  s   8 	'!$]!3&U	
 +,!$SX!
&&..  #M 2)$.#5:5F\A5C5O\UV2=2H,a2=2H,a-3w->\A2=2H,a	
  5!%#N3zz-()I$$T__c)nU$S * 	$$<<)- 	% 	
 ~~!!$0tU37* G+7*7*g%	
 	
r_   zSegmentAPI._peeknc                 L    [        S[        U5      05        U R                  XS9$ )Nr   )r   )r   r   r1  )rg   r   rT  r   r   s        r]   _peekSegmentAPI._peekl  s'     	']9K'LMyyy00r_   c                     [         $ rx   r%   r   s    r]   get_versionSegmentAPI.get_versiony  s    r_   c                     g rx    r   s    r]   reset_stateSegmentAPI.reset_state}  s    r_   c                 8    U R                   R                  5         g)NT)r~   r]  r   s    r]   resetSegmentAPI.reset  s      "r_   c                     U R                   $ rx   )rm   r   s    r]   get_settingsSegmentAPI.get_settings  s    ~~r_   c                 .    U R                   R                  $ rx   )rq   r   r   s    r]   r  SegmentAPI.get_max_batch_size  s    ~~,,,r_   	task_nameoperator_nameinput_collection_idoutput_collection_nameparamsc                     [        S5      ezATasks are not supported in the Segment API (local embedded mode).zTasks are only supported when connecting to a Chroma server via HttpClient. The Segment API (embedded mode) does not support task operations.r   )rg   rg  rh  ri  rj  rk  r   r   s           r]   create_taskSegmentAPI.create_task  s     "P
 	
r_   delete_outputc                     [        S5      erm  r   )rg   rg  ri  rp  r   r   s         r]   remove_taskSegmentAPI.remove_task  s     "P
 	
r_   z)SegmentAPI._validate_embedding_record_setr7  recordsc                     [        S[        US   5      05        U H(  nUS   c  M  U R                  U[        US   5      SS9  M*     g)zQValidate the dimension of an embedding record before submitting it to the system.r   r   rQ  NTrL  )r   r   rN  rX   )rg   r7  rt  records       r]   r  )SegmentAPI._validate_embedding_record_set  sT     	'Z=M9N'OPFk".((F;$7 8 )  r_   dimrM  c                     US   c2  U(       a*  UR                   nU R                  R                  XBS9  X!S'   ggUS   U:w  a  [        SU SUS    35      eg)zValidate that a collection supports records of the given dimension. If update
is true, update the collection if the collection doesn't already have a
dimension.r   N)r   r   zEmbedding dimension z* does not match collection dimensionality )r   rn   r   r'   )rg   r7  rx  rM  r   s        r]   rN  SegmentAPI._validate_dimension  sw     k"*]]---C*-;'  $++&se+UV`alVmUno  r_   zSegmentAPI._get_collectionc                     U R                   R                  US9nU(       a  [        U5      S:X  a  [        SU S35      eUS   $ )N)r   r   r   r   )rn   r   rX   r(   )rg   r   collectionss      r]   r   SegmentAPI._get_collection  sG    kk11]1Cc+.!3+m_<L MNN1~r_   zSegmentAPI._scanc           	      L   U R                   R                  U5      nUS    Vs0 s H  o3S   U_M
     nn[        US   U[        R                  R
                     U[        R                  R                     UR                  [        R                  R                  S 5      S9$ s  snf )Nr   scoper7  )r7  rP  r   rv  )	rn   get_collection_with_segmentsr   r   SegmentScopeVECTORMETADATAr.  RECORD)rg   r   collection_and_segmentsr   scope_to_segments        r]   r,  SegmentAPI._scan  s    "&++"J"J#
 6MZ5X
5X'Gg%5X 	 
 .|< !6!67%ann&=&=>#''(=(=tD
 	

s   B!)	rp   ro   rs   rq   rr   r}   re   rm   rn   )rT   N)f__name__
__module____qualname____firstlineno____doc__r   __annotations__r   r   r   r#   r"   r   r   r   r   rz   rL   r   r   r!   r    	OPERATIONr   r   r   Databaser   r   rD   rE   r   r   r   r   Tenantr   rf   r   r/   r   r*   boolr   r   r   r   r   r   rM   r	   r   r   rG   rP   r6   r   r   r+   r,   r-   r.   r0   r	  r  r  r   r   r   r   r<   r1   r2   r3   r4   r1  r9  r>  r=   r5   rR  rV  rY  r]  r`  rc  r  rI   rH   tuplern  rr  ALLr$   OperationRecordr  rN  r   r   r,  __static_attributes____classcell__)r   s   @r]   rk   rk   u   sU   RM55..ON++
Lv 
L #3 # # .0H0R0RS7E 
C 
 
$ 
  T
  +-E-O-OP4B B Bc Bqzz B  QB .0H0R0RS7E >C > >$ >  T> -/G/Q/QR  $ $$	U}U U 	U
 
!**	U  SU ,.F.P.PQ
# 
$ 
  R
 
< 
 
 )+C+M+MN1s 1qxx 1  O1 02J2T2TU $(AE15#$(GG  G   =>	G
 -.G G G G 
G   VGR -/G/Q/Q  $(AE15$(

  
   =>	

 -.
 
 
 

  

, -/G/Q/QR #$(	FsmF F 	F
 
F   SF .0H0R0RS  $ $$(
}
 
 	

 
 
/	"
   T
" 02J2T2TU %(OO O 
	O   VO &(@(J(JK #'59EI$(2O2O 3-2O 12	2O
 $$AB2O 2O 2O 
2O   L2Oh 
 %(	
	
 	
 		

 	
 
	
 	
 
 %(NN v,N 	N
 N 
N N 02J2T2TU %(	CC C 	C
 
C   VC$ #%=%G%GH *.)-#$(33 3 	3
 I&3 I&3 tn3 3 3 
3   I3j &(@(J(JK
 ,0)-)-#$(44 4 Z(	4
 I&4 I&4 tn4 4 4 
4   L4l &(@(J(JK *.)-#$(** * 	*
 I&* I&* tn* * * 
*   L*X #%=%G%GH
 !NO]"	  "!%# $263$(>
>
 c]>
 	>

 }>
 >
 !/>
 >
 >
 >
 
>
   I>
@ &(@(J(JK "!%26$(I
I
 c]I
 	I

 !/I
 I
 I
 
I
   LI
V %'?'I'IJ
 !NO]"	  %(	JJ J 	J
 
J   KJ %'?'I'IJ  !NO]"	 
 "!%26<$(E
E
 %E
 c]	E

 E
 E
 !/E
 E
 E
 E
 
E
   K E
N $&>&H&HI $(11 1 	1
 1 
1   J1 S     t   h   -C - -  ,0$(

 
 "	

 !$
 c3h(
 
 
 
tSy	
 
  
 $$(

 "
 	

 
 
 

 
$ 35M5Q5Q	,,	15a6G6G1H				,,-0:>	$ .0H0L0LMT all  N $&>&H&HI
4 
D 
 J
r_   rk   r4  r   r   r   r   r   c           	   #   P  #    U/ :X  a  Sn[        U5       H  u  pgSnU(       a  X6   nU(       a  XF   n	U(       a	  0 UESU	0EnOSU	0nU(       a  XV   n
U(       a	  0 UESU
0EnOSU
0n[        R                  " UUb  X&   OS[        R                  R                  UU S9nUv   M     g7f)zeConvert parallel lists of embeddings, metadatas and documents to a sequence of
SubmitEmbeddingRecordsNzchroma:documentz
chroma:uri)r   rQ  encodingr   r4  )	enumerater   r  ScalarEncodingFLOAT32)r4  r   r   r   r   r   ir   r   documenturirv  s               r]   r  r    s      R
3 |H |HDhD(98D-x8'C:h:c:(#.""'1'=jm4%%--
 5  s   B$B&)NNNN)vtenacityr   r   r   r   chromadb.apir   %chromadb.api.collection_configurationr   r	   r
   chromadb.authr   chromadb.configr   r   r   r   chromadb.db.systemr   chromadb.quotar   r   chromadb.rate_limitr   chromadb.segmentr   $chromadb.execution.executor.abstractr   &chromadb.execution.expression.operatorr   r   r   r   r   "chromadb.execution.expression.planr   r   r    chromadb.telemetry.opentelemetryr   r   r    r!   chromadb.telemetry.productr"   chromadb.ingestr#   chromadb.typesr$   r   chromadbr&   chromadb.errorsr'   r(   r)   chromadb.api.typesr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   !chromadb.telemetry.product.eventsr>   r?   r@   rA   rB   rC   typesr   typingrD   rE   rF   rG   rH   rI   rJ   rK   	overridesrL   uuidrM   rN   	functoolsrO   r   loggingrZ   rP   rQ   	getLoggerr  r   r   r^   rf   rk   r  r  r  r\  r_   r]   <module>r     s   N N " 
 ' N N $ 0 1 + 9 W W J J  > $ 8   
     ,  	 	 	      	 5CxS)*			8	$  (Q 1 v
 v
x (,%)%),{{,	, $, 	"	,
 	", 4., q  $,-,r_   