
    _ju                     L    d dl mZmZmZmZ d dlmZmZmZ  G d d          Z	dS )    )DictListSetcast)	LogRecord	OperationVectorc                   B   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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returnNc                     i | _         t                      | _        t                      | _        t                      | _        d| _        d| _        d S )Nr   )r   setr   r   r   r   r   selfs    _/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/segment/impl/vector/batch.py__init__zBatch.__init__   sC    !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 )record	embedding)r   r	   r   ).0idr   s     r   
<listcomp>z-Batch.get_written_vectors.<locals>.<listcomp>%   sB     
 
 
NPD-b1(;KHII
 
 
r    )r   r#   s   ` r   get_written_vectorszBatch.get_written_vectors#   s.    
 
 
 
TW
 
 
 	
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   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   Fr&   exists_alreadyc                 2   |d         d         }|d         d         t           j        k    rl|| 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        |= dS dS || j        |<   | j        
                    |           || j	        v r| j	                            |           |d         d         t           j        k    r@|s,| xj        dz  c_        | j        
                    |           dS | xj        dz  c_        dS |d         d         t           j        k    r| xj        dz  c_        dS |d         d         t           j        k    r| xj        dz  c_        dS 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   N)r   DELETEr   remover   ADDr   UPDATEr   r   addUPSERTr   )r   r&   r4   r)   s       r   applyzBatch.apply5   s   
 Hd#(K(I,<<< T&&&!((,,,'+H5kBimSSNNa'NNN(,X6{CyGWWW%%*%%%))"----(,X6{CyGWWWT111!+,33B7777))Q.)))--b1114,,,!%%b))) T)))(,,, *) (.D $!!"%%% T&&&!((,,, h,	0@@@% +NNa'NN(,,R00000%%*%%%%!+.)-??!#!+.)2BBB!!Q&!!!! CBr   )r   N)F)__name__
__module____qualname____doc__r   strr   __annotations__r   intr   r   r   r   r"   r	   r,   r/   boolr1   propertyr3   r>   r+   r   r   r   r      s        AA#y.))))c(c(XNNN   ? ? ? ? ?'c ' ' ' ''c ' ' ' '
tCy 
T&\ 
 
 
 
(S (Y ( ( ( ('S 'T ' ' ' ' &c & & & X&5' 5'I 5't 5' 5' 5' 5' 5' 5' 5'r   r   N)
typingr   r   r   r   chromadb.typesr   r   r	   r   r+   r   r   <module>rJ      s    ( ( ( ( ( ( ( ( ( ( ( ( 7 7 7 7 7 7 7 7 7 7e' e' e' e' e' e' e' e' e' e'r   