@@ -9,6 +9,7 @@ use chroma_error::{ChromaError, ErrorCodes};
99pub mod admissioncontrolleds3;
1010pub mod config;
1111pub mod local;
12+ pub mod object_storage;
1213pub mod s3;
1314pub mod stream;
1415use local:: LocalStorage ;
@@ -173,7 +174,7 @@ impl ChromaError for StorageError {
173174 StorageError :: PermissionDenied { .. } => ErrorCodes :: PermissionDenied ,
174175 StorageError :: Unauthenticated { .. } => ErrorCodes :: Unauthenticated ,
175176 StorageError :: UnknownConfigurationKey { .. } => ErrorCodes :: InvalidArgument ,
176- StorageError :: Backoff { .. } => ErrorCodes :: ResourceExhausted ,
177+ StorageError :: Backoff => ErrorCodes :: ResourceExhausted ,
177178 StorageError :: CallbackError { .. } => ErrorCodes :: Internal ,
178179 }
179180 }
@@ -193,8 +194,6 @@ pub enum PathError {
193194 } ,
194195}
195196
196- // END BORROWED CODE
197-
198197#[ derive( Error , Debug ) ]
199198pub enum StorageConfigError {
200199 #[ error( "Invalid storage config" ) ]
@@ -207,6 +206,7 @@ pub enum StorageConfigError {
207206#[ allow( clippy:: large_enum_variant) ]
208207pub enum Storage {
209208 S3 ( s3:: S3Storage ) ,
209+ Object ( object_storage:: ObjectStorage ) ,
210210 Local ( local:: LocalStorage ) ,
211211 AdmissionControlledS3 ( admissioncontrolleds3:: AdmissionControlledS3Storage ) ,
212212}
@@ -215,6 +215,7 @@ impl std::fmt::Debug for Storage {
215215 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
216216 match self {
217217 Storage :: S3 ( _) => f. debug_tuple ( "S3" ) . finish ( ) ,
218+ Storage :: Object ( _) => f. debug_tuple ( "Object" ) . finish ( ) ,
218219 Storage :: Local ( _) => f. debug_tuple ( "Local" ) . finish ( ) ,
219220 Storage :: AdmissionControlledS3 ( _) => f. debug_tuple ( "AdmissionControlledS3" ) . finish ( ) ,
220221 }
@@ -235,6 +236,7 @@ impl Storage {
235236 pub fn bucket_name ( & self ) -> Option < & str > {
236237 match self {
237238 Storage :: S3 ( s3) => Some ( & s3. bucket ) ,
239+ Storage :: Object ( obj) => Some ( & obj. bucket ) ,
238240 Storage :: AdmissionControlledS3 ( ac_s3) => Some ( & ac_s3. storage . bucket ) ,
239241 Storage :: Local ( _) => None ,
240242 }
@@ -243,6 +245,10 @@ impl Storage {
243245 pub async fn get ( & self , key : & str , options : GetOptions ) -> Result < Arc < Vec < u8 > > , StorageError > {
244246 match self {
245247 Storage :: S3 ( s3) => s3. get ( key, options) . await ,
248+ Storage :: Object ( obj) => obj
249+ . get ( key, options)
250+ . await
251+ . map ( |( bytes, _) | Vec :: from ( bytes) . into ( ) ) ,
246252 Storage :: Local ( local) => local. get ( key) . await ,
247253 Storage :: AdmissionControlledS3 ( admission_controlled_storage) => {
248254 admission_controlled_storage. get ( key, options) . await
@@ -267,6 +273,11 @@ impl Storage {
267273 let fetch_result = fetch_fn ( Ok ( res. 0 ) ) . await ?;
268274 Ok ( ( fetch_result, res. 1 ) )
269275 }
276+ Storage :: Object ( obj) => {
277+ let ( bytes, etag) = obj. get ( key, options) . await ?;
278+ let fetch_result = fetch_fn ( Ok ( Vec :: from ( bytes) . into ( ) ) ) . await ?;
279+ Ok ( ( fetch_result, Some ( etag) ) )
280+ }
270281 Storage :: Local ( local) => {
271282 let res = local. get_with_e_tag ( key) . await ?;
272283 let fetch_result = fetch_fn ( Ok ( res. 0 ) ) . await ?;
@@ -318,6 +329,7 @@ impl Storage {
318329 {
319330 match self {
320331 Storage :: S3 ( _) => self . fetch_batch_generic ( keys, options, fetch_fn) . await ,
332+ Storage :: Object ( _) => self . fetch_batch_generic ( keys, options, fetch_fn) . await ,
321333 Storage :: Local ( _) => self . fetch_batch_generic ( keys, options, fetch_fn) . await ,
322334 Storage :: AdmissionControlledS3 ( admission_controlled_storage) => {
323335 admission_controlled_storage
@@ -334,6 +346,10 @@ impl Storage {
334346 ) -> Result < ( Arc < Vec < u8 > > , Option < ETag > ) , StorageError > {
335347 match self {
336348 Storage :: S3 ( s3) => s3. get_with_e_tag ( key) . await ,
349+ Storage :: Object ( obj) => {
350+ let ( bytes, etag) = obj. get ( key, options) . await ?;
351+ Ok ( ( Vec :: from ( bytes) . into ( ) , Some ( etag) ) )
352+ }
337353 Storage :: Local ( local) => local. get_with_e_tag ( key) . await ,
338354 Storage :: AdmissionControlledS3 ( admission_controlled_storage) => {
339355 admission_controlled_storage
@@ -350,6 +366,7 @@ impl Storage {
350366 pub async fn confirm_same ( & self , key : & str , e_tag : & ETag ) -> Result < bool , StorageError > {
351367 match self {
352368 Storage :: S3 ( s3) => s3. confirm_same ( key, e_tag) . await ,
369+ Storage :: Object ( obj) => obj. confirm_same ( key, e_tag) . await ,
353370 Storage :: Local ( local) => local. confirm_same ( key, e_tag) . await ,
354371 Storage :: AdmissionControlledS3 ( as3) => as3. confirm_same ( key, e_tag) . await ,
355372 }
@@ -363,6 +380,7 @@ impl Storage {
363380 ) -> Result < Option < ETag > , StorageError > {
364381 match self {
365382 Storage :: S3 ( s3) => s3. put_file ( key, path, options) . await ,
383+ Storage :: Object ( obj) => obj. put_file ( key, path, options) . await . map ( Some ) ,
366384 Storage :: Local ( local) => local. put_file ( key, path, options) . await ,
367385 Storage :: AdmissionControlledS3 ( as3) => as3. put_file ( key, path, options) . await ,
368386 }
@@ -376,6 +394,7 @@ impl Storage {
376394 ) -> Result < Option < ETag > , StorageError > {
377395 match self {
378396 Storage :: S3 ( s3) => s3. put_bytes ( key, bytes, options) . await ,
397+ Storage :: Object ( obj) => obj. put ( key, bytes. into ( ) , options) . await . map ( Some ) ,
379398 Storage :: Local ( local) => local. put_bytes ( key, & bytes, options) . await ,
380399 Storage :: AdmissionControlledS3 ( as3) => as3. put_bytes ( key, bytes, options) . await ,
381400 }
@@ -384,12 +403,20 @@ impl Storage {
384403 pub async fn delete ( & self , key : & str , options : DeleteOptions ) -> Result < ( ) , StorageError > {
385404 match self {
386405 Storage :: S3 ( s3) => s3. delete ( key, options) . await ,
387- Storage :: Local ( local ) => {
406+ Storage :: Object ( obj ) => {
388407 if options. if_match . is_some ( ) {
389408 return Err ( StorageError :: Message {
390409 message : "if match not supported for object store backend" . to_string ( ) ,
391410 } ) ;
392411 }
412+ obj. delete ( key) . await
413+ }
414+ Storage :: Local ( local) => {
415+ if options. if_match . is_some ( ) {
416+ return Err ( StorageError :: Message {
417+ message : "if match not supported for local backend" . to_string ( ) ,
418+ } ) ;
419+ }
393420 local. delete ( key) . await
394421 }
395422 Storage :: AdmissionControlledS3 ( ac) => ac. delete ( key, options) . await ,
@@ -402,6 +429,7 @@ impl Storage {
402429 ) -> Result < crate :: s3:: DeletedObjects , StorageError > {
403430 match self {
404431 Storage :: S3 ( s3) => s3. delete_many ( keys) . await ,
432+ Storage :: Object ( obj) => obj. delete_many ( keys) . await ,
405433 Storage :: Local ( local) => local. delete_many ( keys) . await ,
406434 Storage :: AdmissionControlledS3 ( ac) => ac. delete_many ( keys) . await ,
407435 }
@@ -410,6 +438,7 @@ impl Storage {
410438 pub async fn rename ( & self , src_key : & str , dst_key : & str ) -> Result < ( ) , StorageError > {
411439 match self {
412440 Storage :: S3 ( s3) => s3. rename ( src_key, dst_key) . await ,
441+ Storage :: Object ( obj) => obj. rename ( src_key, dst_key) . await ,
413442 Storage :: Local ( local) => local. rename ( src_key, dst_key) . await ,
414443 Storage :: AdmissionControlledS3 ( _) => Err ( StorageError :: NotImplemented ) ,
415444 }
@@ -418,6 +447,7 @@ impl Storage {
418447 pub async fn copy ( & self , src_key : & str , dst_key : & str ) -> Result < ( ) , StorageError > {
419448 match self {
420449 Storage :: S3 ( s3) => s3. copy ( src_key, dst_key) . await ,
450+ Storage :: Object ( obj) => obj. copy ( src_key, dst_key) . await ,
421451 Storage :: Local ( local) => local. copy ( src_key, dst_key) . await ,
422452 Storage :: AdmissionControlledS3 ( ac) => ac. copy ( src_key, dst_key) . await ,
423453 }
@@ -431,6 +461,7 @@ impl Storage {
431461 match self {
432462 Storage :: Local ( local) => local. list_prefix ( prefix) . await ,
433463 Storage :: S3 ( s3) => s3. list_prefix ( prefix) . await ,
464+ Storage :: Object ( obj) => obj. list_prefix ( prefix) . await ,
434465 Storage :: AdmissionControlledS3 ( acs3) => acs3. list_prefix ( prefix, options) . await ,
435466 }
436467 }
@@ -446,6 +477,9 @@ impl Configurable<StorageConfig> for Storage {
446477 StorageConfig :: S3 ( _) => Ok ( Storage :: S3 (
447478 s3:: S3Storage :: try_from_config ( config, registry) . await ?,
448479 ) ) ,
480+ StorageConfig :: Object ( _) => Ok ( Storage :: Object (
481+ object_storage:: ObjectStorage :: try_from_config ( config, registry) . await ?,
482+ ) ) ,
449483 StorageConfig :: Local ( _) => Ok ( Storage :: Local (
450484 local:: LocalStorage :: try_from_config ( config, registry) . await ?,
451485 ) ) ,
0 commit comments