o
    gu                     @   s>   d dl mZmZmZmZ d dlmZmZmZ G dd dZ	dS )    )DictListSetcast)	LogRecord	OperationVectorc                   @   s   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
dZ
de	fddZdee fddZdee fddZdee dee fddZdedefddZdedefddZede	fddZd"dededd	fd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                 C   s.   i | _ t | _t | _t | _d| _d| _d S )Nr   )r
   setr   r   r   r   r   self r   Y/var/www/visachat/venv/lib/python3.10/site-packages/chromadb/segment/impl/vector/batch.py__init__   s   
zBatch.__init__c                 C   s   t | jt | j S )z'Get the number of changes in this batch)lenr   r   r   r   r   r   __len__   s   zBatch.__len__c                 C   
   t | jS )z0Get the list of deleted embeddings in this batch)listr   r   r   r   r   get_deleted_ids      
zBatch.get_deleted_idsc                 C   r   )z0Get the list of written embeddings in this batch)r   r   r   r   r   r   get_written_ids   r   zBatch.get_written_idsidsc                    s    fdd|D S )z.Get the list of vectors to write in this batchc                    s$   g | ]}t t j| d  d qS )record	embedding)r   r   r
   ).0idr   r   r   
<listcomp>%   s    z-Batch.get_written_vectors.<locals>.<listcomp>r   )r   r   r   r   r   get_written_vectors#   s   
zBatch.get_written_vectorsr"   c                 C   s
   | j | S )zGet the record for a given ID)r
   r   r"   r   r   r   
get_record)   r   zBatch.get_recordc                 C   s
   || j v S )zCheck if a given ID is deleted)r   r%   r   r   r   
is_deleted-   r   zBatch.is_deletedc                 C   r   )N)r   r   r   r   r   r   delete_count1   r   zBatch.delete_countFr   exists_alreadyc                 C   s  |d d }|d d t jkr|| jv ru| j| | j| d d t jkr.|  jd8  _nR| j| d d t jkrH|  jd8  _| j	
| n8| j| d d t jkrt|| jv rg|  jd8  _| j| n|  jd8  _| 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|  jd7  _| j
| dS |  jd7  _dS |d d t jkr|  jd7  _dS |d d t jkr|  jd7  _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   r)   r"   r   r   r   apply5   sF   





zBatch.apply)r   N)F)__name__
__module____qualname____doc__r   strr   __annotations__r   intr   r   r   r   r   r   r$   r&   boolr'   propertyr(   r2   r   r   r   r   r	      s$   
 
r	   N)
typingr   r   r   r   chromadb.typesr   r   r   r	   r   r   r   r   <module>   s    