
    ui                     P    d dl mZmZmZmZ d dlmZmZmZm	Z	  G d d          Z
dS )    )DictListSetcast)	LogRecord	OperationSeqIdVectorc                   L   e Zd ZU dZeeef         ed<   ee         ed<   ee         ed<   ee         ed<   e	ed<   e	ed<   e
ed<   ddZd	e	fdZd	ee         fdZd	ee         fdZdee         d	ee         fdZded	efdZded	efdZed	e	fd            Zddeded	d
fdZd
S )Batchz7Used to model the set of changes as an atomic operation_ids_to_records_deleted_ids_written_ids_upsert_add_ids	add_countupdate_count
max_seq_idreturnNc                     i | _         t                      | _        t                      | _        t                      | _        d| _        d| _        d| _        d S )Nr   )r   setr   r   r   r   r   r   selfs    U/var/www/icac/venv/lib/python3.11/site-packages/chromadb/segment/impl/vector/batch.py__init__zBatch.__init__   sH    !EEEE"uu    c                 T    t          | j                  t          | j                  z   S )z'Get the number of changes in this batch)lenr   r   r   s    r   __len__zBatch.__len__   s#    4$%%D,=(>(>>>r   c                 *    t          | j                  S )z0Get the list of deleted embeddings in this batch)listr   r   s    r   get_deleted_idszBatch.get_deleted_ids       D%&&&r   c                 *    t          | j                  S )z0Get the list of written embeddings in this batch)r    r   r   s    r   get_written_idszBatch.get_written_ids"   r"   r   idsc                        fd|D             S )z.Get the list of vectors to write in this batchc                 h    g | ].}t          t          j        |         d          d                   /S )operation_record	embedding)r   r
   r   ).0idr   s     r   
<listcomp>z-Batch.get_written_vectors.<locals>.<listcomp>(   sF     
 
 
 -b12DEkRSS
 
 
r    )r   r%   s   ` r   get_written_vectorszBatch.get_written_vectors&   s.    
 
 
 

 
 
 	
r   r+   c                     | j         |         S )zGet the record for a given ID)r   r   r+   s     r   
get_recordzBatch.get_record-   s    #B''r   c                     || j         v S )zCheck if a given ID is deleted)r   r0   s     r   
is_deletedzBatch.is_deleted1   s    T&&&r   c                 *    t          | j                  S )N)r   r   r   s    r   delete_countzBatch.delete_count5   s    4$%%%r   Frecordexists_alreadyc                 b   |d         d         }|d         d         t           j        k    ri|| j        v r*| j                            |           | j        |         d         d         t           j        k    r| xj        dz  c_        n| j        |         d         d         t           j        k    r+| xj        dz  c_        | j	        
                    |           n| j        |         d         d         t           j        k    r^|| j        v r+| xj        dz  c_        | j                            |           nN| xj        dz  c_        | j	        
                    |           n#|| j	        vr| j	        
                    |           || j        v r| j        |= n|| j        |<   | j        
                    |           || j	        v r| j	                            |           |d         d         t           j        k    r>|s+| xj        dz  c_        | j        
                    |           nj| xj        dz  c_        nY|d         d         t           j        k    r| xj        dz  c_        n,|d         d         t           j        k    r| xj        dz  c_        t          | j        |d                   | _        dS )ak  Apply an embedding record to this batch. Records passed to this method are assumed to be validated for correctness.
        For example, a delete or update presumes the ID exists in the index. An add presumes the ID does not exist in the index.
        The exists_already flag should be set to True if the ID does exist in the index, and False otherwise.
        r(   r+   	operation   
log_offsetN)r   DELETEr   remover   ADDr   UPDATEr   r   addUPSERTr   maxr   )r   r6   r7   r+   s       r   applyzBatch.apply9   s    &'-$%k2i6FFF T&&&!((,,,(,-?@M }% % NNa'NNN(,-?@M '( ( %%*%%%))"----(,-?@M '( ( T111!+,33B7777))Q.)))--b1114,,,!%%b))) T)))(, (.D $!!"%%% T&&&!((,,, ()+6):JJJ% +NNa'NN(,,R0000%%*%%%*+K8IMII!#*+K8I<LLL!!Q&!!dovl/CDDr   )r   N)F)__name__
__module____qualname____doc__r   strr   __annotations__r   intr	   r   r   r   r!   r$   r
   r.   r1   boolr3   propertyr5   rC   r-   r   r   r   r      s        AA#y.))))c(c(XNNN   ? ? ? ? ?'c ' ' ' ''c ' ' ' '
tCy 
T&\ 
 
 
 
(S (Y ( ( ( ('S 'T ' ' ' ' &c & & & X&=E =EI =Et =E =E =E =E =E =E =Er   r   N)typingr   r   r   r   chromadb.typesr   r   r	   r
   r   r-   r   r   <module>rO      s    ( ( ( ( ( ( ( ( ( ( ( ( > > > > > > > > > > > >pE pE pE pE pE pE pE pE pE pEr   