@@ -114,30 +114,24 @@ async def start_server(configs: Config):
114114 return process
115115
116116
117- __CLIENT_CACHE : dict [str , AsyncClientAPI ] = {}
118-
119-
120117async def get_client (configs : Config ) -> AsyncClientAPI :
121- client_entry = configs .db_url
122- if __CLIENT_CACHE .get (client_entry ) is None :
123- settings : dict [str , Any ] = {"anonymized_telemetry" : False }
124- if isinstance (configs .db_settings , dict ):
125- valid_settings = {
126- k : v for k , v in configs .db_settings .items () if k in Settings .__fields__
127- }
128- settings .update (valid_settings )
129- parsed_url = urlparse (configs .db_url )
130- settings ["chroma_server_host" ] = parsed_url .hostname or "127.0.0.1"
131- settings ["chroma_server_http_port" ] = parsed_url .port or 8000
132- settings ["chroma_server_ssl_enabled" ] = parsed_url .scheme == "https"
133- settings ["chroma_server_api_default_path" ] = parsed_url .path or APIVersion .V2
134- settings_obj = Settings (** settings )
135- __CLIENT_CACHE [client_entry ] = await chromadb .AsyncHttpClient (
136- settings = settings_obj ,
137- host = str (settings_obj .chroma_server_host ),
138- port = int (settings_obj .chroma_server_http_port or 8000 ),
139- )
140- return __CLIENT_CACHE [client_entry ]
118+ settings : dict [str , Any ] = {"anonymized_telemetry" : False }
119+ if isinstance (configs .db_settings , dict ):
120+ valid_settings = {
121+ k : v for k , v in configs .db_settings .items () if k in Settings .__fields__
122+ }
123+ settings .update (valid_settings )
124+ parsed_url = urlparse (configs .db_url )
125+ settings ["chroma_server_host" ] = parsed_url .hostname or "127.0.0.1"
126+ settings ["chroma_server_http_port" ] = parsed_url .port or 8000
127+ settings ["chroma_server_ssl_enabled" ] = parsed_url .scheme == "https"
128+ settings ["chroma_server_api_default_path" ] = parsed_url .path or APIVersion .V2
129+ settings_obj = Settings (** settings )
130+ return await chromadb .AsyncHttpClient (
131+ settings = settings_obj ,
132+ host = str (settings_obj .chroma_server_host ),
133+ port = int (settings_obj .chroma_server_http_port or 8000 ),
134+ )
141135
142136
143137def get_collection_name (full_path : str ) -> str :
@@ -277,7 +271,7 @@ class ClientManager:
277271 __clients : dict [str , _ClientModel ]
278272
279273 def __new__ (cls ) -> "ClientManager" :
280- if cls .__singleton is None :
274+ if not hasattr ( cls , "__singleton" ) or cls .__singleton is None :
281275 cls .__singleton = super ().__new__ (cls )
282276 cls .__singleton .__clients = {}
283277 return cls .__singleton
0 commit comments