66 UpdateMetadata ,
77 EmbeddingFunction ,
88)
9+ from chromadb .base_types import CollectionSchema , ValueType
910from chromadb .utils .embedding_functions import (
1011 known_embedding_functions ,
1112 register_embedding_function ,
@@ -41,6 +42,7 @@ class CollectionConfiguration(TypedDict, total=True):
4142 hnsw : Optional [HNSWConfiguration ]
4243 spann : Optional [SpannConfiguration ]
4344 embedding_function : Optional [EmbeddingFunction ] # type: ignore
45+ schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]]
4446
4547
4648def load_collection_configuration_from_json_str (
@@ -106,6 +108,7 @@ def load_collection_configuration_from_json(
106108 hnsw = hnsw_config ,
107109 spann = spann_config ,
108110 embedding_function = ef , # type: ignore
111+ schema = config_json_map .get ("schema" ),
109112 )
110113
111114
@@ -118,6 +121,7 @@ def collection_configuration_to_json(config: CollectionConfiguration) -> Dict[st
118121 hnsw_config = config .get ("hnsw" )
119122 spann_config = config .get ("spann" )
120123 ef = config .get ("embedding_function" )
124+ schema = config .get ("schema" )
121125 else :
122126 try :
123127 hnsw_config = config .get_parameter ("hnsw" ).value
@@ -172,6 +176,7 @@ def collection_configuration_to_json(config: CollectionConfiguration) -> Dict[st
172176 "hnsw" : hnsw_config ,
173177 "spann" : spann_config ,
174178 "embedding_function" : ef_config ,
179+ "schema" : schema ,
175180 }
176181
177182
@@ -252,6 +257,7 @@ class CreateCollectionConfiguration(TypedDict, total=False):
252257 hnsw : Optional [CreateHNSWConfiguration ]
253258 spann : Optional [CreateSpannConfiguration ]
254259 embedding_function : Optional [EmbeddingFunction ] # type: ignore
260+ schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]]
255261
256262
257263def create_collection_configuration_from_legacy_collection_metadata (
@@ -379,6 +385,7 @@ def create_collection_configuration_to_json(
379385 "hnsw" : hnsw_config ,
380386 "spann" : spann_config ,
381387 "embedding_function" : ef_config ,
388+ "schema" : config .get ("schema" ),
382389 }
383390
384391
@@ -450,6 +457,7 @@ class UpdateCollectionConfiguration(TypedDict, total=False):
450457 hnsw : Optional [UpdateHNSWConfiguration ]
451458 spann : Optional [UpdateSpannConfiguration ]
452459 embedding_function : Optional [EmbeddingFunction ] # type: ignore
460+ schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]]
453461
454462
455463def update_collection_configuration_from_legacy_collection_metadata (
@@ -504,8 +512,14 @@ def update_collection_configuration_to_json(
504512 """Convert an UpdateCollectionConfiguration to a JSON-serializable dict"""
505513 hnsw_config = config .get ("hnsw" )
506514 spann_config = config .get ("spann" )
515+ schema = config .get ("schema" )
507516 ef = config .get ("embedding_function" )
508- if hnsw_config is None and spann_config is None and ef is None :
517+ if (
518+ hnsw_config is None
519+ and spann_config is None
520+ and ef is None
521+ and schema is None
522+ ):
509523 return {}
510524
511525 if hnsw_config is not None :
@@ -539,6 +553,7 @@ def update_collection_configuration_to_json(
539553 "hnsw" : hnsw_config ,
540554 "spann" : spann_config ,
541555 "embedding_function" : ef_config ,
556+ "schema" : schema ,
542557 }
543558
544559
@@ -687,13 +702,40 @@ def overwrite_collection_configuration(
687702 else :
688703 updated_embedding_function = update_ef
689704
705+
706+ existing_schema = existing_config .get ("schema" )
707+ new_diff_schema = update_config .get ("schema" )
708+ updated_schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]] = None
709+ if existing_schema is not None :
710+ if new_diff_schema is not None :
711+ updated_schema = overwrite_schema (existing_schema , new_diff_schema )
712+ else :
713+ updated_schema = existing_schema
714+ else :
715+ updated_schema = new_diff_schema
716+
690717 return CollectionConfiguration (
691718 hnsw = updated_hnsw_config ,
692719 spann = updated_spann_config ,
693720 embedding_function = updated_embedding_function ,
721+ schema = updated_schema ,
694722 )
695723
696724
725+ def overwrite_schema (
726+ existing_schema : Dict [str , Dict [ValueType , CollectionSchema ]],
727+ new_diff_schema : Dict [str , Dict [ValueType , CollectionSchema ]],
728+ ) -> Dict [str , Dict [ValueType , CollectionSchema ]]:
729+ """Overwrite a schema with a new configuration"""
730+ for new_key , new_value in new_diff_schema .items ():
731+ if new_key in existing_schema :
732+ for value_type , new_schema in new_value .items ():
733+ existing_schema [new_key ][value_type ] = new_schema
734+ else :
735+ existing_schema [new_key ] = new_value
736+ return existing_schema
737+
738+
697739def validate_embedding_function_conflict_on_create (
698740 embedding_function : Optional [EmbeddingFunction ], # type: ignore
699741 configuration_ef : Optional [EmbeddingFunction ], # type: ignore
0 commit comments