Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@ def __add_to_module_config(
else:
return_dict["moduleConfig"][addition_key] = addition_val

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

for cls_field in type(self).model_fields:
Expand All @@ -2494,14 +2494,23 @@ def _to_dict(self) -> Dict[str, Any]:
ret_dict["vectorIndexType"] = val.vector_index_type().value
ret_dict[cls_field] = val._to_dict()
elif isinstance(val, _VectorConfigCreate):
ret_dict["vectorConfig"] = {val.name or "default": val._to_dict()}
ret_dict["vectorConfig"] = {
val.name or "default": val._to_dict(
emit_default_vector_index_type=emit_default_vector_index_type
)
}
elif (
isinstance(val, list)
and len(val) > 0
and all(isinstance(item, _NamedVectorConfigCreate) for item in val)
):
val = cast(List[_NamedVectorConfigCreate], val)
ret_dict["vectorConfig"] = {item.name: item._to_dict() for item in val}
ret_dict["vectorConfig"] = {
item.name: item._to_dict(
emit_default_vector_index_type=emit_default_vector_index_type
)
for item in val
}
elif (
isinstance(val, list)
and len(val) > 0
Expand All @@ -2514,11 +2523,17 @@ def _to_dict(self) -> Dict[str, Any]:
raise WeaviateInvalidInputError(
"Vector config name must be set when specifying multiple vectors"
)
ret_dict["vectorConfig"][item.name] = item._to_dict()
ret_dict["vectorConfig"][item.name] = item._to_dict(
emit_default_vector_index_type=emit_default_vector_index_type
)
else:
assert isinstance(val, _ConfigCreateModel)
ret_dict[cls_field] = val._to_dict()
if self.vectorIndexConfig is None and "vectorConfig" not in ret_dict:
if (
self.vectorIndexConfig is None
and "vectorConfig" not in ret_dict
and emit_default_vector_index_type
):
ret_dict["vectorIndexType"] = VectorIndexType.HNSW

ret_dict["class"] = self.name
Expand Down
4 changes: 2 additions & 2 deletions weaviate/collections/classes/config_named_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class _NamedVectorConfigCreate(_ConfigCreateModel):
default=None, alias="vector_index_config"
)

def _to_dict(self) -> Dict[str, Any]:
def _to_dict(self, *, emit_default_vector_index_type: bool = True) -> Dict[str, Any]:
ret_dict: Dict[str, Any] = self.__parse_vectorizer()
if self.vectorIndexConfig is not None:
ret_dict["vectorIndexType"] = self.vectorIndexConfig.vector_index_type().value
ret_dict["vectorIndexConfig"] = self.vectorIndexConfig._to_dict()
else:
elif emit_default_vector_index_type:
ret_dict["vectorIndexType"] = self.vectorIndexType.value
Comment thread
dirkkul marked this conversation as resolved.
return ret_dict

Expand Down
4 changes: 2 additions & 2 deletions weaviate/collections/classes/config_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class _VectorConfigCreate(_ConfigCreateModel):
default=None, alias="vector_index_config"
)

def _to_dict(self) -> Dict[str, Any]:
def _to_dict(self, *, emit_default_vector_index_type: bool = True) -> Dict[str, Any]:
ret_dict: Dict[str, Any] = self.__parse_vectorizer()
if self.vectorIndexConfig is not None:
ret_dict["vectorIndexType"] = self.vectorIndexConfig.vector_index_type().value
ret_dict["vectorIndexConfig"] = self.vectorIndexConfig._to_dict()
else:
elif emit_default_vector_index_type:
ret_dict["vectorIndexType"] = self.vectorIndexType.value
Comment thread
dirkkul marked this conversation as resolved.
return ret_dict

Expand Down
10 changes: 9 additions & 1 deletion weaviate/collections/collections/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,16 @@ def create(
f"Invalid collection config create parameters: {e}"
) from e

# Servers >= 1.37.4 apply DEFAULT_VECTOR_INDEX_TYPE to named-vector
# configs that omit `vectorIndexType`; older servers reject the empty
# field, so for them we keep emitting the client-side HNSW default.
emit_default_vector_index_type = not self._connection._weaviate_version.is_at_least(
1, 37, 4
)
return self.__create(
config=config._to_dict(),
config=config._to_dict(
emit_default_vector_index_type=emit_default_vector_index_type,
),
data_model_properties=data_model_properties,
data_model_references=data_model_references,
skip_argument_validation=skip_argument_validation,
Expand Down
Loading