
    ti00                         d dl mZmZmZ d dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ d dlmZ erd dlmZ  G d ded                   ZdS )	    )TYPE_CHECKINGOptionalUnionN)URICollectionMetadata	EmbeddingIncludeMetadataDocumentImageWhereIDs	GetResultQueryResultID	OneOrManyWhereDocument)CollectionCommon)AsyncServerAPIc                      e Zd Z	 	 	 	 	 d dee         deeee         eej	                 f                  deee
                  deee                  deee                  deee                  ddfd	Zdefd
Zdddddddgfdeee                  dee         dee         dee         dee         dedefdZd!dedefdZdddddddg dfdeeee         eej	                 f                  deee                  deee                  deee                  dedee         dee         dedefdZ	 d"dee         dee         ddfdZ	 	 	 	 	 d dee         deeee         eej	                 f                  deee
                  deee                  deee                  deee                  ddfdZ	 	 	 	 	 d dee         deeee         eej	                 f                  deee
                  deee                  deee                  deee                  ddfdZ	 	 	 d#dee         dee         dee         ddfdZdS )$AsyncCollectionNids
embeddings	metadatas	documentsimagesurisreturnc                    K   |                      ||||||          \  }}}}}| j                            || j        ||||           d{V  dS )a]  Add embeddings to the data store.
        Args:
            ids: The ids of the embeddings you wish to add
            embeddings: The embeddings to add. If None, embeddings will be computed based on the documents or images using the embedding_function set for the Collection. Optional.
            metadatas: The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.
            images: The images to associate with the embeddings. Optional.
            uris: The uris of the images to associate with the embeddings. Optional.

        Returns:
            None

        Raises:
            ValueError: If you don't provide either embeddings or documents
            ValueError: If the length of ids, embeddings, metadatas, or documents don't match
            ValueError: If you don't provide an embedding function and don't provide embeddings
            ValueError: If you provide both embeddings and documents
            ValueError: If you provide an id that already exists

        N)#_validate_and_prepare_embedding_set_client_addidselfr   r   r   r   r   r   s          V/var/www/icac/venv/lib/python3.11/site-packages/chromadb/api/models/AsyncCollection.pyaddzAsyncCollection.add    sz      P 44Y	64
 
	

 lTWj)YPTUUUUUUUUUUU    c                 R   K   | j                             | j                   d{V S )zThe total number of embeddings added to the database

        Returns:
            int: The total number of embeddings added to the database

        )collection_idN)r!   _countr#   )r%   s    r&   countzAsyncCollection.countN   s5       \((tw(?????????r(   wherelimitoffsetwhere_documentincludec           
         K   |                      ||||          \  }}}	}
| j                            | j        ||d|||	|
           d{V }|                     ||
          S )a  Get embeddings and their associate data from the data store. If no ids or where filter is provided returns
        all embeddings up to limit starting at offset.

        Args:
            ids: The ids of the embeddings to get. Optional.
            where: A Where type dict used to filter results by. E.g. `{"$and": ["color" : "red", "price": {"$gte": 4.20}]}`. Optional.
            limit: The number of documents to return. Optional.
            offset: The offset to start returning results from. Useful for paging results with limit. Optional.
            where_document: A WhereDocument type dict used to filter by the documents. E.g. `{$contains: {"text": "hello"}}`. Optional.
            include: A list of what to include in the results. Can contain `"embeddings"`, `"metadatas"`, `"documents"`. Ids are always included. Defaults to `["metadatas", "documents"]`. Optional.

        Returns:
            GetResult: A GetResult object containing the results.

        N)r0   r1   )!_validate_and_prepare_get_requestr!   _getr#   _transform_get_response)r%   r   r-   r.   r/   r0   r1   	valid_idsvalid_wherevalid_where_documentvalid_includeget_resultss               r&   getzAsyncCollection.getW   s      : 223~wWW	
  !L--G/! . 	
 	
 	
 	
 	
 	
 	
 	
 ++KGGGr(   
   c                 R   K   | j                             | j        |           d{V S )zGet the first few results in the database up to limit

        Args:
            limit: The number of results to return.

        Returns:
            GetResult: A GetResult object containing the results.
        N)r!   _peekr#   )r%   r.   s     r&   peekzAsyncCollection.peek   s4       \''777777777r(   )r   r   	distancesquery_embeddingsquery_textsquery_images
query_uris	n_resultsc	           
         K   |                      ||||||||          \  }	}
}}| j                            | j        |	|
|||           d{V }|                     ||          S )a}  Get the n_results nearest neighbor embeddings for provided query_embeddings or query_texts.

        Args:
            query_embeddings: The embeddings to get the closes neighbors of. Optional.
            query_texts: The document texts to get the closes neighbors of. Optional.
            query_images: The images to get the closes neighbors of. Optional.
            n_results: The number of neighbors to return for each query_embedding or query_texts. Optional.
            where: A Where type dict used to filter results by. E.g. `{"$and": ["color" : "red", "price": {"$gte": 4.20}]}`. Optional.
            where_document: A WhereDocument type dict used to filter by the documents. E.g. `{$contains: {"text": "hello"}}`. Optional.
            include: A list of what to include in the results. Can contain `"embeddings"`, `"metadatas"`, `"documents"`, `"distances"`. Ids are always included. Defaults to `["metadatas", "documents", "distances"]`. Optional.

        Returns:
            QueryResult: A QueryResult object containing the results.

        Raises:
            ValueError: If you don't provide either query_embeddings, query_texts, or query_images
            ValueError: If you provide both query_embeddings and query_texts
            ValueError: If you provide both query_embeddings and query_images
            ValueError: If you provide both query_texts and query_images

        )r*   rA   rE   r-   r0   r1   N)#_validate_and_prepare_query_requestr!   _queryr#   _transform_query_response)r%   rA   rB   rC   rD   rE   r-   r0   r1   valid_query_embeddingsvalid_n_resultsr7   r8   query_resultss                 r&   queryzAsyncCollection.query   s      V 44	
 	
	
"  #l11'3%/ 2 
 
 
 
 
 
 
 
 --mWEEEr(   namemetadatac                    K   |                      |           | j                            | j        ||           d{V  |                     ||           dS )zModify the collection name or metadata

        Args:
            name: The updated name for the collection. Optional.
            metadata: The updated metadata for the collection. Optional.

        Returns:
            None
        )r#   new_namenew_metadataN)_validate_modify_requestr!   _modifyr#   "_update_model_after_modify_success)r%   rN   rO   s      r&   modifyzAsyncCollection.modify   sk       	%%h///
 l""dg8"TTTTTTTTT//h?????r(   c                    K   |                      ||||||          \  }}}}}| j                            | j        |||||           d{V  dS )a  Update the embeddings, metadatas or documents for provided ids.

        Args:
            ids: The ids of the embeddings to update
            embeddings: The embeddings to update. If None, embeddings will be computed based on the documents or images using the embedding_function set for the Collection. Optional.
            metadatas:  The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.
            images: The images to associate with the embeddings. Optional.
        Returns:
            None
        N)$_validate_and_prepare_update_requestr!   _updater#   r$   s          r&   updatezAsyncCollection.update   sy      > 55Y	64
 
	

 l""47CY	SWXXXXXXXXXXXr(   c                    K   |                      ||||||          \  }}}}}| j                            | j        |||||           d{V  dS )aO  Update the embeddings, metadatas or documents for provided ids, or create them if they don't exist.

        Args:
            ids: The ids of the embeddings to update
            embeddings: The embeddings to add. If None, embeddings will be computed based on the documents using the embedding_function set for the Collection. Optional.
            metadatas:  The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.

        Returns:
            None
        )r*   r   r   r   r   r   N)$_validate_and_prepare_upsert_requestr!   _upsertr#   r$   s          r&   upsertzAsyncCollection.upsert
  s      > 55Y	64
 
	

 l""'! # 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r(   c                    K   |                      |||          \  }}}| j                            | j        |||           d{V  dS )a4  Delete the embeddings based on ids and/or a where filter

        Args:
            ids: The ids of the embeddings to delete
            where: A Where type dict used to filter the delection by. E.g. `{"$and": ["color" : "red", "price": {"$gte": 4.20}]}`. Optional.
            where_document: A WhereDocument type dict used to filter the deletion by the document content. E.g. `{$contains: {"text": "hello"}}`. Optional.

        Returns:
            None

        Raises:
            ValueError: If you don't provide either ids, where, or where_document
        N)$_validate_and_prepare_delete_requestr!   _deleter#   )r%   r   r-   r0   s       r&   deletezAsyncCollection.delete6  sc      & (,'P'P(
 (
$e^ l""47CGGGGGGGGGGGr(   )NNNNN)r<   )NN)NNN) __name__
__module____qualname__r   r   r   r   r   npndarrayr
   r   r   r   r'   intr,   r   r   r	   r   r;   r?   r   rM   strr   rV   rZ   r^   r   rb    r(   r&   r   r      s        3737-1)-,V ,Vr],V )$"*%'
,V Ih/0,V Ih/0,V 5)*,V y~&,V 
,V ,V ,V ,V\@S @ @ @ @ (,!%# $26'5*H *Him$*H *H }	*H
 *H !/*H *H 
*H *H *H *HX	8 	8 	8Y 	8 	8 	8 	8$ 5937/3!%26BBB?F ?F")$"*%'
?F i12?F y/0?F Ys^,?F ?F ?F !/?F ?F 
?F ?F ?F ?FD TX@ @SM@4<=O4P@	@ @ @ @< 3737-1)-#Y #Yr]#Y )$"*%'
#Y Ih/0#Y Ih/0#Y 5)*#Y y~&#Y 
#Y #Y #Y #YZ 3737-1)-*
 *
r]*
 )$"*%'
*
 Ih/0*
 Ih/0*
 5)**
 y~&*
 
*
 *
 *
 *
\ "!%26	H Hc]H H !/	H
 
H H H H H Hr(   r   r   )typingr   r   r   numpyrf   chromadb.api.typesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   $chromadb.api.models.CollectionCommonr   chromadb.apir   r   rj   r(   r&   <module>rp      sc           
                                   " B A A A A A ,++++++nH nH nH nH nH&'78 nH nH nH nH nHr(   