
    ug,                        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jN                  e(      Z) e       a*dZ+de,fdZ- e-       Z.dZ/	 d dl0m1Z1 e1Z/e/swd dl3Z3e3jh                  dk  rde.rZd dl5Z5d dl6Z6 e5jn                  e6jp                  ddddg        e9d       e6jt                  jw                  d      e6jt                  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y# e2$ r dZ/Y Jw xY w)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.6.3returnc                  ,    	 dd l } y# t        $ r Y yw xY w)Nr   TF)google.colabImportError)googles    F/var/www/openai/venv/lib/python3.12/site-packages/chromadb/__init__.pyis_in_colabr"   3   s     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                  B    t        j                  j                  di | ay)zGOverride Chroma's default settings, environment variables or .env filesN )chromadbconfigr   
__settings)kwargss    r!   	configurer0   ^   s     ))3F3J    c                      t         S )N)r.   r+   r1   r!   get_settingsr3   d   s    r1   settingstenantdatabasec                 p    | 
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.
    Fr4   r5   r6   )r   is_persistentstrClientCreatorr8   s      r!   EphemeralClientr<   h   s<     :"H [F8}H(6H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.
    Tr5   r6   r4   )r   persist_directoryr9   r:   r;   )r=   r4   r5   r6   s       r!   PersistentClientrA      sD     :!%H!H [F8}HHMMr1   	localhosti@  hostportsslheadersc                    |
t               }t        |       } t        |      }t        |      }t        |      }t        |      }d|_        |j
                  r+|j
                  | k7  rt        d|j
                   d|  d      | |_        |j                  r+|j                  |k7  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.
    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      s"   0 : t9Dt9D
s)C[F8}H=H""x'B'Bd'J6x7R7R6S  TG  HL  GM  MN  O
 	
 #'H''H,L,LPT,T;H<\<\;]  ^Q  RV  QW  WX  Y
 	
 (,H$),H&%,H"HMMr1   c                   K   |
t               }t        |       } t        |      }t        |      }t        |      }t        |      }d|_        |j
                  r+|j
                  | k7  rt        d|j
                   d|  d      | |_        |j                  r+|j                  |k7  rt        d|j                   d| d      ||_        ||_        ||_	        t        j                  |||       d{   S 7 w)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      s;    0 : t9Dt9D
s)C[F8}HHH""x'B'Bd'J6x7R7R6S  TG  HL  GM  MN  O
 	
 #'H''H,L,LPT,T;H<\<\;]  ^Q  RV  QW  WX  Y
 	
 (,H$),H&%,H"#**8   s   C0C92C73C9zapi.trychroma.comT)
cloud_host
cloud_port
enable_sslapi_keyr[   r\   r]   c                   |ddl }|j                  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 X	
 <=: [F8}H'lGZJZJj!J=H",H'1H$)3H& 	< ( /6H+2F2U2UH/HMMr1   c                 J    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Mr1   c                     t        |       S )zU

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

    r4   )AdminClientCreatorrm   s    r!   r   r   P  s     x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 A G :  F F < < 5    " 
		8	$Z
T  =	6I ""Z/!J!!ui9KL {#%([[__[%ACKK	"( 4h 
 $( $Nx NN N 	N2 #' $	N
Nx N N 	N
 N8 (,#' $0N
0N
0N 
0N d38n%	0N
 x 0N 0N 0N 0Nh (,#' $2
2
2 
2 d38n%	2
 x 2 2 2 2p "#'	7N *7N7N7N c]7N x 	7N 7N 7N 7N 7Nv $ $NNN N 	N& &.Z 1( 1H 1[  Is   G G! G!