From 0fa9a2eee3484c599153b948bf04d979e81c193f Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 22 Oct 2025 23:37:49 +0800 Subject: [PATCH] Fix dimension type comparison in Milvus vector field validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Convert dimensions to int for comparison • Handle string vs int type mismatches --- lightrag/kg/milvus_impl.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lightrag/kg/milvus_impl.py b/lightrag/kg/milvus_impl.py index cbe2cf82..edb7983c 100644 --- a/lightrag/kg/milvus_impl.py +++ b/lightrag/kg/milvus_impl.py @@ -462,14 +462,37 @@ class MilvusVectorDBStorage(BaseVectorStorage): if type_name in ["FloatVector", "FLOAT_VECTOR"]: existing_dimension = field.get("params", {}).get("dim") - if existing_dimension != current_dimension: + # Convert both to int for comparison to handle type mismatches + # (Milvus API may return string "1024" vs int 1024) + try: + existing_dim_int = ( + int(existing_dimension) + if existing_dimension is not None + else None + ) + current_dim_int = ( + int(current_dimension) + if current_dimension is not None + else None + ) + except (TypeError, ValueError) as e: + logger.error( + f"[{self.workspace}] Failed to parse dimensions: existing={existing_dimension} (type={type(existing_dimension)}), " + f"current={current_dimension} (type={type(current_dimension)}), error={e}" + ) + raise ValueError( + f"Invalid dimension values for collection '{self.final_namespace}': " + f"existing={existing_dimension}, current={current_dimension}" + ) from e + + if existing_dim_int != current_dim_int: raise ValueError( f"Vector dimension mismatch for collection '{self.final_namespace}': " - f"existing={existing_dimension}, current={current_dimension}" + f"existing={existing_dim_int}, current={current_dim_int}" ) logger.debug( - f"[{self.workspace}] Vector dimension check passed: {current_dimension}" + f"[{self.workspace}] Vector dimension check passed: {current_dim_int}" ) return