
    ti,                         d dl mZmZ d dlZd dlmZ d dlmZ d dl	m
Z d dlmZ d dlZd dlmZmZmZ d dlmZmZmZ d d	l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% g dZ& ej'        e(          Z) e            a*dZ+de,fdZ- e-            Z.dZ/	 d dl0m1Z1 e1Z/n# e2$ r dZ/Y nw xY we/sld dl3Z3e3j4        dk     r]e.rPd dl5Z5d dl6Z6 e5j7        e6j8        ddddg            e9d           e6j:        ;                    d          e6j:        d<   n e<d          d4dZ=defdZ>deefdee         de?de?defdZ@ddeefd e?dee         de?de?def
d!ZAd"d#dddeefd$e?d%eBd&e,d'eee?e?f                  dee         de?de?defd(ZCd"d#dddeefd$e?d%eBd&e,d'eee?e?f                  dee         de?de?defd)ZD	 	 d5d*d#d+d,de?de?d-ee?         dee         d.e?d/eBd0e,defd1ZEtT          eefdede?de?defd2Z e            fdedefd3ZdS )6    )DictOptionalN)Client)AdminClient)AsyncClient)TokenTransportHeader)DEFAULT_DATABASEDEFAULT_TENANTSettings)AdminAPIAsyncClientAPI	ClientAPI)
Collection)CollectionMetadata	DocumentsEmbeddingFunction
EmbeddingsIDsIncludeMetadataWhereQueryResult	GetResultWhereDocumentUpdateCollectionMetadata)r   r   r   r   r   r   r   r   r   r   r   r   r   r   z0.5.3returnc                  2    	 dd l } dS # t          $ r Y dS w xY w)Nr   TF)google.colabImportError)googles    D/var/www/icac/venv/lib/python3.11/site-packages/chromadb/__init__.pyis_in_colabr"   4   s:    t   uus    
F)is_thin_client)   #   r   z-mpipinstallzpysqlite3-binary	pysqlite3sqlite3z[91mYour system has an unsupported version of sqlite3. Chroma                     requires sqlite3 >= 3.35.0.[0m
[94mPlease visit                     https://docs.trychroma.com/troubleshooting#sqlite to learn how                     to upgrade.[0mc                  2    t          j        j        di | adS )zGOverride Chroma's default settings, environment variables or .env filesN )chromadbconfigr   
__settings)kwargss    r!   	configurer0   _   s      )33F33JJJ    c                      t           S )N)r.   r+   r1   r!   get_settingsr3   e   s    r1   settingstenantdatabasec                     | t                      } d| _        t          |          }t          |          }t          | ||          S )aA  
    Creates an in-memory instance of Chroma. This is useful for testing and
    development, but not recommended for production use.

    Args:
        tenant: The tenant to use for this client. Defaults to the default tenant.
        database: The database to use for this client. Defaults to the default database.
    NFr4   r5   r6   )r   is_persistentstrClientCreatorr8   s      r!   EphemeralClientr<   i   sH     ::"H [[F8}}H(6HMMMMr1   z./chromapathc                     |t                      }| |_        d|_        t          |          }t          |          }t	          |||          S )a  
    Creates a persistent instance of Chroma that saves to disk. This is useful for
    testing and development, but not recommended for production use.

    Args:
        path: The directory to save Chroma's data to. Defaults to "./chroma".
        tenant: The tenant to use for this client. Defaults to the default tenant.
        database: The database to use for this client. Defaults to the default database.
    NTr5   r6   r4   )r   persist_directoryr9   r:   r;   )r=   r4   r5   r6   s       r!   PersistentClientrA      sP     ::!%H!H [[F8}}HHMMMMr1   	localhosti@  hostportsslheadersc                    |t                      }t          |           } t          |          }t          |          }t          |          }t          |          }d|_        |j        r&|j        | k    rt          d|j         d|  d          | |_        |j        r&|j        |k    rt          d|j         d| d          ||_        ||_        ||_	        t          |||          S )a  
    Creates a client that connects to a remote Chroma server. This supports
    many clients connecting to the same server, and is the recommended way to
    use Chroma in production.

    Args:
        host: The hostname of the Chroma server. Defaults to "localhost".
        port: The port of the Chroma server. Defaults to "8000".
        ssl: Whether to use SSL to connect to the Chroma server. Defaults to False.
        headers: A dictionary of headers to send to the Chroma server. Defaults to {}.
        settings: A dictionary of settings to communicate with the chroma server.
        tenant: The tenant to use for this client. Defaults to the default tenant.
        database: The database to use for this client. Defaults to the default database.
    Nchromadb.api.fastapi.FastAPI(Chroma server host provided in settings[3] is different to the one provided in HttpClient: []-Chroma server http port provided in settings[r?   )r   r:   intboolchroma_api_implchroma_server_host
ValueErrorchroma_server_http_portchroma_server_ssl_enabledchroma_server_headersr;   rC   rD   rE   rF   r4   r5   r6   s          r!   
HttpClientrV      sB   0 :: t99Dt99D
s))C[[F8}}H=H" 
x'Bd'J'J Ox7R  O  O  HL  O  O  O
 
 	
 #'H' 
H,LPT,T,T YH<\  Y  Y  RV  Y  Y  Y
 
 	
 (,H$),H&%,H"HMMMMr1   c                   K   |t                      }t          |           } t          |          }t          |          }t          |          }t          |          }d|_        |j        r&|j        | k    rt          d|j         d|  d          | |_        |j        r&|j        |k    rt          d|j         d| d          ||_        ||_        ||_	        t          j        |||           d{V S )a  
    Creates an async client that connects to a remote Chroma server. This supports
    many clients connecting to the same server, and is the recommended way to
    use Chroma in production.

    Args:
        host: The hostname of the Chroma server. Defaults to "localhost".
        port: The port of the Chroma server. Defaults to "8000".
        ssl: Whether to use SSL to connect to the Chroma server. Defaults to False.
        headers: A dictionary of headers to send to the Chroma server. Defaults to {}.
        settings: A dictionary of settings to communicate with the chroma server.
        tenant: The tenant to use for this client. Defaults to the default tenant.
        database: The database to use for this client. Defaults to the default database.
    Nz'chromadb.api.async_fastapi.AsyncFastAPIrI   rJ   rK   rL   r?   )r   r:   rM   rN   rO   rP   rQ   rR   rS   rT   AsyncClientCreatorcreaterU   s          r!   AsyncHttpClientrZ      sp     0 :: t99Dt99D
s))C[[F8}}HHH" 
x'Bd'J'J Ox7R  O  O  HL  O  O  O
 
 	
 #'H' 
H,LPT,T,T YH<\  Y  Y  RV  Y  Y  Y
 
 	
 (,H$),H&%,H"#*8         r1   zapi.trychroma.comT)
cloud_host
cloud_port
enable_sslapi_keyr[   r\   r]   c                   |ddl }|j                            d          }|t          d           t	          d          }|t                      }t          |           } t          |          }t          |          }t          |          }t          |          }t          |          }d|_	        ||_
        ||_        ||_        d|_        ||_        t          j        |_        t%          | ||          S )	z
    Creates a client to connect to a tennant and database on the Chroma cloud.

    Args:
        tenant: The tenant to use for this client.
        database: The database to use for this client.
        api_key: The api key to use for this client.
    Nr   CHROMA_API_KEYzD[93mDon't have an API key?[0m Get one at https://app.trychroma.comz"Please enter your Chroma API key: rH   z1chromadb.auth.token_authn.TokenAuthClientProviderr?   )osenvirongetprintinputr   r:   rM   rN   rO   rP   rR   rS   chroma_client_auth_providerchroma_client_auth_credentialsr   X_CHROMA_TOKEN"chroma_auth_token_transport_headerr;   )r5   r6   r^   r4   r[   r\   r]   ra   s           r!   CloudClientrj     s    ( 			*..!122 X	
 	
 	
 <==:: [[F8}}H'llGZJZJj!!J=H",H'1H$)3H& 	< ( /6H+2F2UH/HMMMMr1   c                 b    t          |          }t          |          }t          |||           S )z
    Return a running chroma.API instance

    tenant: The tenant to use for this client. Defaults to the default tenant.
    database: The database to use for this client. Defaults to the default database.
    r?   )r:   r;   r8   s      r!   r   r   >  s/     [[F8}}HHMMMMr1   c                 "    t          |           S )zU

    Creates an admin client that can be used to create tenants and databases.

    r4   )AdminClientCreatorrm   s    r!   r   r   Q  s     x0000r1   )r   N)NN)Ftypingr   r   loggingchromadb.api.clientr   r;   r   rn   chromadb.api.async_clientr   rX   chromadb.auth.token_authnr   chromadb.configr,   r	   r
   r   chromadb.apir   r   r   chromadb.api.models.Collectionr   chromadb.api.typesr   r   r   r   r   r   r   r   r   r   r   r   __all__	getLogger__name__loggerr.   __version__rN   r"   IN_COLAB	is_clientchromadb.is_thin_clientr#   r   r)   sqlite_version_info
subprocesssys
check_call
executable
__import__modulespopRuntimeErrorr0   r3   r:   r<   rA   rM   rV   rZ   rj   r+   r1   r!   <module>r      s   ! ! ! ! ! ! ! !  7 7 7 7 7 7 A A A A A A G G G G G G : : : : : :     F F F F F F F F F F < < < < < < < < < < 5 5 5 5 5 5                              " 
	8	$	$XZZ
T     ;==	666666II   III  NNN"Z// 	JJJ!J!ui9KL   J{###%([__[%A%ACK	"",(  4 4 4 4h    
 $( $N Nx NN N 	N N N N2 #' $	N N
Nx N N 	N
 N N N N8 (,#' $0N 0N
0N
0N 
0N d38n%	0N
 x 0N 0N 0N 0N 0N 0N 0Nh (,#' $2 2
2
2 
2 d38n%	2
 x 2 2 2 2 2 2 2p "#'	7N *7N 7N 7N7N7N c]7N x 	7N 7N 7N 7N 7N 7N 7N 7Nv $ $N NNN N 	N N N N& &.XZZ 1 1( 1H 1 1 1 1 1 1s   B B%$B%