Skip to content

Commit aa7d7b3

Browse files
committed
Make moduleconfig optional for custom reranker/generative
1 parent fc85585 commit aa7d7b3

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

weaviate/collections/classes/config.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,11 @@ class _GenerativeAnyscale(_GenerativeConfigCreate):
378378

379379

380380
class _GenerativeCustom(_GenerativeConfigCreate):
381-
module_config: Dict[str, Any]
381+
module_config: Optional[Dict[str, Any]]
382382

383383
def _to_dict(self) -> Dict[str, Any]:
384+
if self.module_config is None:
385+
return {}
384386
return self.module_config
385387

386388

@@ -495,9 +497,11 @@ class _RerankerCohereConfig(_RerankerConfigCreate):
495497

496498

497499
class _RerankerCustomConfig(_RerankerConfigCreate):
498-
module_config: Dict[str, Any]
500+
module_config: Optional[Dict[str, Any]]
499501

500502
def _to_dict(self) -> Dict[str, Any]:
503+
if self.module_config is None:
504+
return {}
501505
return self.module_config
502506

503507

@@ -534,7 +538,7 @@ def anyscale(
534538
@staticmethod
535539
def custom(
536540
module_name: str,
537-
module_config: Dict[str, Any],
541+
module_config: Optional[Dict[str, Any]] = None,
538542
) -> _GenerativeConfigCreate:
539543
"""Create a `_GenerativeCustom` object for use when generating using a custom module.
540544
@@ -799,7 +803,9 @@ def transformers() -> _RerankerConfigCreate:
799803
return _RerankerTransformersConfig(reranker=Rerankers.TRANSFORMERS)
800804

801805
@staticmethod
802-
def custom(module_name: str, module_config: Dict[str, Any]) -> _RerankerConfigCreate:
806+
def custom(
807+
module_name: str, module_config: Optional[Dict[str, Any]] = None
808+
) -> _RerankerConfigCreate:
803809
"""Create a `_RerankerCustomConfig` object for use when reranking using a custom module.
804810
805811
Arguments:
@@ -914,9 +920,9 @@ class _CollectionConfigUpdate(_ConfigUpdateModel):
914920
vectorIndexConfig: Optional[_VectorIndexConfigUpdate] = Field(
915921
default=None, alias="vector_index_config"
916922
)
917-
vectorizerConfig: Optional[
918-
Union[_VectorIndexConfigUpdate, List[_NamedVectorConfigUpdate]]
919-
] = Field(default=None, alias="vectorizer_config")
923+
vectorizerConfig: Optional[Union[_VectorIndexConfigUpdate, List[_NamedVectorConfigUpdate]]] = (
924+
Field(default=None, alias="vectorizer_config")
925+
)
920926
multiTenancyConfig: Optional[_MultiTenancyConfigUpdate] = Field(
921927
default=None, alias="multi_tenancy_config"
922928
)
@@ -963,10 +969,10 @@ def merge_with_existing(self, schema: Dict[str, Any]) -> Dict[str, Any]:
963969
raise WeaviateInvalidInputError(
964970
f"Cannot update vector index config with name {vc.name} to change its quantizer"
965971
)
966-
schema["vectorConfig"][vc.name][
967-
"vectorIndexConfig"
968-
] = vc.vectorIndexConfig.merge_with_existing(
969-
schema["vectorConfig"][vc.name]["vectorIndexConfig"]
972+
schema["vectorConfig"][vc.name]["vectorIndexConfig"] = (
973+
vc.vectorIndexConfig.merge_with_existing(
974+
schema["vectorConfig"][vc.name]["vectorIndexConfig"]
975+
)
970976
)
971977
schema["vectorConfig"][vc.name][
972978
"vectorIndexType"
@@ -1536,9 +1542,9 @@ class _CollectionConfigCreate(_ConfigCreateModel):
15361542
vectorIndexConfig: Optional[_VectorIndexConfigCreate] = Field(
15371543
default=None, alias="vector_index_config"
15381544
)
1539-
vectorizerConfig: Optional[
1540-
Union[_VectorizerConfigCreate, List[_NamedVectorConfigCreate]]
1541-
] = Field(default=_Vectorizer.none(), alias="vectorizer_config")
1545+
vectorizerConfig: Optional[Union[_VectorizerConfigCreate, List[_NamedVectorConfigCreate]]] = (
1546+
Field(default=_Vectorizer.none(), alias="vectorizer_config")
1547+
)
15421548
generativeSearch: Optional[_GenerativeConfigCreate] = Field(
15431549
default=None, alias="generative_config"
15441550
)

0 commit comments

Comments
 (0)