
    ug(Z                     L   d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d dl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$m%Z% d dl&m'Z'm(Z(m)Z* d dl+m,c m-Z.  G d de      Z/ G d de/e      Z0 G d de      Z1 G d de/e1e$      Z2y)    )ABCabstractmethod)SequenceOptional)UUID)override)CollectionConfigurationCollectionConfigurationInternal)UserIdentity)AsyncCollection)DEFAULT_DATABASEDEFAULT_TENANT)CollectionMetadata	Documents
EmbeddableEmbeddingFunction
DataLoader
EmbeddingsIDsIncludeLoadable	MetadatasURIsWhereQueryResult	GetResultWhereDocument)	ComponentSettings)DatabaseTenant
CollectionNc                      e Zd Zedefd       Zedefd       Ze	 	 d,dedee	   dee
   ddfd       Zed	e	ddfd
       Ze	 	 	 d-dedededee   dee   dee   defd       Ze	 	 	 	 d.dededee   dee   dee   dee   defd       Ze	 	 	 d-dedededee   dee   dee   defd       Zededefd       Zed/dededefd       Zeddddddddg df	dedee   dee   dee	   dee   dee   dee   dee   dee   d edefd!       Ze	 	 d,dedee   dee   dee   ddf
d"       Zedddg d#fded$ed%edee   dee   d edefd&       Zedefd'       Z ede	fd(       Z!ede"fd)       Z#edefd*       Z$ede%fd+       Z&y)0AsyncBaseAPIreturnc                    K   yw)zGet the current time in nanoseconds since epoch.
        Used to check if the server is alive.

        Returns:
            int: The current time in nanoseconds since epoch

        N selfs    K/var/www/openai/venv/lib/python3.12/site-packages/chromadb/api/async_api.py	heartbeatzAsyncBaseAPI.heartbeat$         	   c                    K   yw)zCount the number of collections.

        Returns:
            int: The number of collections.

        Examples:
            ```python
            await client.count_collections()
            # 1
            ```
        Nr'   r(   s    r*   count_collectionszAsyncBaseAPI.count_collections3         	r-   Nidnew_namenew_metadatac                    K   yw)a  [Internal] Modify a collection by UUID. Can update the name and/or metadata.

        Args:
            id: The internal UUID of the collection to modify.
            new_name: The new name of the collection.
                                If None, the existing name will remain. Defaults to None.
            new_metadata: The new metadata to associate with the collection.
                                      Defaults to None.
        Nr'   )r)   r1   r2   r3   s       r*   _modifyzAsyncBaseAPI._modifyB   s       	r-   namec                    K   yw)a7  Delete a collection with the given name.
        Args:
            name: The name of the collection to delete.

        Raises:
            ValueError: If the collection does not exist.

        Examples:
            ```python
            await client.delete_collection("my_collection")
            ```
        Nr'   r)   r6   s     r*   delete_collectionzAsyncBaseAPI.delete_collectionT        " 	r-   idscollection_id
embeddings	metadatas	documentsurisc                    K   yw)a  [Internal] Add embeddings to a collection specified by UUID.
        If (some) ids already exist, only the new embeddings will be added.

        Args:
            ids: The ids to associate with the embeddings.
            collection_id: The UUID of the collection to add the embeddings to.
            embedding: The sequence of embeddings to add.
            metadata: The metadata to associate with the embeddings. Defaults to None.
            documents: The documents to associate with the embeddings. Defaults to None.
            uris: URIs of data sources for each embedding. Defaults to None.

        Returns:
            True if the embeddings were added successfully.
        Nr'   )r)   r;   r<   r=   r>   r?   r@   s          r*   _addzAsyncBaseAPI._addk        0 	r-   c                    K   yw)aw  [Internal] Update entries in a collection specified by UUID.

        Args:
            collection_id: The UUID of the collection to update the embeddings in.
            ids: The IDs of the entries to update.
            embeddings: The sequence of embeddings to update. Defaults to None.
            metadatas: The metadata to associate with the embeddings. Defaults to None.
            documents: The documents to associate with the embeddings. Defaults to None.
            uris: URIs of data sources for each embedding. Defaults to None.
        Returns:
            True if the embeddings were updated successfully.
        Nr'   r)   r<   r;   r=   r>   r?   r@   s          r*   _updatezAsyncBaseAPI._update        , 	r-   c                    K   yw)a  [Internal] Add or update entries in the a collection specified by UUID.
        If an entry with the same id already exists, it will be updated,
        otherwise it will be added.

        Args:
            collection_id: The collection to add the embeddings to
            ids: The ids to associate with the embeddings. Defaults to None.
            embeddings: The sequence of embeddings to add
            metadatas: The metadata to associate with the embeddings. Defaults to None.
            documents: The documents to associate with the embeddings. Defaults to None.
            uris: URIs of data sources for each embedding. Defaults to None.
        Nr'   rE   s          r*   _upsertzAsyncBaseAPI._upsert   rG   r-   c                    K   yw)a  [Internal] Returns the number of entries in a collection specified by UUID.

        Args:
            collection_id: The UUID of the collection to count the embeddings in.

        Returns:
            int: The number of embeddings in the collection

        Nr'   )r)   r<   s     r*   _countzAsyncBaseAPI._count         	r-   
   nc                    K   yw)a4  [Internal] Returns the first n entries in a collection specified by UUID.

        Args:
            collection_id: The UUID of the collection to peek into.
            n: The number of entries to peek. Defaults to 10.

        Returns:
            GetResult: The first n entries in the collection.

        Nr'   )r)   r<   rN   s      r*   _peekzAsyncBaseAPI._peek   r0   r-   )r=   r>   r?   wheresortlimitoffsetpage	page_sizewhere_documentincludec                    K   yw)a  [Internal] Returns entries from a collection specified by UUID.

        Args:
            ids: The IDs of the entries to get. Defaults to None.
            where: Conditional filtering on metadata. Defaults to {}.
            sort: The column to sort the entries by. Defaults to None.
            limit: The maximum number of entries to return. Defaults to None.
            offset: The number of entries to skip before returning. Defaults to None.
            page: The page number to return. Defaults to None.
            page_size: The number of entries to return per page. Defaults to None.
            where_document: Conditional filtering on documents. Defaults to {}.
            include: The fields to include in the response.
                          Defaults to ["embeddings", "metadatas", "documents"].
        Returns:
            GetResult: The entries in the collection that match the query.

        Nr'   )r)   r<   r;   rQ   rR   rS   rT   rU   rV   rW   rX   s              r*   _getzAsyncBaseAPI._get   s     > 	r-   c                    K   yw)a  [Internal] Deletes entries from a collection specified by UUID.

        Args:
            collection_id: The UUID of the collection to delete the entries from.
            ids: The IDs of the entries to delete. Defaults to None.
            where: Conditional filtering on metadata. Defaults to {}.
            where_document: Conditional filtering on documents. Defaults to {}.

        Returns:
            IDs: The list of IDs of the entries that were deleted.
        Nr'   )r)   r<   r;   rQ   rW   s        r*   _deletezAsyncBaseAPI._delete   s     & 	r-   )r=   r>   r?   	distancesquery_embeddings	n_resultsc                    K   yw)a  [Internal] Performs a nearest neighbors query on a collection specified by UUID.

        Args:
            collection_id: The UUID of the collection to query.
            query_embeddings: The embeddings to use as the query.
            n_results: The number of results to return. Defaults to 10.
            where: Conditional filtering on metadata. Defaults to {}.
            where_document: Conditional filtering on documents. Defaults to {}.
            include: The fields to include in the response.
                          Defaults to ["embeddings", "metadatas", "documents", "distances"].

        Returns:
            QueryResult: The results of the query.
        Nr'   )r)   r<   r^   r_   rQ   rW   rX   s          r*   _queryzAsyncBaseAPI._query  rC   r-   c                    K   yw)zResets the database. This will delete all collections and entries.

        Returns:
            bool: True if the database was reset successfully.
        Nr'   r(   s    r*   resetzAsyncBaseAPI.reset!        	r-   c                    K   yw)z]Get the version of Chroma.

        Returns:
            str: The version of Chroma

        Nr'   r(   s    r*   get_versionzAsyncBaseAPI.get_version*        	r-   c                      y)zwGet the settings used to initialize.

        Returns:
            Settings: The settings used to initialize.

        Nr'   r(   s    r*   get_settingszAsyncBaseAPI.get_settings4  s     	    c                    K   yw)zUReturn the maximum number of records that can be created or mutated in a single call.Nr'   r(   s    r*   get_max_batch_sizezAsyncBaseAPI.get_max_batch_size>  s      	r-   c                    K   yw)zsResolve the tenant and databases for the client. Returns the default
        values if can't be resolved.

        Nr'   r(   s    r*   get_user_identityzAsyncBaseAPI.get_user_identityC  s      	r-   NN)NNN)NNNN)rM   )'__name__
__module____qualname__r   intr+   r/   r   r   strr   r5   r9   r   r   r   r   r   boolrB   rF   rI   rK   r   rP   r   r   r   rZ   r\   r   ra   rc   rf   r   ri   rl   r   rn   r'   rj   r*   r$   r$   #   s\          #'59	 3- 12	
 
 "  
 ,  *.)-#  	
 I& I& tn 
 2 
 ,0)-)-#  Z(	
 I& I& tn 
 .  *.)-#  	
 I& I& tn 
 . 
$ 
3 
 
  # y    "!%"# $"#'26C c] 	
 sm }  sm C= !/  
 @ 
 "&26 c] 	
 !/ 
 ( 
 !%26P % 	
  !/  
 2 T   3   h   #     rj   r$   c                       e Zd ZU eed<   eed<   e	 	 ddee   dee   dee   fd       Z	edd e
j                         ddfd	ed
ee   dee   deee      deee      dedefd       Ze e
j                         dfd	edeee      deee      defd       Zedd e
j                         dfd	ed
ee   dee   deee      deee      defd       Zeefdededdfd       Zededdfd       Zeedd              Zy)AsyncClientAPItenantdatabaseNrS   rT   r%   c                    K   yw)a  List all collections.
        Args:
            limit: The maximum number of entries to return. Defaults to None.
            offset: The number of entries to skip before returning. Defaults to None.

        Returns:
            Sequence[str]: A list of collection names.

        Examples:
            ```python
            await client.list_collections()
            # ["my_collection"]
            ```
        Nr'   )r)   rS   rT   s      r*   list_collectionszAsyncClientAPI.list_collectionsP  s     ( 	r-   Fr6   configurationmetadataembedding_functiondata_loaderget_or_createc                    K   yw)aY  Create a new collection with the given name and metadata.
        Args:
            name: The name of the collection to create.
            metadata: Optional metadata to associate with the collection.
            embedding_function: Optional function to use to embed documents.
                                Uses the default embedding function if not provided.
            get_or_create: If True, return the existing collection if it exists.
            data_loader: Optional function to use to load records (documents, images, etc.)

        Returns:
            Collection: The newly created collection.

        Raises:
            ValueError: If the collection already exists and get_or_create is False.
            ValueError: If the collection name is invalid.

        Examples:
            ```python
            await client.create_collection("my_collection")
            # collection(name="my_collection", metadata={})

            await client.create_collection("my_collection", metadata={"foo": "bar"})
            # collection(name="my_collection", metadata={"foo": "bar"})
            ```
        Nr'   )r)   r6   r|   r}   r~   r   r   s          r*   create_collectionz AsyncClientAPI.create_collectionf  s     J 	r-   c                    K   yw)a  Get a collection with the given name.
        Args:
            name: The name of the collection to get
            embedding_function: Optional function to use to embed documents.
                                Uses the default embedding function if not provided.
            data_loader: Optional function to use to load records (documents, images, etc.)

        Returns:
            Collection: The collection

        Raises:
            ValueError: If the collection does not exist

        Examples:
            ```python
            await client.get_collection("my_collection")
            # collection(name="my_collection", metadata={})
            ```
        Nr'   )r)   r6   r~   r   s       r*   get_collectionzAsyncClientAPI.get_collection  s     8 	r-   c                    K   yw)a1  Get or create a collection with the given name and metadata.
        Args:
            name: The name of the collection to get or create
            metadata: Optional metadata to associate with the collection. If
            the collection already exists, the metadata provided is ignored.
            If the collection does not exist, the new collection will be created
            with the provided metadata.
            embedding_function: Optional function to use to embed documents
            data_loader: Optional function to use to load records (documents, images, etc.)

        Returns:
            The collection

        Examples:
            ```python
            await client.get_or_create_collection("my_collection")
            # collection(name="my_collection", metadata={})
            ```
        Nr'   )r)   r6   r|   r}   r~   r   s         r*   get_or_create_collectionz'AsyncClientAPI.get_or_create_collection  s     < 	r-   c                    K   yw)zSet the tenant and database for the client. Raises an error if the tenant or
        database does not exist.

        Args:
            tenant: The tenant to set.
            database: The database to set.

        Nr'   r)   rx   ry   s      r*   
set_tenantzAsyncClientAPI.set_tenant        	r-   c                    K   yw)zSet the database for the client. Raises an error if the database does not exist.

        Args:
            database: The database to set.

        Nr'   )r)   ry   s     r*   set_databasezAsyncClientAPI.set_database  rg   r-   c                       y)zClear the system cache so that new systems can be created for an existing path.
        This should only be used for testing purposes.Nr'   r'   rj   r*   clear_system_cachez!AsyncClientAPI.clear_system_cache  s    
 	rj   ro   )r%   N)rp   rq   rr   rt   __annotations__r   r   rs   r   r{   efDefaultEmbeddingFunctionr	   r   r   r   r   r   ru   r   r   r   r   r   r   r   staticmethodr   r'   rj   r*   rw   rw   L  sE   KM  $ $}  
#	 *  <@15 (B'')6:#$$   78$ -.	$
 %j)
$ j23$ $ 
$ $L  (B'')6: %j)
 j23 
 :  <@15 (B'')6:   78 -.	
 %j)
 j23 
 > <L 	s 	c 	QU 	 	 3 4     rj   rw   c                       e Zd Zeefdededdfd       Zeefdededefd       Zeefdededdfd       Z	eddefde
e   d	e
e   dedee   fd
       Zededdfd       Zededefd       Zy)AsyncAdminAPIr6   rx   r%   Nc                    K   yw)zCreate a new database. Raises an error if the database already exists.

        Args:
            database: The name of the database to create.

        Nr'   r)   r6   rx   s      r*   create_databasezAsyncAdminAPI.create_database  rg   r-   c                    K   yw)zGet a database. Raises an error if the database does not exist.

        Args:
            database: The name of the database to get.
            tenant: The tenant of the database to get.

        Nr'   r   s      r*   get_databasezAsyncAdminAPI.get_database  r,   r-   c                    K   yw)zDelete a database. Raises an error if the database does not exist.

        Args:
            database: The name of the database to delete.
            tenant: The tenant of the database to delete.

        Nr'   r   s      r*   delete_databasezAsyncAdminAPI.delete_database  r,   r-   rS   rT   c                    K   yw)zList all databases for a tenant. Raises an error if the tenant does not exist.

        Args:
            tenant: The tenant to list databases for.

        Nr'   )r)   rS   rT   rx   s       r*   list_databaseszAsyncAdminAPI.list_databases
  r0   r-   c                    K   yw)zCreate a new tenant. Raises an error if the tenant already exists.

        Args:
            tenant: The name of the tenant to create.

        Nr'   r8   s     r*   create_tenantzAsyncAdminAPI.create_tenant  rg   r-   c                    K   yw)zGet a tenant. Raises an error if the tenant does not exist.

        Args:
            tenant: The name of the tenant to get.

        Nr'   r8   s     r*   
get_tenantzAsyncAdminAPI.get_tenant#  rg   r-   )rp   rq   rr   r   r   rt   r   r    r   r   r   rs   r   r   r   r!   r   r'   rj   r*   r   r     s   =K # s PT   :H s C X   =K # s PT     $ $$	}  	
 
(	      S V  rj   r   c                      e Zd ZdZeddeefdee   dee   de	de	de
e   f
d       Zeeeefde	de	defd	              Zeddd
eefde	dee   dee   dede	de	defd       Zeeefde	de	de	defd       Zeddeefde	dee   dee   de	de	defd       Zeeeefde	de	de	ddfd              Zeeddeefdedee	   dee   de	de	ddfd              Zeeeefdede	de	defd              Zeedeefdedede	de	def
d              Zeeddddddddddgeefdedee   dee   d ee	   dee   dee   d!ee   d"ee   d#ee   d$ede	de	defd%              Zeedddeefdeded&e dee!   dee"   d'ee#   de	de	defd(              Z$eeddddeefdeded&ee    dee!   dee"   d'ee#   de	de	defd)              Z%eedddeefdeded&e dee!   dee"   d'ee#   de	de	defd*              Z&eedddg d+eefded,e d-edee   d#ee   d$ede	de	de'fd.              Z(eedddeefdedee   dee   d#ee   de	de	ddfd/              Z)y)0AsyncServerAPIzAn API instance that extends the relevant Base API methods by passing
    in a tenant and database. This is the root component of the Chroma SystemNrS   rT   rx   ry   r%   c                    K   y wNr'   )r)   rS   rT   rx   ry   s        r*   r{   zAsyncServerAPI.list_collections2  rg   r-   c                    K   y wr   r'   r   s      r*   r/   z AsyncServerAPI.count_collections<  s     
 	r-   Fr6   r|   r}   r   c                    K   y wr   r'   )r)   r6   r|   r}   r   rx   ry   s          r*   r   z AsyncServerAPI.create_collectionC  r   r-   c                    K   y wr   r'   r)   r6   rx   ry   s       r*   r   zAsyncServerAPI.get_collectionO  rd   r-   c                    K   y wr   r'   )r)   r6   r|   r}   rx   ry   s         r*   r   z'AsyncServerAPI.get_or_create_collectionX  r,   r-   c                    K   y wr   r'   r   s       r*   r9   z AsyncServerAPI.delete_collectionc  rg   r-   r1   r2   r3   c                    K   y wr   r'   )r)   r1   r2   r3   rx   ry   s         r*   r5   zAsyncServerAPI._modifym  r   r-   r<   c                    K   y wr   r'   )r)   r<   rx   ry   s       r*   rK   zAsyncServerAPI._county  rg   r-   rM   rN   c                    K   y wr   r'   )r)   r<   rN   rx   ry   s        r*   rP   zAsyncServerAPI._peek  r,   r-   r>   r?   r;   rQ   rR   rU   rV   rW   rX   c                    K   y wr   r'   )r)   r<   r;   rQ   rR   rS   rT   rU   rV   rW   rX   rx   ry   s                r*   rZ   zAsyncServerAPI._get  r:   r-   r=   r@   c	                    K   y wr   r'   )	r)   r;   r<   r=   r>   r?   r@   rx   ry   s	            r*   rB   zAsyncServerAPI._add  r0   r-   c	                    K   y wr   r'   	r)   r<   r;   r=   r>   r?   r@   rx   ry   s	            r*   rF   zAsyncServerAPI._update  r0   r-   c	                    K   y wr   r'   r   s	            r*   rI   zAsyncServerAPI._upsert  r0   r-   )r>   r?   r]   r^   r_   c	                    K   y wr   r'   )	r)   r<   r^   r_   rQ   rW   rX   rx   ry   s	            r*   ra   zAsyncServerAPI._query  r0   r-   c                    K   y wr   r'   )r)   r<   r;   rQ   rW   rx   ry   s          r*   r\   zAsyncServerAPI._delete  rL   r-   )*rp   rq   rr   __doc__r   r   r   r   rs   rt   r   CollectionModelr{   r   r/   r
   r   ru   r   r   r   r9   r   r5   rK   r   rP   r   r   r   r   rZ   r   r   r   r   rB   rF   rI   r   ra   r\   r'   rj   r*   r   r   .  s   Q   $ $$(}  	
  
/	"  *<L69	  
  DH15#$(		   ?@	 -.		
 	 	 	 
	 	  %(	  	
 
   DH15$(   ?@ -.	
   
   %(	  	
 
    #'59$( 3- 12	
   
    %(	  	
 
    $(  	
  
    "!%"# $"#'26'5$( c] 	
 sm }  sm C= !/    
  "  *.)-#$(  	
 I& I& tn   
   
 ,0)-)-#$(  Z(	
 I& I& tn   
    *.)-#$(  	
 I& I& tn   
   
 !%26B$( % 	
  !/    
    "!%26$(		 c]	 		
 !/	 	 	 
	  	rj   r   )3abcr   r   typingr   r   uuidr   	overridesr   chromadb.api.configurationr	   r
   chromadb.authr   #chromadb.api.models.AsyncCollectionr   chromadb.configr   r   chromadb.api.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   chromadb.typesr    r!   r"   r   "chromadb.utils.embedding_functionsutilsembedding_functionsr   r$   rw   r   r   r'   rj   r*   <module>r      s    # %   ' ? <    " 0 J J / /f3 fR	Z\3 ZzBC BJz\=) zrj   