Skip to content

Commit afbb362

Browse files
committed
Send empty vector index type on new Weavaite versions
1 parent f26bee0 commit afbb362

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

weaviate/collections/classes/config.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ def __add_to_module_config(
24732473
else:
24742474
return_dict["moduleConfig"][addition_key] = addition_val
24752475

2476-
def _to_dict(self) -> Dict[str, Any]:
2476+
def _to_dict(self, *, emit_default_vector_index_type: bool = True) -> Dict[str, Any]:
24772477
ret_dict: Dict[str, Any] = {}
24782478

24792479
for cls_field in type(self).model_fields:
@@ -2494,14 +2494,23 @@ def _to_dict(self) -> Dict[str, Any]:
24942494
ret_dict["vectorIndexType"] = val.vector_index_type().value
24952495
ret_dict[cls_field] = val._to_dict()
24962496
elif isinstance(val, _VectorConfigCreate):
2497-
ret_dict["vectorConfig"] = {val.name or "default": val._to_dict()}
2497+
ret_dict["vectorConfig"] = {
2498+
val.name or "default": val._to_dict(
2499+
emit_default_vector_index_type=emit_default_vector_index_type
2500+
)
2501+
}
24982502
elif (
24992503
isinstance(val, list)
25002504
and len(val) > 0
25012505
and all(isinstance(item, _NamedVectorConfigCreate) for item in val)
25022506
):
25032507
val = cast(List[_NamedVectorConfigCreate], val)
2504-
ret_dict["vectorConfig"] = {item.name: item._to_dict() for item in val}
2508+
ret_dict["vectorConfig"] = {
2509+
item.name: item._to_dict(
2510+
emit_default_vector_index_type=emit_default_vector_index_type
2511+
)
2512+
for item in val
2513+
}
25052514
elif (
25062515
isinstance(val, list)
25072516
and len(val) > 0
@@ -2514,11 +2523,17 @@ def _to_dict(self) -> Dict[str, Any]:
25142523
raise WeaviateInvalidInputError(
25152524
"Vector config name must be set when specifying multiple vectors"
25162525
)
2517-
ret_dict["vectorConfig"][item.name] = item._to_dict()
2526+
ret_dict["vectorConfig"][item.name] = item._to_dict(
2527+
emit_default_vector_index_type=emit_default_vector_index_type
2528+
)
25182529
else:
25192530
assert isinstance(val, _ConfigCreateModel)
25202531
ret_dict[cls_field] = val._to_dict()
2521-
if self.vectorIndexConfig is None and "vectorConfig" not in ret_dict:
2532+
if (
2533+
self.vectorIndexConfig is None
2534+
and "vectorConfig" not in ret_dict
2535+
and emit_default_vector_index_type
2536+
):
25222537
ret_dict["vectorIndexType"] = VectorIndexType.HNSW
25232538

25242539
ret_dict["class"] = self.name

weaviate/collections/classes/config_named_vectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class _NamedVectorConfigCreate(_ConfigCreateModel):
7777
default=None, alias="vector_index_config"
7878
)
7979

80-
def _to_dict(self) -> Dict[str, Any]:
80+
def _to_dict(self, *, emit_default_vector_index_type: bool = True) -> Dict[str, Any]:
8181
ret_dict: Dict[str, Any] = self.__parse_vectorizer()
8282
if self.vectorIndexConfig is not None:
8383
ret_dict["vectorIndexType"] = self.vectorIndexConfig.vector_index_type().value
8484
ret_dict["vectorIndexConfig"] = self.vectorIndexConfig._to_dict()
85-
else:
85+
elif emit_default_vector_index_type:
8686
ret_dict["vectorIndexType"] = self.vectorIndexType.value
8787
return ret_dict
8888

weaviate/collections/classes/config_vectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ class _VectorConfigCreate(_ConfigCreateModel):
8787
default=None, alias="vector_index_config"
8888
)
8989

90-
def _to_dict(self) -> Dict[str, Any]:
90+
def _to_dict(self, *, emit_default_vector_index_type: bool = True) -> Dict[str, Any]:
9191
ret_dict: Dict[str, Any] = self.__parse_vectorizer()
9292
if self.vectorIndexConfig is not None:
9393
ret_dict["vectorIndexType"] = self.vectorIndexConfig.vector_index_type().value
9494
ret_dict["vectorIndexConfig"] = self.vectorIndexConfig._to_dict()
95-
else:
95+
elif emit_default_vector_index_type:
9696
ret_dict["vectorIndexType"] = self.vectorIndexType.value
9797
return ret_dict
9898

weaviate/collections/collections/executor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,16 @@ def create(
253253
f"Invalid collection config create parameters: {e}"
254254
) from e
255255

256+
# Servers >= 1.37.4 apply DEFAULT_VECTOR_INDEX_TYPE to named-vector
257+
# configs that omit `vectorIndexType`; older servers reject the empty
258+
# field, so for them we keep emitting the client-side HNSW default.
259+
emit_default_vector_index_type = not self._connection._weaviate_version.is_at_least(
260+
1, 37, 4
261+
)
256262
return self.__create(
257-
config=config._to_dict(),
263+
config=config._to_dict(
264+
emit_default_vector_index_type=emit_default_vector_index_type,
265+
),
258266
data_model_properties=data_model_properties,
259267
data_model_references=data_model_references,
260268
skip_argument_validation=skip_argument_validation,

0 commit comments

Comments
 (0)