o
    ɭRhE1                     @   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%m&Z&m'Z'm(Z(m)Z) g dZ*e+e,Z-e a.dZ/de0fddZ1e1 Z2dZ3z
d dl4m5Z5 e5Z3W n e6y   dZ3Y nw e3sd dl7Z7e7j8dk re2rd dl9Z9d dl:Z:e9;e:j<ddddg e=d e:j>?de:j>d< ne@dd@ddZAdefddZBdeefdee deCd eCdefd!d"ZDd#deefd$eCdee deCd eCdef
d%d&ZEddeefd$eeC dee deCd eCdef
d'd(ZFd)d*dddeefd+eCd,eGd-e0d.eeeCeCf  dee deCd eCdefd/d0ZHd)d*dddeefd+eCd,eGd-e0d.eeeCeCf  dee deCd eCdefd1d2ZI		dAd3d*d4d5deCd eCd6eeC dee d7eCd8eGd9e0defd:d;ZJt.eefdedeCd eCdefd<d=Ze fdedefd>d?ZdS )B    )DictOptionalN)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)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z1.0.12returnc                  C   s$   zdd l } W dS  ty   Y dS w )Nr   TF)google.colabImportError)google r#   S/home/air/sanwanet/backup_V2/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$   	configureg   s   r1   c                   C   s   t S )N)r/   r#   r#   r#   r$   get_settingsm   s   r2   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r3   r4   r5   )r
   is_persistentstrClientCreatorr6   r#   r#   r$   EphemeralClientq   s   r:   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r4   r5   r3   )r
   persist_directoryr7   r8   r9   r;   r3   r4   r5   r#   r#   r$   PersistentClient   s   r?   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_implr7   r=   r8   r9   r>   r#   r#   r$   
RustClient   s   

rB   	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
   r8   intboolrA   chroma_server_host
ValueErrorchroma_server_http_portchroma_server_ssl_enabledchroma_server_headersr9   rD   rE   rF   rG   r3   r4   r5   r#   r#   r$   
HttpClient   s*   rU   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.AsyncFastAPIrI   rJ   rK   rL   r<   )r
   r8   rM   rN   rA   rO   rP   rQ   rR   rS   AsyncClientCreatorcreaterT   r#   r#   r$   AsyncHttpClient   s0   rX   zapi.trychroma.comT)
cloud_host
cloud_port
enable_sslapi_keyrY   rZ   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: rH   z1chromadb.auth.token_authn.TokenAuthClientProviderr<   )osenvirongetprintinputr
   r8   rM   rN   rA   rO   rQ   rR   chroma_client_auth_providerchroma_client_auth_credentialsr   X_CHROMA_TOKEN"chroma_auth_token_transport_headerr9   )r4   r5   r\   r3   rY   rZ   r[   r^   r#   r#   r$   CloudClient)  s2   rg   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<   )r8   r9   r6   r#   r#   r$   r   c  s   r   c                 C   s
   t | dS )zU

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

    r3   )AdminClientCreatorrh   r#   r#   r$   r   v  s   
r   )r   N)NN)Ktypingr   r   loggingchromadb.api.clientr   r9   r   ri   chromadb.api.async_clientr   rV   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   __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RuntimeErrorr1   r2   r8   r:   r?   rB   rM   rU   rX   rg   r#   r#   r#   r$   <module>   sL   H
	

	



4
8	
;
