o
    ɭRh?H                     @   s`  U d dl Z d dl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
mZmZmZ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 d d	lmZ d dlZd
Zzd dlmZ W n eyr   dZd dlmZ d dlmZ Y nw es{d dlmZ d
Z zd dl!m Z  W n ey   d
Z Y nw e"e#Z$dZ%dhZ&h dZ'i ddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1Z(ee)e)f e*d2< d3Z+d4Z,G d5d6 d6e)eZ-G d7d8 d8eZ.G d9d: d:eZ/ed;d<d=Z0G d>d< d<eeZ1G d?d@ d@e1Z2edAZ3dBe)dCee3 dDee3 fdEdFZ4dGee5 dDe)fdHdIZ6dS )J    N)ABC)Enum)TopologicalSorter)OptionalListAnyDictSetIterableUnion)TypeTypeVarcast)EnforceOverrides)override)LiteralF)BaseSettingsT)	validator)is_thin_clienta  [91mYou are using a deprecated configuration of Chroma.

[94mIf you do not have data you wish to migrate, you only need to change how you construct
your Chroma client. Please see the "New Clients" section of https://docs.trychroma.com/deployment/migration.
________________________________________________________________________________________________

If you do have data you wish to migrate, we have a migration tool you can use in order to
migrate your data to the new Chroma architecture.
Please `pip install chroma-migrate` and run `chroma-migrate` to migrate your data and then
change how you construct your Chroma client.

See https://docs.trychroma.com/deployment/migration for more information or join our discord at https://discord.gg/MMeYNTmh3x for help![0mchroma_db_impl>	   duckdb+parquetchromadb.db.duckdb.DuckDBchromadb.api.local.LocalAPI!chromadb.db.clickhouse.Clickhouse#chromadb.db.duckdb.PersistentDuckDBrestlocalduckdb
clickhousezchromadb.api.APIchroma_api_implzchromadb.api.ServerAPIz%chromadb.api.async_api.AsyncServerAPIz chromadb.auth.ClientAuthProviderchroma_client_auth_providerz*chromadb.auth.ServerAuthenticationProviderchroma_server_authn_providerz)chromadb.auth.ServerAuthorizationProviderchroma_server_authz_providerzchromadb.db.system.SysDBchroma_sysdb_implz-chromadb.execution.executor.abstract.Executorchroma_executor_implzchromadb.ingest.Consumerchroma_consumer_implzchromadb.ingest.Producerchroma_producer_implzchromadb.quota.QuotaEnforcerchroma_quota_enforcer_implz%chromadb.rate_limit.RateLimitEnforcerchroma_rate_limit_enforcer_implz*chromadb.rate_limit.AsyncRateLimitEnforcer%chroma_async_rate_limit_enforcer_implzchromadb.segment.SegmentManagerchroma_segment_manager_implz-chromadb.segment.distributed.SegmentDirectorychroma_segment_directory_implz/chromadb.segment.distributed.MemberlistProviderchroma_memberlist_provider_implz1chromadb.telemetry.product.ProductTelemetryClientchroma_product_telemetry_impl_abstract_type_keysdefault_tenantdefault_databasec                   @      e Zd ZdZdZdS )
APIVersionz/api/v1z/api/v2N)__name__
__module____qualname__V1V2 r8   r8   Q/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/chromadb/config.pyr2   _       r2   c                   @   s   e Zd ZdZdZdZdS )RoutingModea  
    Routing mode for the segment directory

    node - Assign based on the node name, used in production with multi-node settings with the assumption that
    there is one query service pod per node. This is useful for when there is a disk based cache on the
    node that we want to route to.

    id - Assign based on the member id, used in development and testing environments where the node name is not
    guaranteed to be unique. (I.e a local development kubernetes env). Or when there are multiple query service
    pods per node.
    nodeidN)r3   r4   r5   __doc__NODEIDr8   r8   r8   r9   r;   g   s    r;   c                   @   s  e Zd ZU dZeed< dZeed< edddddded	ee fd
dZ	dZ
ee ed< dZeed< dZeed< dZeed< dZee ed< dZeeeef  ed< dZee ed< dZee ed< dZeeeef  ed< ejZee ed< g Zee ed< dZeed< dZeed< dZeed< dZee ed< dZ eed < dZ!ee ed!< dZ"ee ed"< dZ#ee ed#< ej d$gej d%d$gej d&d$gej$ d$gej$ d%d$gej$ d&d$giZ%eeee f ed'< dZ&eed(< dZ'ee ed)< dZ(ee ed*< dZ)ee ed+< dZ*ee ed,< dZ+ee ed-< dZ,ee ed.< d/Z-eed0< e-Z.eed1< dZ/eed2< dZ0ee ed3< d4Z1ee ed5< i Z2eeef ed6< dZ3ee ed7< d8Z4e5d9 ed:< d;Z6e5d< ed=< d>Z7eed?< e8j9Z:e8ed@< dAZ;eedB< dCZ<eedD< dEZ=dZ>ee edF< dGZ?eedH< dGZ@eedI< dGZAeedJ< dKZBeedL< dMZCeedN< dOZDeedP< dEZEdQZFdZGee edR< dZHee edS< dTZIeedU< dVZJeedW< dXZKeedY< dZZLeed[< dZZMeed\< d]ZNeed^< dZOee ed_< d`ZPeeda< dbed	eQfdcddZRdbed	eQfdedfZSG dgdh dhZTdS )iSettings environmentz!chromadb.api.rust.RustBindingsAPIr   chroma_server_nofileT)prealwaysallow_reusevreturnc                 C   s    t |tu r| dkrd S |S )NrB   )typestrstrip)clsrH   r8   r8   r9   empty_str_to_none   s   zSettings.empty_str_to_noneN(   chroma_server_thread_pool_sizedefault	tenant_idtopic_namespacechroma_server_hostchroma_server_headerschroma_server_http_portFchroma_server_ssl_enabledchroma_server_ssl_verifychroma_server_api_default_path chroma_server_cors_allow_originsis_persistentz./chromapersist_directoryr   chroma_memory_limit_byteschroma_segment_cache_policyallow_reset"chroma_auth_token_transport_headerr    chroma_client_auth_credentialsGETz
/heartbeatz/versionchroma_server_auth_ignore_paths;chroma_overwrite_singleton_tenant_database_access_from_authr!   chroma_server_authn_credentials$chroma_server_authn_credentials_filer"   chroma_server_authz_configchroma_server_authz_config_filez*chromadb.telemetry.product.posthog.Posthogr-   chroma_telemetry_implanonymized_telemetrychroma_otel_collection_endpointchromadbchroma_otel_service_namechroma_otel_collection_headerschroma_otel_granularityapply)nonevalidaterp   
migrationsmd5)rt   sha256migrations_hash_algorithmzRchromadb.segment.impl.distributed.segment_directory.RendezvousHashSegmentDirectoryr+   %chroma_segment_directory_routing_modezTchromadb.segment.impl.distributed.segment_directory.CustomResourceMemberlistProviderr,   zquery-service-memberlistworker_memberlist_name	localhostchroma_server_grpc_portz chromadb.db.impl.sqlite.SqliteDBr#   r&   r%   z7chromadb.segment.impl.manager.local.LocalSegmentManagerr*   z/chromadb.execution.executor.local.LocalExecutorr$      chroma_query_replication_factori  chroma_quota_provider_impl"chroma_rate_limiting_provider_implz8chromadb.quota.simple_quota_enforcer.SimpleQuotaEnforcerr'   z=chromadb.rate_limit.simple_rate_limit.SimpleRateLimitEnforcerr(   zBchromadb.rate_limit.simple_rate_limit.SimpleAsyncRateLimitEnforcerr)      )chroma_logservice_request_timeout_seconds$chroma_sysdb_request_timeout_seconds<   $chroma_query_request_timeout_secondsr   z9chromadb.ingest.impl.simple_policy.SimpleAssignmentPolicy(chroma_collection_assignment_policy_implkeyc                 C   s$   | | }|du rt d| d|S )zYReturn the value of a required config key, or raise an exception if it is not
        setNzMissing required config value '')
ValueErrorselfr   valr8   r8   r9   require3  s   zSettings.requirec                 C   s(   t | |}t|tr|tv rtt|S N)getattr
isinstancerK   _legacy_config_valuesr   LEGACY_ERRORr   r8   r8   r9   __getitem__;  s   
zSettings.__getitem__c                   @   r1   )zSettings.Configz.envzutf-8N)r3   r4   r5   env_fileenv_file_encodingr8   r8   r8   r9   ConfigB  r:   r   )Ur3   r4   r5   rC   rK   __annotations__r   r   r   rN   rD   intrP   rR   rS   rT   rU   r   rV   rW   boolrX   r   r2   r7   rY   rZ   r   r[   r\   r]   r^   r_   r`   r    ra   r6   rc   rd   r!   re   rf   r"   rg   rh   r-   ri   rj   rk   rm   rn   ro   rs   r   rv   r+   r;   r@   rw   r,   rx   chroma_coordinator_hostrz   r#   r&   r%   r*   r$   r|   chroma_logservice_hostchroma_logservice_portr}   r~   r'   r(   r)   r   r   r   r   r   r   r   r   r   r8   r8   r8   r9   rA   x   s   
 






rA   T	Component)boundc                   @   sz   e Zd ZU ed  ed< ded< eed< dddZdee d	efd
dZ	d	ed  fddZ
dddZdddZdddZdS )r   _dependenciesSystem_system_runningsystemc                 C   s   t  | _|| _d| _d S )NF)setr   r   r   )r   r   r8   r8   r9   __init__O  s   
zComponent.__init__rJ   rI   c                 C   s   | j |}| j| |S )zbGet a Component instance of the given type, and register as a dependency of
        that instance.)r   instancer   add)r   rJ   instr8   r8   r9   r   T  s   zComponent.requirec                 C   s   | j S )z<Return the full set of components this component depends on.)r   r   r8   r8   r9   dependencies[  s   zComponent.dependenciesNc                 C      t d| jj  d| _dS )zWIdempotently stop this component's execution and free all associated
        resources.zStopping component FNloggerdebug	__class__r3   r   r   r8   r8   r9   stop_  s   
zComponent.stopc                 C   r   )z-Idempotently start this component's executionzStarting component TNr   r   r8   r8   r9   starte  s   
zComponent.startc                 C   s   t d| jj  dS )zgReset this component's state to its initial blank state. Only intended to be
        called from tests.zResetting component N)r   r   r   r3   r   r8   r8   r9   reset_statej  s   zComponent.reset_state)r   r   rI   N)r3   r4   r5   r	   r   r   r   r   r   r   r   r   r   r   r8   r8   r8   r9   r   J  s   
 


c                       s   e Zd ZU eed< eee ef ed< def fddZdee	 de	fddZ
dee fd	d
Zed fddZed fddZedddZ  ZS )r   settings
_instancesc                    s~  t r|d dvrtdtD ]}|| d urttq|d d ur7|d dkr7td |d dkr7td	 |d
 d urt dkrdd l	}|
|j\}}|d
 }||krctd| d|  nN||krz||j||f td|  W n6 ty } ztd| d| d|  W Y d }~nd }~ww ||k rtd| d| d ntd || _i | _t |  d S )Nr   )zchromadb.api.fastapi.FastAPIz'chromadb.api.async_fastapi.AsyncFastAPIa  Chroma is running in http-only client mode, and can only be run with 'chromadb.api.fastapi.FastAPI' or 'chromadb.api.async_fastapi.AsyncFastAPI' as the chroma_api_impl.             see https://docs.trychroma.com/guides#using-the-python-http-only-client for more information.r^   LRUzAFailed to set chroma_segment_cache_policy: Only LRU is available.r]   r   zPFailed to set chroma_segment_cache_policy: chroma_memory_limit_bytes is require.rD   WindowszUchroma_server_nofile cannot be set to a value greater than the current hard limit of z. Keeping soft limit at zSet chroma_server_nofile to z&Failed to set chroma_server_nofile to z: z" nofile soft limit will remain at zchroma_server_nofile is set to z., but this is less than current soft limit of z'. chroma_server_nofile will not be set.zWchroma_server_nofile is not supported on Windows. chroma_server_nofile will not be set.)r   RuntimeError_legacy_config_keysr   r   r   errorplatformr   resource	getrlimitRLIMIT_NOFILEloggingwarning	setrlimitinfo	Exceptionr   r   superr   )r   r   r   r   	curr_soft	curr_harddesired_softer   r8   r9   r   t  sd   
zSystem.__init__rJ   rI   c                 C   s   t |r#t|}|tvrtd| t| }| j|}t||}|| jvr8|| }|| j|< | j	r8|
  | j| }tt|S )z|Return an instance of the component type specified. If the system is running,
        the component will be started as well.z"Cannot instantiate abstract type: )inspect
isabstractget_fqnr.   r   r   r   	get_classr   r   r   r   r   )r   rJ   type_fqnr   fqnimplr   r8   r8   r9   r     s   





zSystem.instancec                 C   s4   t  }| j D ]}|j|g| R   q| S )zYReturn the full set of all components and their dependencies in dependency
        order.)r   r   valuesr   r   static_order)r   sorter	componentr8   r8   r9   
components  s   zSystem.componentsNc                    s$   t    |  D ]}|  q	d S r   )r   r   r   r   r   r   r8   r9   r     s   

zSystem.startc                    s,   t    tt|  D ]}|  qd S r   )r   r   reversedlistr   r   r   r8   r9   r     s   

zSystem.stopc                 C   s2   | j jstdtt|  D ]}|  qdS )zOReset the state of this system and all constituents in reverse dependency orderzResetting is not allowed by this configuration (to enable it, set `allow_reset` to `True` in your Settings() or include `ALLOW_RESET=TRUE` in your environment variables)N)r   r_   r   r   r   r   r   r   r8   r8   r9   r     s   
zSystem.reset_stater   )r3   r4   r5   rA   r   r   r   r   r   r   r   r
   r   r   r   r   r   __classcell__r8   r8   r   r9   r   p  s   
 A	r   Cr   rJ   rI   c                 C   s2   |  dd\}}t|}t||}ttt |S )zIGiven a fully qualifed class name, import the module and return the class.   )rsplit	importlibimport_moduler   r   r   r   )r   rJ   module_name
class_namemodulerM   r8   r8   r9   r     s   

r   rM   c                 C   s   | j  d| j S )z.Given a class, return its fully qualified namer   )r4   r3   )rM   r8   r8   r9   r     s   r   )7r   r   r   abcr   enumr   graphlibr   typingr   r   r   r   r	   r
   r   r   r   r   	overridesr   r   typing_extensionsr   r   in_pydantic_v2pydanticr   ImportErrorpydantic.v1r   r   chromadb.is_thin_client	getLoggerr3   r   r   r   r   r.   rK   r   DEFAULT_TENANTDEFAULT_DATABASEr2   r;   rA   r   r   r   r   r   objectr   r8   r8   r8   r9   <module>   s   
 $
	
 P&z