o
    ɭRh;                     @   s   d dl mZmZm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mZ d dlmZ d dlmZ er@d dlmZ G dd ded Zd	S )
    )TYPE_CHECKINGOptionalUnion)URICollectionMetadata	EmbeddingPyEmbeddingIncludeMetadataDocumentImageWhereIDs	GetResultQueryResultID	OneOrManyWhereDocument)CollectionCommon)UpdateCollectionConfiguration)AsyncServerAPIc                   @   s  e Zd Z					d-dee deeee ee f  deee	  deee
  deee  deee  ddfd	d
Zdefd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dZd.dedefddZddddddddg df	deeee ee f  deee
  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dZ			d/dee d ee d!ee ddfd"d#Zd$edd fd%d&Z					d-dee deeee ee f  deee	  deee
  deee  deee  ddfd'd(Z					d-dee deeee ee f  deee	  deee
  deee  deee  ddfd)d*Z			d/dee dee dee ddfd+d,Z dS )0AsyncCollectionNids
embeddings	metadatas	documentsimagesurisreturnc              
      X   | j ||||||d}| jj| j|d |d |d |d |d | j| jdI dH  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

        r   r   r   r   r   r   r   r   r   r   r   collection_idr   r   r   r   r   tenantdatabaseN)!_validate_and_prepare_add_request_client_addidr#   r$   )selfr   r   r   r   r   r   add_request r+   e/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/chromadb/api/models/AsyncCollection.pyadd   s&   "	zAsyncCollection.addc                    s    | j j| j| j| jdI dH S )zThe total number of embeddings added to the database

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

        )r"   r#   r$   N)r&   _countr(   r#   r$   )r)   r+   r+   r,   countS   s   zAsyncCollection.countwherelimitoffsetwhere_documentincludec           	         s`   | j ||||d}| jj| j|d |d |d |d ||| j| jd	I dH }| j||d d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": "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.

        )r   r0   r3   r4   r   r0   r3   r4   )	r"   r   r0   r3   r4   r1   r2   r#   r$   Nresponser4   )!_validate_and_prepare_get_requestr&   _getr(   r#   r$   _transform_get_response)	r)   r   r0   r1   r2   r3   r4   get_requestget_resultsr+   r+   r,   get`   s*   zAsyncCollection.get
   c                    s(   |  | jj| j|| j| jdI dH 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.
        )r"   nr#   r$   N)_transform_peek_responser&   _peekr(   r#   r$   )r)   r1   r+   r+   r,   peek   s   	
zAsyncCollection.peek)r   r   	distancesquery_embeddingsquery_textsquery_images
query_uris	n_resultsc
                    sr   | j |||||||||	d	}
| jj| j|
d |
d |
d |
d |
d |
d | j| jd	I d	H }| j||
d d
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.
            ids: A subset of ids to search within. 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": "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

        )	rC   rD   rE   rF   r   rG   r0   r3   r4   r   r   rG   r0   r3   r4   )	r"   r   rC   rG   r0   r3   r4   r#   r$   Nr5   )#_validate_and_prepare_query_requestr&   _queryr(   r#   r$   _transform_query_response)r)   rC   rD   rE   rF   r   rG   r0   r3   r4   query_requestquery_resultsr+   r+   r,   query   s4   ,zAsyncCollection.querynamemetadataconfigurationc                    sB   |  | | jj| j|||| j| jdI dH  | ||| 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_metadatanew_configurationr#   r$   N)_validate_modify_requestr&   _modifyr(   r#   r$   "_update_model_after_modify_success)r)   rN   rO   rP   r+   r+   r,   modify   s   
	zAsyncCollection.modifyrQ   c                    s8   | j j| j|| j| jdI dH }t| j || j| jdS )a  Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
        This is an experimental API that only works for Hosted Chroma for now.

        Args:
            new_name: The name of the new collection.

        Returns:
            Collection: A new collection with the specified name and containing identical data to the current collection.
        )r"   rQ   r#   r$   N)clientmodelembedding_functiondata_loader)r&   _forkr(   r#   r$   r   _embedding_function_data_loader)r)   rQ   rY   r+   r+   r,   fork	  s   zAsyncCollection.forkc              
      r   )	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
        r    r   r   r   r   r   r!   N)$_validate_and_prepare_update_requestr&   _updater(   r#   r$   )r)   r   r   r   r   r   r   update_requestr+   r+   r,   update#  &   	zAsyncCollection.updatec              
      r   )	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   r!   N)$_validate_and_prepare_upsert_requestr&   _upsertr(   r#   r$   )r)   r   r   r   r   r   r   upsert_requestr+   r+   r,   upsertP  rd   zAsyncCollection.upsertc                    sD   |  |||}| jj| j|d |d |d | j| jdI dH  dS )a0  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": "hello"}`. Optional.

        Returns:
            None

        Raises:
            ValueError: If you don't provide either ids, where, or where_document
        r   r0   r3   )r"   r   r0   r3   r#   r$   N)$_validate_and_prepare_delete_requestr&   _deleter(   r#   r$   )r)   r   r0   r3   delete_requestr+   r+   r,   delete}  s   zAsyncCollection.delete)NNNNN)r=   )NNN)!__name__
__module____qualname__r   r   r   r   r   r   r
   r   r   r   r-   intr/   r   r   r	   r   r<   rA   r   rM   strr   r   rW   r_   rc   rh   r   rl   r+   r+   r+   r,   r      sN   	
	




6

/

	



J
 
"
	




5
	




/r   r   N)typingr   r   r   chromadb.api.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   $chromadb.api.models.CollectionCommonr   %chromadb.api.collection_configurationr   chromadb.apir   r   r+   r+   r+   r,   <module>   s    D