
    ug                         d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlZde
ded	efd
Zdeded	e
fdZ G d de      Zeee   gdf   Z G d de      Zy)    )abstractmethod)CallableOptionalSequence)OperationRecord	LogRecordSeqIdVectorScalarEncoding)	Component)UUIDNvectorencodingreturnc                 J   |t         j                  k(  r3t        j                  | t        j                        j                         S |t         j                  k(  r3t        j                  | t        j                        j                         S t        d|j                         )z"Encode a vector into a byte array.dtypeUnsupported encoding: )
r   FLOAT32nparrayfloat32tobytesINT32int32
ValueErrorvaluer   r   s     M/var/www/openai/venv/lib/python3.12/site-packages/chromadb/ingest/__init__.pyencode_vectorr       st     >)))xxbjj199;;	^))	)xxbhh/77991(..1ABCC    c                    |t         j                  k(  r%t        j                  | t        j                        S |t         j
                  k(  r%t        j                  | t        j                        S t        d|j                         )z!Decode a byte array into a vectorr   r   )r   r   r   
frombufferr   r   r   r   r   s     r   decode_vectorr$      sb     >)))}}V2::66	^))	)}}V2::661(..1ABCCr!   c                       e Zd ZdZededdfd       Zededdfd       Zededede	fd       Z
eded	ee   dee	   fd
       Zeedefd              Zy)Producerz4Interface for writing embeddings to an ingest streamcollection_idr   Nc                      y )N selfr'   s     r   
delete_logzProducer.delete_log(   s    r!   c                      y)zFTruncates the log for the given collection, removing all seen records.Nr)   r*   s     r   	purge_logzProducer.purge_log,        	r!   	embeddingc                      y)zVAdd an embedding record to the given collections log. Returns the SeqID of the record.Nr)   )r+   r'   r0   s      r   submit_embeddingzProducer.submit_embedding1       
 	r!   
embeddingsc                      y)a  Add a batch of embedding records to the given collections log. Returns the SeqIDs of
        the records. The returned SeqIDs will be in the same order as the given
        SubmitEmbeddingRecords. However, it is not guaranteed that the SeqIDs will be
        processed in the same order as the given SubmitEmbeddingRecords. If the number
        of records exceeds the maximum batch size, an exception will be thrown.Nr)   )r+   r'   r4   s      r   submit_embeddingszProducer.submit_embeddings8   s     	r!   c                      y)ziReturn the maximum number of records that can be submitted in a single call
        to submit_embeddings.Nr)   r+   s    r   max_batch_sizezProducer.max_batch_sizeC   r3   r!   )__name__
__module____qualname____doc__r   r   r,   r.   r   r	   r2   r   r6   propertyintr9   r)   r!   r   r&   r&   %   s    >    t    !.=	  !/7/H	%     r!   r&   c                       e Zd ZdZe	 	 	 ddededee   dee   dee   defd	       Z	ed
eddfd       Z
edefd       Zedefd       Zy)Consumerz5Interface for reading embeddings off an ingest streamNr'   
consume_fnstartendidr   c                      y)au  Register a function that will be called to receive embeddings for a given
        collections log stream. The given function may be called any number of times, with any number of
        records, and may be called concurrently.

        Only records between start (exclusive) and end (inclusive) SeqIDs will be
        returned. If start is None, the first record returned will be the next record
        generated, not including those generated before creating the subscription. If
        end is None, the consumer will consume indefinitely, otherwise it will
        automatically be unsubscribed when the end SeqID is reached.

        If the function throws an exception, the function may be called again with the
        same or different records.

        Takes an optional UUID as a unique subscription ID. If no ID is provided, a new
        ID will be generated and returned.Nr)   )r+   r'   rB   rC   rD   rE   s         r   	subscribezConsumer.subscribeQ   s    0 	r!   subscription_idc                      y)zUnregister a subscription. The consume function will no longer be invoked,
        and resources associated with the subscription will be released.Nr)   )r+   rH   s     r   unsubscribezConsumer.unsubscribek   s     	r!   c                      y)z9Return the minimum possible SeqID in this implementation.Nr)   r8   s    r   	min_seqidzConsumer.min_seqidq   r/   r!   c                      y)z9Return the maximum possible SeqID in this implementation.Nr)   r8   s    r   	max_seqidzConsumer.max_seqidv   r/   r!   )NNN)r:   r;   r<   r=   r   r   ConsumerCallbackFnr   r	   rG   rJ   rL   rN   r)   r!   r   rA   rA   N   s    ?
 "&#! ' 	
 e_ TN 
 2 4 D  
 5   5  r!   rA   )abcr   typingr   r   r   chromadb.typesr   r   r	   r
   r   chromadb.configr   uuidr   numpyr   bytesr    r$   r&   rO   rA   r)   r!   r   <module>rW      s     / /  &  D& DN Du DD% D> Df D#y #L x	23T9: +y +r!   