o
    g,                     @   s  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'e(Z)e a*dZ+de,fddZ-e- Z.dZ/z
d dl0m1Z1 e1Z/W n e2y   dZ/Y nw e/sd dl3Z3e3j4dk re.rd dl5Z5d dl6Z6e57e6j8ddddg e9d e6j:;de6j:d< ne<dd>ddZ=defddZ>deefdee de?d e?defd!d"Z@d#deefd$e?dee de?d e?def
d%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-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/d0ZD		d?d1d(d2d3de?d e?d4ee? dee d5e?d6eBd7e,defd8d9ZEt*eefdede?d e?defd:d;Ze fdedefd<d=ZdS )@    )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                  C   s$   zdd l } W dS  ty   Y dS w )Nr   TF)google.colabImportError)google r   H/var/www/visachat/venv/lib/python3.10/site-packages/chromadb/__init__.pyis_in_colab3   s   r!   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                  K   s   t jjdi | adS )zGOverride Chroma's default settings, environment variables or .env filesNr   )chromadbconfigr
   
__settings)kwargsr   r   r    	configure^   s   r-   c                   C   s   t S )N)r+   r   r   r   r    get_settingsd   s   r.   settingstenantdatabasec                 C   s2   | du rt  } d| _t|}t|}t| ||d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r/   r0   r1   )r
   is_persistentstrClientCreatorr2   r   r   r    EphemeralClienth   s   r6   z./chromapathc                 C   s8   |du rt  }| |_d|_t|}t|}t|||d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r0   r1   r/   )r
   persist_directoryr3   r4   r5   )r7   r/   r0   r1   r   r   r    PersistentClient   s   r:   	localhosti@  hostportsslheadersc                 C   s   |du rt  }t| } t|}t|}t|}t|}d|_|jr2|j| kr2td|j d|  d| |_|jrI|j|krItd|j d| d||_||_||_	t
|||d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[r8   )r
   r4   intboolchroma_api_implchroma_server_host
ValueErrorchroma_server_http_portchroma_server_ssl_enabledchroma_server_headersr5   r<   r=   r>   r?   r/   r0   r1   r   r   r    
HttpClient   s*   rN   c                    s   |du rt  }t| } t|}t|}t|}t|}d|_|jr3|j| kr3td|j d|  d| |_|jrJ|j|krJtd|j d| d||_||_||_	t
j|||dI dH 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.AsyncFastAPIrA   rB   rC   rD   r8   )r
   r4   rE   rF   rG   rH   rI   rJ   rK   rL   AsyncClientCreatorcreaterM   r   r   r    AsyncHttpClient   s0   rQ   zapi.trychroma.comT)
cloud_host
cloud_port
enable_sslapi_keyrR   rS   rT   c                C   s   |du rddl }|jd}|du rtd td}|du r!t }t| } t|}t|}t|}t|}t|}d|_	||_
||_||_d|_||_tj|_t| ||d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: r@   z1chromadb.auth.token_authn.TokenAuthClientProviderr8   )osenvirongetprintinputr
   r4   rE   rF   rG   rH   rJ   rK   chroma_client_auth_providerchroma_client_auth_credentialsr   X_CHROMA_TOKEN"chroma_auth_token_transport_headerr5   )r0   r1   rU   r/   rR   rS   rT   rW   r   r   r    CloudClient  s2   r`   c                 C   s   t |}t |}t||| d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.
    r8   )r4   r5   r2   r   r   r    r   =  s   r   c                 C   s
   t | dS )zU

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

    r/   )AdminClientCreatorra   r   r   r    r   P  s   
r   )r   N)NN)Ftypingr   r   loggingchromadb.api.clientr   r5   r   rb   chromadb.api.async_clientr   rO   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__rF   r!   IN_COLAB	is_clientchromadb.is_thin_clientr"   r   r(   sqlite_version_info
subprocesssys
check_call
executable
__import__modulespopRuntimeErrorr-   r.   r4   r6   r:   rE   rN   rQ   r`   r   r   r   r    <module>   s.   8
	

	


4
8	
;
