@@ -13,8 +13,8 @@ use chroma_types::{
1313 DeleteDatabaseError , DeleteDatabaseResponse , GetCollectionWithSegmentsError ,
1414 GetCollectionsError , GetDatabaseError , GetSegmentsError , GetTenantError , GetTenantResponse ,
1515 InternalCollectionConfiguration , InternalUpdateCollectionConfiguration , ListDatabasesError ,
16- Metadata , MetadataValue , ResetError , ResetResponse , Segment , SegmentScope , SegmentType ,
17- SegmentUuid , UpdateCollectionError , UpdateTenantError , UpdateTenantResponse ,
16+ Metadata , MetadataValue , ResetError , ResetResponse , Schema , SchemaError , Segment , SegmentScope ,
17+ SegmentType , SegmentUuid , UpdateCollectionError , UpdateTenantError , UpdateTenantResponse ,
1818} ;
1919use futures:: TryStreamExt ;
2020use sea_query_binder:: SqlxBinder ;
@@ -251,6 +251,7 @@ impl SqliteSysDb {
251251 name : String ,
252252 segments : Vec < Segment > ,
253253 configuration : InternalCollectionConfiguration ,
254+ schema : Option < Schema > ,
254255 metadata : Option < Metadata > ,
255256 dimension : Option < i32 > ,
256257 get_or_create : bool ,
@@ -307,13 +308,18 @@ impl SqliteSysDb {
307308 sqlx:: query (
308309 r#"
309310 INSERT INTO collections
310- (id, name, config_json_str, dimension, database_id)
311- VALUES ($1, $2, $3, $4, $5)
311+ (id, name, config_json_str, schema_str, dimension, database_id)
312+ VALUES ($1, $2, $3, $4, $5, $6 )
312313 "# ,
313314 )
314315 . bind ( collection_id. to_string ( ) )
315316 . bind ( & name)
316317 . bind ( serde_json:: to_string ( & configuration) . map_err ( CreateCollectionError :: Configuration ) ?)
318+ . bind ( serde_json:: to_string ( & schema) . map_err ( |e| {
319+ CreateCollectionError :: Schema ( SchemaError :: InvalidSchema {
320+ reason : e. to_string ( ) ,
321+ } )
322+ } ) ?)
317323 . bind ( dimension)
318324 . bind ( database_id)
319325 . execute ( & mut * tx)
@@ -347,7 +353,7 @@ impl SqliteSysDb {
347353 database,
348354 config : configuration,
349355 metadata,
350- schema : None ,
356+ schema,
351357 dimension,
352358 log_position : 0 ,
353359 total_records_post_compaction : 0 ,
@@ -685,6 +691,7 @@ impl SqliteSysDb {
685691 . column ( ( table:: Collections :: Table , table:: Collections :: ConfigJsonStr ) )
686692 . column ( ( table:: Collections :: Table , table:: Collections :: Dimension ) )
687693 . column ( ( table:: Collections :: Table , table:: Collections :: DatabaseId ) )
694+ . column ( ( table:: Collections :: Table , table:: Collections :: SchemaStr ) )
688695 . inner_join (
689696 table:: Databases :: Table ,
690697 sea_query:: Expr :: col ( ( table:: Databases :: Table , table:: Databases :: Id ) )
@@ -739,6 +746,7 @@ impl SqliteSysDb {
739746 . column ( ( table:: Databases :: Table , table:: Databases :: TenantId ) )
740747 . column ( ( table:: Databases :: Table , table:: Databases :: Name ) )
741748 . column ( ( table:: Collections :: Table , table:: Collections :: DatabaseId ) )
749+ . column ( ( table:: Collections :: Table , table:: Collections :: SchemaStr ) )
742750 . columns ( [
743751 table:: CollectionMetadata :: Key ,
744752 table:: CollectionMetadata :: StrValue ,
@@ -788,6 +796,17 @@ impl SqliteSysDb {
788796 }
789797 None => InternalCollectionConfiguration :: default_hnsw ( ) ,
790798 } ;
799+ let schema = match first_row. get :: < Option < & str > , _ > ( 7 ) {
800+ Some ( json_str) => {
801+ match serde_json:: from_str :: < Schema > ( json_str)
802+ . map_err ( GetCollectionsError :: Schema )
803+ {
804+ Ok ( schema) => Some ( schema) ,
805+ Err ( e) => return Some ( Err ( e) ) ,
806+ }
807+ }
808+ None => None ,
809+ } ;
791810 let database_id = match DatabaseUuid :: from_str ( first_row. get ( 6 ) ) {
792811 Ok ( db_id) => db_id,
793812 Err ( _) => return Some ( Err ( GetCollectionsError :: DatabaseId ) ) ,
@@ -796,7 +815,7 @@ impl SqliteSysDb {
796815 Some ( Ok ( Collection {
797816 collection_id,
798817 config : configuration,
799- schema : None ,
818+ schema,
800819 metadata,
801820 total_records_post_compaction : 0 ,
802821 version : 0 ,
@@ -1112,7 +1131,7 @@ mod tests {
11121131 use super :: * ;
11131132 use chroma_sqlite:: db:: test_utils:: get_new_sqlite_db;
11141133 use chroma_types:: {
1115- InternalUpdateCollectionConfiguration , SegmentScope , SegmentType , SegmentUuid ,
1134+ InternalUpdateCollectionConfiguration , KnnIndex , SegmentScope , SegmentType , SegmentUuid ,
11161135 UpdateHnswConfiguration , UpdateMetadata , UpdateMetadataValue ,
11171136 UpdateVectorIndexConfiguration , VectorIndexConfiguration ,
11181137 } ;
@@ -1295,6 +1314,7 @@ mod tests {
12951314 "test_collection" . to_string ( ) ,
12961315 segments. clone ( ) ,
12971316 InternalCollectionConfiguration :: default_hnsw ( ) ,
1317+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
12981318 Some ( collection_metadata. clone ( ) ) ,
12991319 None ,
13001320 false ,
@@ -1338,6 +1358,7 @@ mod tests {
13381358 "test_collection" . to_string ( ) ,
13391359 segments. clone ( ) ,
13401360 InternalCollectionConfiguration :: default_hnsw ( ) ,
1361+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
13411362 None ,
13421363 None ,
13431364 false ,
@@ -1355,6 +1376,7 @@ mod tests {
13551376 "test_collection" . to_string ( ) ,
13561377 segments,
13571378 InternalCollectionConfiguration :: default_hnsw ( ) ,
1379+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
13581380 None ,
13591381 None ,
13601382 false ,
@@ -1385,6 +1407,7 @@ mod tests {
13851407 "test_collection" . to_string ( ) ,
13861408 segments. clone ( ) ,
13871409 InternalCollectionConfiguration :: default_hnsw ( ) ,
1410+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
13881411 None ,
13891412 None ,
13901413 false ,
@@ -1402,6 +1425,7 @@ mod tests {
14021425 "test_collection" . to_string ( ) ,
14031426 vec ! [ ] ,
14041427 InternalCollectionConfiguration :: default_hnsw ( ) ,
1428+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
14051429 None ,
14061430 None ,
14071431 true ,
@@ -1425,6 +1449,7 @@ mod tests {
14251449 "test_collection" . to_string ( ) ,
14261450 vec ! [ ] ,
14271451 InternalCollectionConfiguration :: default_hnsw ( ) ,
1452+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
14281453 None ,
14291454 None ,
14301455 false ,
@@ -1498,6 +1523,7 @@ mod tests {
14981523 "test_collection" . to_string ( ) ,
14991524 vec ! [ ] ,
15001525 InternalCollectionConfiguration :: default_hnsw ( ) ,
1526+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
15011527 None ,
15021528 None ,
15031529 false ,
@@ -1579,6 +1605,7 @@ mod tests {
15791605 "test_collection" . to_string ( ) ,
15801606 segments. clone ( ) ,
15811607 InternalCollectionConfiguration :: default_hnsw ( ) ,
1608+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
15821609 Some ( collection_metadata. clone ( ) ) ,
15831610 None ,
15841611 false ,
@@ -1629,6 +1656,7 @@ mod tests {
16291656 "test_collection" . to_string ( ) ,
16301657 segments. clone ( ) ,
16311658 InternalCollectionConfiguration :: default_hnsw ( ) ,
1659+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
16321660 Some ( collection_metadata. clone ( ) ) ,
16331661 None ,
16341662 false ,
@@ -1659,6 +1687,7 @@ mod tests {
16591687 "test_collection" . to_string ( ) ,
16601688 vec ! [ ] ,
16611689 InternalCollectionConfiguration :: default_hnsw ( ) ,
1690+ Some ( Schema :: new_default ( KnnIndex :: Hnsw ) ) ,
16621691 None ,
16631692 None ,
16641693 false ,
0 commit comments