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