1- import json
1+ import orjson as json
22import logging
33from typing import Optional , cast , Tuple
44from typing import Sequence
@@ -147,7 +147,7 @@ def heartbeat(self) -> int:
147147 """Returns the current server time in nanoseconds to check if the server is alive"""
148148 resp = self ._session .get (self ._api_url )
149149 raise_chroma_error (resp )
150- return int (resp . json ( )["nanosecond heartbeat" ])
150+ return int (json . loads ( resp . text )["nanosecond heartbeat" ])
151151
152152 @trace_method ("FastAPI.create_database" , OpenTelemetryGranularity .OPERATION )
153153 @override
@@ -177,7 +177,7 @@ def get_database(
177177 params = {"tenant" : tenant },
178178 )
179179 raise_chroma_error (resp )
180- resp_json = resp . json ( )
180+ resp_json = json . loads ( resp . text )
181181 return Database (
182182 id = resp_json ["id" ], name = resp_json ["name" ], tenant = resp_json ["tenant" ]
183183 )
@@ -198,7 +198,7 @@ def get_tenant(self, name: str) -> Tenant:
198198 self ._api_url + "/tenants/" + name ,
199199 )
200200 raise_chroma_error (resp )
201- resp_json = resp . json ( )
201+ resp_json = json . loads ( resp . text )
202202 return Tenant (name = resp_json ["name" ])
203203
204204 @trace_method ("FastAPI.list_collections" , OpenTelemetryGranularity .OPERATION )
@@ -221,7 +221,7 @@ def list_collections(
221221 },
222222 )
223223 raise_chroma_error (resp )
224- json_collections = resp . json ( )
224+ json_collections = json . loads ( resp . text )
225225 collections = []
226226 for json_collection in json_collections :
227227 collections .append (Collection (self , ** json_collection ))
@@ -239,7 +239,7 @@ def count_collections(
239239 params = {"tenant" : tenant , "database" : database },
240240 )
241241 raise_chroma_error (resp )
242- return cast (int , resp . json ( ))
242+ return cast (int , json . loads ( resp . text ))
243243
244244 @trace_method ("FastAPI.create_collection" , OpenTelemetryGranularity .OPERATION )
245245 @override
@@ -268,7 +268,7 @@ def create_collection(
268268 params = {"tenant" : tenant , "database" : database },
269269 )
270270 raise_chroma_error (resp )
271- resp_json = resp . json ( )
271+ resp_json = json . loads ( resp . text )
272272 return Collection (
273273 client = self ,
274274 id = resp_json ["id" ],
@@ -302,7 +302,7 @@ def get_collection(
302302 self ._api_url + "/collections/" + name if name else str (id ), params = _params
303303 )
304304 raise_chroma_error (resp )
305- resp_json = resp . json ( )
305+ resp_json = json . loads ( resp . text )
306306 return Collection (
307307 client = self ,
308308 name = resp_json ["name" ],
@@ -381,7 +381,7 @@ def _count(
381381 self ._api_url + "/collections/" + str (collection_id ) + "/count"
382382 )
383383 raise_chroma_error (resp )
384- return cast (int , resp . json ( ))
384+ return cast (int , json . loads ( resp . text ))
385385
386386 @trace_method ("FastAPI._peek" , OpenTelemetryGranularity .OPERATION )
387387 @override
@@ -434,7 +434,7 @@ def _get(
434434 )
435435
436436 raise_chroma_error (resp )
437- body = resp . json ( )
437+ body = json . loads ( resp . text )
438438 return GetResult (
439439 ids = body ["ids" ],
440440 embeddings = body .get ("embeddings" , None ),
@@ -462,7 +462,7 @@ def _delete(
462462 )
463463
464464 raise_chroma_error (resp )
465- return cast (IDs , resp . json ( ))
465+ return cast (IDs , json . loads ( resp . text ))
466466
467467 @trace_method ("FastAPI._submit_batch" , OpenTelemetryGranularity .ALL )
468468 def _submit_batch (
@@ -586,7 +586,7 @@ def _query(
586586 )
587587
588588 raise_chroma_error (resp )
589- body = resp . json ( )
589+ body = json . loads ( resp . text )
590590
591591 return QueryResult (
592592 ids = body ["ids" ],
@@ -604,15 +604,15 @@ def reset(self) -> bool:
604604 """Resets the database"""
605605 resp = self ._session .post (self ._api_url + "/reset" )
606606 raise_chroma_error (resp )
607- return cast (bool , resp . json ( ))
607+ return cast (bool , json . loads ( resp . text ))
608608
609609 @trace_method ("FastAPI.get_version" , OpenTelemetryGranularity .OPERATION )
610610 @override
611611 def get_version (self ) -> str :
612612 """Returns the version of the server"""
613613 resp = self ._session .get (self ._api_url + "/version" )
614614 raise_chroma_error (resp )
615- return cast (str , resp . json ( ))
615+ return cast (str , json . loads ( resp . text ))
616616
617617 @override
618618 def get_settings (self ) -> Settings :
@@ -626,7 +626,7 @@ def max_batch_size(self) -> int:
626626 if self ._max_batch_size == - 1 :
627627 resp = self ._session .get (self ._api_url + "/pre-flight-checks" )
628628 raise_chroma_error (resp )
629- self ._max_batch_size = cast (int , resp . json ( )["max_batch_size" ])
629+ self ._max_batch_size = cast (int , json . loads ( resp . text )["max_batch_size" ])
630630 return self ._max_batch_size
631631
632632
@@ -637,7 +637,7 @@ def raise_chroma_error(resp: requests.Response) -> None:
637637
638638 chroma_error = None
639639 try :
640- body = resp . json ( )
640+ body = json . loads ( resp . text )
641641 if "error" in body :
642642 if body ["error" ] in errors .error_types :
643643 chroma_error = errors .error_types [body ["error" ]](body ["message" ])
0 commit comments