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 (
@@ -107,6 +109,7 @@ def load_collection_configuration_from_json(
107109 hnsw = hnsw_config ,
108110 spann = spann_config ,
109111 embedding_function = ef , # type: ignore
112+ schema = config_json_map .get ("schema" ),
110113 )
111114
112115
@@ -119,6 +122,7 @@ def collection_configuration_to_json(config: CollectionConfiguration) -> Dict[st
119122 hnsw_config = config .get ("hnsw" )
120123 spann_config = config .get ("spann" )
121124 ef = config .get ("embedding_function" )
125+ schema = config .get ("schema" )
122126 else :
123127 try :
124128 hnsw_config = config .get_parameter ("hnsw" ).value
@@ -178,6 +182,7 @@ def collection_configuration_to_json(config: CollectionConfiguration) -> Dict[st
178182 "hnsw" : hnsw_config ,
179183 "spann" : spann_config ,
180184 "embedding_function" : ef_config ,
185+ "schema" : schema ,
181186 }
182187
183188
@@ -258,6 +263,7 @@ class CreateCollectionConfiguration(TypedDict, total=False):
258263 hnsw : Optional [CreateHNSWConfiguration ]
259264 spann : Optional [CreateSpannConfiguration ]
260265 embedding_function : Optional [EmbeddingFunction ] # type: ignore
266+ schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]]
261267
262268
263269def load_collection_configuration_from_create_collection_configuration (
@@ -402,6 +408,7 @@ def create_collection_configuration_to_json(
402408 "hnsw" : hnsw_config ,
403409 "spann" : spann_config ,
404410 "embedding_function" : ef_config ,
411+ "schema" : config .get ("schema" ),
405412 }
406413
407414
@@ -473,6 +480,7 @@ class UpdateCollectionConfiguration(TypedDict, total=False):
473480 hnsw : Optional [UpdateHNSWConfiguration ]
474481 spann : Optional [UpdateSpannConfiguration ]
475482 embedding_function : Optional [EmbeddingFunction ] # type: ignore
483+ schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]]
476484
477485
478486def update_collection_configuration_from_legacy_collection_metadata (
@@ -527,8 +535,14 @@ def update_collection_configuration_to_json(
527535 """Convert an UpdateCollectionConfiguration to a JSON-serializable dict"""
528536 hnsw_config = config .get ("hnsw" )
529537 spann_config = config .get ("spann" )
538+ schema = config .get ("schema" )
530539 ef = config .get ("embedding_function" )
531- if hnsw_config is None and spann_config is None and ef is None :
540+ if (
541+ hnsw_config is None
542+ and spann_config is None
543+ and ef is None
544+ and schema is None
545+ ):
532546 return {}
533547
534548 if hnsw_config is not None :
@@ -562,6 +576,7 @@ def update_collection_configuration_to_json(
562576 "hnsw" : hnsw_config ,
563577 "spann" : spann_config ,
564578 "embedding_function" : ef_config ,
579+ "schema" : schema ,
565580 }
566581
567582
@@ -710,13 +725,40 @@ def overwrite_collection_configuration(
710725 else :
711726 updated_embedding_function = update_ef
712727
728+
729+ existing_schema = existing_config .get ("schema" )
730+ new_diff_schema = update_config .get ("schema" )
731+ updated_schema : Optional [Dict [str , Dict [ValueType , CollectionSchema ]]] = None
732+ if existing_schema is not None :
733+ if new_diff_schema is not None :
734+ updated_schema = overwrite_schema (existing_schema , new_diff_schema )
735+ else :
736+ updated_schema = existing_schema
737+ else :
738+ updated_schema = new_diff_schema
739+
713740 return CollectionConfiguration (
714741 hnsw = updated_hnsw_config ,
715742 spann = updated_spann_config ,
716743 embedding_function = updated_embedding_function ,
744+ schema = updated_schema ,
717745 )
718746
719747
748+ def overwrite_schema (
749+ existing_schema : Dict [str , Dict [ValueType , CollectionSchema ]],
750+ new_diff_schema : Dict [str , Dict [ValueType , CollectionSchema ]],
751+ ) -> Dict [str , Dict [ValueType , CollectionSchema ]]:
752+ """Overwrite a schema with a new configuration"""
753+ for new_key , new_value in new_diff_schema .items ():
754+ if new_key in existing_schema :
755+ for value_type , new_schema in new_value .items ():
756+ existing_schema [new_key ][value_type ] = new_schema
757+ else :
758+ existing_schema [new_key ] = new_value
759+ return existing_schema
760+
761+
720762def validate_embedding_function_conflict_on_create (
721763 embedding_function : Optional [EmbeddingFunction ], # type: ignore
722764 configuration_ef : Optional [EmbeddingFunction ], # type: ignore
0 commit comments