
    q9iv9                        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*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAZAg dZBd dlCmDZD  ej                  eF      ZG e       aHdZIdeJfdZK eK       ZLdZM	 d dlNmOZO eOZMeMswd dlQZQeQj                  dk  rdeLrZd dlSZSd dlTZT eSj                  eTj                  ddddg        eWd       eTj                  j                  d      eTj                  d<   n eZd      d:d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e]e@f   dee   d e]d!e]def
d%Z_ddeefd$ee]   dee   d e]d!e]def
d&Z`d'd(dddeefd)e]d*ead+eJd,eee]e]f      dee   d e]d!e]defd-Zbd'd(dddeefd)e]d*ead+eJd,eee]e]f      dee   d e]d!e]defd.Zc	 	 	 	 d;d/d0d1d2d ee]   d!ee]   d3ee]   dee   d4e]d5ead6eJdefd7Zdt        eefded e]d!e]defd8Z e       fdedefd9Zy# eP$ r dZMY pw xY w)<    )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SparseVectorSparseVectorsSparseEmbeddingFunctionSchemaVectorIndexConfigHnswIndexConfigSpannIndexConfigFtsIndexConfigSparseVectorIndexConfigStringInvertedIndexConfigIntInvertedIndexConfigFloatInvertedIndexConfigBoolInvertedIndexConfig)Search)KeyKKnnRrf)Path)$r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r	   r.   r/   r0   r1   r2   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   )CloudClientArgz1.3.6returnc                  ,    	 dd l } y# t        $ r Y yw xY w)Nr   TF)google.colabImportError)googles    Z/var/www/html/leadgen/airagagent/rag_env/lib/python3.12/site-packages/chromadb/__init__.pyis_in_colabr;   p   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:   	configurerI      s     ))3F3J    c                      t         S )N)rG   rD   rJ   r:   get_settingsrL      s    rJ   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rM   rN   rO   )r   is_persistentstrClientCreatorrQ   s      r:   EphemeralClientrU      s<     :"H [F8}H(6HMMrJ   z./chromapathc                     |
t               }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rN   rO   rM   )r   rS   persist_directoryrR   rT   rV   rM   rN   rO   s       r:   PersistentClientr[      sH     :!$TH!H [F8}HHMMrJ   c                     |
t               }d|_        | du|_        | xs d|_        t	        |      }t	        |      }t        |||      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 rX   )r   chroma_api_implrR   rY   rS   rT   rZ   s       r:   
RustClientr_      sU     :BH!-H!%H [F8}HHMMrJ   	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[rX   )r   rS   intboolr^   chroma_server_host
ValueErrorchroma_server_http_portchroma_server_ssl_enabledchroma_server_headersrT   ra   rb   rc   rd   rM   rN   rO   s          r:   
HttpClientrs      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MrJ   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.AsyncFastAPIrg   rh   ri   rj   rX   )r   rS   rk   rl   r^   rm   rn   ro   rp   rq   AsyncClientCreatorcreaterr   s          r:   AsyncHttpClientrw   (  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.comi  T)
cloud_host
cloud_port
enable_sslapi_keyrx   ry   rz   c                   t        dd|      g}t        |D cg c]  }|j                   c}      sC|D ]>  }|j                  xs) t        j                  j                  |j                        |_        @ |D cg c]  }|j                  | }	}|	r_t        ddj                  |	D cg c]  }|j                   c}       ddj                  |	D cg c]  }|j                   c}             |
t               }| xs t        j                  j                  d      } | t        |       } |xs t        j                  j                  d      }|t        |      }t        |      }t        |      }t        |      }t        |      }d	|_        ||_        ||_        ||_        d
|_        ||_        t(        j*                  |_        d|_        t1        | ||      S c c}w c c}w c c}w c c}w )aK  
    Creates a client to connect to a tenant and database on Chroma cloud.

    Args:
        tenant: The tenant to use for this client. Optional. If not provided, it will be inferred from the API key if the key is scoped to a single tenant. If provided, it will be validated against the API key's scope.
        database: The database to use for this client. Optional. If not provided, it will be inferred from the API key if the key is scoped to a single database. If provided, it will be validated against the API key's scope.
        api_key: The api key to use for this client.
    r{   CHROMA_API_KEY)nameenv_varvaluezMissing required arguments: z, z8. Please provide them or set the environment variables: CHROMA_TENANTCHROMA_DATABASErf   z1chromadb.auth.token_authn.TokenAuthClientProviderTrX   )r4   allr   osenvirongetr   rn   joinr~   r   rS   rk   rl   r^   rm   ro   rp   chroma_client_auth_providerchroma_client_auth_credentialsr	   X_CHROMA_TOKEN"chroma_auth_token_transport_header;chroma_overwrite_singleton_tenant_database_access_from_authrT   )
rN   rO   r{   rM   rx   ry   rz   required_argsargmissing_argss
             r:   CloudClientr   ]  s   ( 	I/?wOM
 ]3c		34  	AC		@RZZ^^CKK%@CI	A $1FCCII4ECFLF*499,5W3chh5W+X*Y ZEEIYYgsOt`cPSP[P[OtEuDvx
 	

 : 6rzz~~o6FV<2::>>*;<Hx='lGZJZJj!J=H",H'1H$)3H& 	< ( /6H+2F2U2UH/KOHHHMMM 4 G 6XOts   G:G$G$)G)G.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.
    rX   )rS   rT   rQ   s      r:   r   r     s%     [F8}HHMMrJ   c                     t        |       S )zU

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

    rM   )AdminClientCreatorr   s    r:   r   r     s     x00rJ   )r5   N)NNNN)etypingr   r   r   loggingchromadb.api.clientr   rT   r   r   chromadb.api.async_clientr   ru   chromadb.auth.token_authnr	   chromadb.configrE   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    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   "chromadb.execution.expression.planr.   &chromadb.execution.expression.operatorr/   r0   r1   r2   pathlibr3   r   __all__chromadb.typesr4   	getLogger__name__loggerrG   __version__rl   r;   IN_COLAB	is_clientchromadb.is_thin_clientr<   r8   rB   sqlite_version_info
subprocesssys
check_call
executable
__import__modulespopRuntimeErrorrI   rL   rS   rU   r[   r_   rk   rs   rw   r   rD   rJ   r:   <module>r      s$   ( (  7 H :  F F < < 5       B 6   	(T *			8	$Z
T  =	6I ""Z/!J!!ui9KL {#%([[__[%ACKK	"( 4h 
 $( $Nx NN N 	N2 (#' $	N
T	
Nx N N 	N
 N8 #' $	N
3-Nx N N 	N
 N< (,#' $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l !"!#'	>N *>NSM>Nsm>N c]>N x 	>N >N >N >N >ND $ $NNN N 	N& &.Z 1( 1H 1c	  Is   I II