o
    \hw1                     @   sV  d dl mZ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&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, g dZ-e.e/Z0e a1dZ2de3fddZ4e4 Z5dZ6z
d dl7m8Z8 e8Z6W n e9y   dZ6Y nw e6sd dl:Z:e:j;dk re5rd dl<Z<d dl=Z=e<>e=j?ddddg e@d e=jABde=jAd< neCddAddZDdefddZEdeefdee d eFd!eFdefd"d#ZGd$deefd%eeFe,f dee d eFd!eFdef
d&d'ZHddeefd%eeF dee d eFd!eFdef
d(d)ZId*d+dddeefd,eFd-eJd.e3d/eeeFeFf  dee d eFd!eFdefd0d1ZKd*d+dddeefd,eFd-eJd.e3d/eeeFeFf  dee d eFd!eFdefd2d3ZL		dBd4d+d5d6d eFd!eFd7eeF dee d8eFd9eJd:e3defd;d<ZMt1eefded eFd!eFdefd=d>Ze fdedefd?d@ZdS )C    )DictOptionalUnionN)Client)AdminClient)AsyncClient)TokenTransportHeader)DEFAULT_DATABASEDEFAULT_TENANTSettings)AdminAPIAsyncClientAPI	ClientAPI)
Collection)CollectionMetadataUpdateMetadata	DocumentsEmbeddingFunction
EmbeddingsURIURIsIDsIncludeMetadata	MetadatasWhereQueryResult	GetResultWhereDocumentUpdateCollectionMetadata)Path)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z1.0.13returnc                  C   s$   zdd l } W dS  ty   Y dS w )Nr   TF)google.colabImportError)google r%   T/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/chromadb/__init__.pyis_in_colab=   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&   	configureh   s   r3   c                   C   s   t S )N)r1   r%   r%   r%   r&   get_settingsn   s   r4   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r5   r6   r7   )r   is_persistentstrClientCreatorr8   r%   r%   r&   EphemeralClientr   s   r<   z./chromapathc                 C   s<   |du rt  }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r6   r7   r5   )r   r:   persist_directoryr9   r;   r=   r5   r6   r7   r%   r%   r&   PersistentClient   s   
rA   c                 C   sF   |du rt  }d|_| du|_| pd|_t|}t|}t|||dS )a  
    Creates an ephemeral or persistance instance of Chroma that saves to disk.
    This is useful for testing and development, but not recommended for production use.

    Args:
        path: An optional directory to save Chroma's data to. The client is ephemeral if a None value is provided. Defaults to None.
        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.rust.RustBindingsAPI r>   )r   chroma_api_implr9   r?   r:   r;   r@   r%   r%   r&   
RustClient   s   

rD   	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[r>   )r   r:   intboolrC   chroma_server_host
ValueErrorchroma_server_http_portchroma_server_ssl_enabledchroma_server_headersr;   rF   rG   rH   rI   r5   r6   r7   r%   r%   r&   
HttpClient   s*   rW   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.AsyncFastAPIrK   rL   rM   rN   r>   )r   r:   rO   rP   rC   rQ   rR   rS   rT   rU   AsyncClientCreatorcreaterV   r%   r%   r&   AsyncHttpClient   s0   rZ   zapi.trychroma.comT)
cloud_host
cloud_port
enable_sslapi_keyr[   r\   r]   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: rJ   z1chromadb.auth.token_authn.TokenAuthClientProviderr>   )osenvirongetprintinputr   r:   rO   rP   rC   rQ   rS   rT   chroma_client_auth_providerchroma_client_auth_credentialsr   X_CHROMA_TOKEN"chroma_auth_token_transport_headerr;   )r6   r7   r^   r5   r[   r\   r]   r`   r%   r%   r&   CloudClient*  s2   ri   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.
    r>   )r:   r;   r8   r%   r%   r&   r   d  s   r   c                 C   s
   t | dS )zU

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

    r5   )AdminClientCreatorrj   r%   r%   r&   r   w  s   
r   )r!   N)NN)Ntypingr   r   r   loggingchromadb.api.clientr   r;   r   rk   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   r   r   r   r   pathlibr    __all__	getLogger__name__loggerr1   __version__rP   r'   IN_COLAB	is_clientchromadb.is_thin_clientr(   r#   r.   sqlite_version_info
subprocesssys
check_call
executable
__import__modulespopRuntimeErrorr3   r4   r:   r<   rA   rD   rO   rW   rZ   ri   r%   r%   r%   r&   <module>   sN   H
	

	




4
8	
;
