
    ugu                     D    d dl mZmZmZmZ d dlmZmZmZ  G d d      Z	y)    )DictListSetcast)	LogRecord	OperationVectorc                   
   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<   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y	)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returnNc                     i | _         t               | _        t               | _        t               | _        d| _        d| _        y )Nr   )r   setr   r   r   r   r   selfs    W/var/www/openai/venv/lib/python3.12/site-packages/chromadb/segment/impl/vector/batch.py__init__zBatch.__init__   s7    !EE"u    c                 X    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                 n    |D cg c]%  }t        t        | j                  |   d   d         ' c}S c c}w )z.Get the list of vectors to write in this batchrecord	embedding)r   r	   r   )r   r#   ids      r   get_written_vectorszBatch.get_written_vectors#   sD     UX
TWbD--b1(;KHITW
 	
 
s   *2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   r*   s     r   
is_deletedzBatch.is_deleted-   s    T&&&&r   c                 ,    t        | j                        S )N)r   r   r   s    r   delete_countzBatch.delete_count1   s    4$$%%r   r%   exists_alreadyc                    |d   d   }|d   d   t         j                  k(  r|| j                  v rE| j                  j                  |       | j                  |   d   d   t         j
                  k(  r| xj                  dz  c_        n| j                  |   d   d   t         j                  k(  r1| xj                  dz  c_        | j                  j                  |       n| j                  |   d   d   t         j                  k(  r|| j                  v r1| xj                  dz  c_        | j                  j                  |       nZ| xj                  dz  c_        | j                  j                  |       n)|| j                  vr| j                  j                  |       || j                  v r| j                  |= yy|| j                  |<   | j                  j                  |       || j                  v r| j                  j                  |       |d   d   t         j                  k(  rI|s1| xj                  dz  c_        | j                  j                  |       y| xj                  dz  c_        y|d   d   t         j
                  k(  r| xj                  dz  c_        y|d   d   t         j                  k(  r| xj                  dz  c_        yy)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   N)r   DELETEr   remover   ADDr   UPDATEr   r   addUPSERTr   )r   r%   r0   r'   s       r   applyzBatch.apply5   sp   
 Hd#(K(I,<,<< T&&&!!((,''+H5kBimmSNNa'N((,X6{CyGWGWW%%*%%%))"-((,X6{CyGWGWWT111!+,,33B7))Q.)))--b14,,,!!%%b) T)))((, * (.D  $!!"% T&&&!!((, h,	0@0@@%NNa'N((,,R0%%*%!+.)--?!#!+.)2B2BB!!Q&! Cr   )r   N)F)__name__
__module____qualname____doc__r   strr   __annotations__r   intr   r   r   r   r"   r	   r(   r+   boolr-   propertyr/   r:    r   r   r   r      s    A#y.))c(c(XN? ?'c ''c '
tCy 
T&\ 
(S (Y ('S 'T ' &c & &5'I 5't 5' 5'r   r   N)
typingr   r   r   r   chromadb.typesr   r   r	   r   rD   r   r   <module>rG      s    ( ( 7 7e' e'r   