
    ug6                         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mZ d dlmZ erd dlmZ  G d ded         Zy)	    )TYPE_CHECKINGOptionalUnion)URICollectionMetadata	EmbeddingIncludeEnumPyEmbeddingIncludeMetadataDocumentImageWhereIDs	GetResultQueryResultID	OneOrManyWhereDocument)CollectionCommon)AsyncServerAPIc                   T   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	Zdefd
Zdddddej"                  ej$                  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ej"                  ej$                  ej2                  gfdeeee   ee   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   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   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"y)#AsyncCollectionNids
embeddings	metadatas	documentsimagesurisreturnc           
         K   | j                  ||||||      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                         d{    y7 w)	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_requests           X/var/www/openai/venv/lib/python3.12/site-packages/chromadb/api/models/AsyncCollection.pyaddzAsyncCollection.add   s     D <<! = 
 ll''E""<0!+.!+.V$;;]]   	
 		
 		
   A+A5-A3.A5c                    K   | j                   j                  | j                  | j                  | j                         d{   S 7 w)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+   s    r-   countzAsyncCollection.countS   sC      \\(('';;]] ) 
 
 	
 
s   A A	AA	wherelimitoffsetwhere_documentincludec                   K   | j                  ||||      }| j                  j                  | j                  |d   |d   |d   |d   d||| j                  | j
                  
       d{   }| j                  ||d         S 7 w)	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.

        )r   r3   r6   r7   r   r3   r6   r7   N)
r$   r   r3   r6   r7   sortr4   r5   r%   r&   responser7   )!_validate_and_prepare_get_requestr(   _getr*   r%   r&   _transform_get_response)	r+   r   r3   r4   r5   r6   r7   get_requestget_resultss	            r-   getzAsyncCollection.get`   s     0 <<)	 = 
 !LL--''E"g&&'78	*;;]] . 
 
 ++ +i*@ , 
 	

s   A(B*B+B
   c                    K   | j                  | j                  j                  | j                  || j                  | j
                         d{         S 7 w)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+   r4   s     r-   peekzAsyncCollection.peek   sT      ,,,,$$"gg{{	 %  
 	
s   AAA	Aquery_embeddingsquery_textsquery_images
query_uris	n_resultsc	           
        K   | j                  ||||||||      }	| j                  j                  | j                  |	d   |	d   |	d   |	d   |	d   | j                  | j
                         d{   }
| j                  |
|	d   	      S 7 w)
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

        )rH   rI   rJ   rK   rL   r3   r6   r7   r   rL   r3   r6   r7   )r$   rH   rL   r3   r6   r7   r%   r&   Nr:   )#_validate_and_prepare_query_requestr(   _queryr*   r%   r&   _transform_query_response)r+   rH   rI   rJ   rK   rL   r3   r6   r7   query_requestquery_resultss              r-   queryzAsyncCollection.query   s     T @@-#%!) A 	
 #ll11''*<8#K0(()9:!),;;]] 2 	
 	
 --"M),D . 
 	
	
s   A-B/B
0Bnamemetadatac                    K   | j                  |       | j                  j                  | j                  ||       d{    | j	                  ||       y7 w)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+   rT   rU   s      r-   modifyzAsyncCollection.modify   sQ      	%%h/
 ll""dgg8"TTT//h? 	Us   =AA Ac           
         K   | j                  ||||||      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                         d{    y7 w)	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_requests           r-   updatezAsyncCollection.update        2 BB! C 
 ll""''u%%l3$[1$[1';;]] # 	
 		
 		
r/   c           
         K   | j                  ||||||      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                         d{    y7 w)	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_requests           r-   upsertzAsyncCollection.upsert)  rb   r/   c                    K   | j                  |||      }| j                  j                  | j                  |d   |d   |d   | j                  | j
                         d{    y7 w)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
        r   r3   r6   )r$   r   r3   r6   r%   r&   N)$_validate_and_prepare_delete_requestr(   _deleter*   r%   r&   )r+   r   r3   r6   delete_requests        r-   deletezAsyncCollection.deleteV  sp     & BB
 ll""''u% ))*:;;;]] # 
 	
 	
s   AA)!A'"A))NNNNN)rB   )NN)NNN)#__name__
__module____qualname__r   r   r   r   r   r
   r   r   r   r   r.   intr2   r	   r   r   r   r   r   r   rA   rG   	distancesr   rS   strr   r\   ra   rg   r   rl        r-   r   r      s    3737-1)-4
r]4
 )$+&(
4
 Ih/04
 Ih/04
 5)*4
 y~&4
 
4
l
S 
 (,!%# $26'11;3H3HI.
im$.
 .
 }	.

 .
 !/.
 .
 
.
`
 
Y 
2 5937/3!%26!!!!!!
B
")$+&(
B
 i12B
 y/0B
 Ys^,B
 B
 B
 !/B
 B
& 
'B
J TX@SM@4<=O4P@	@< 3737-1)-+
r]+
 )$+&(
+
 Ih/0+
 Ih/0+
 5)*+
 y~&+
 
+
j 3737-1)-+
r]+
 )$+&(
+
 Ih/0+
 Ih/0+
 5)*+
 y~&+
 
+
^ "!%26	
c]
 
 !/	

 

rt   r   r   N)typingr   r   r   chromadb.api.typesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   $chromadb.api.models.CollectionCommonr   chromadb.apir   r   rs   rt   r-   <module>ry      sE    1 1    & B+X
&'78 X
rt   