From cecac56a26795489eac3edacd8faff04f3676c51 Mon Sep 17 00:00:00 2001 From: HYP-hu <41627818+HYP-hu@users.noreply.github.com> Date: Mon, 7 Jul 2025 22:52:02 +0800 Subject: [PATCH] fix: Fix milvus vector_name_exists bug (#2818) --- .../storage/vector_store/milvus_store.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py b/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py index 690384ecb..0e6df4446 100644 --- a/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py +++ b/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py @@ -649,15 +649,17 @@ class MilvusStore(VectorStoreBase): def vector_name_exists(self): """Whether vector name exists.""" try: - from pymilvus import utility - except ImportError: - raise ValueError( - "Could not import pymilvus python package. " - "Please install it with `pip install pymilvus`." - ) + if not self._milvus_client.has_collection(self.collection_name): + logger.info(f"Collection {self.collection_name} does not exist") + return False - """is vector store name exist.""" - return utility.has_collection(self.collection_name) + stats = self._milvus_client.get_collection_stats(self.collection_name) + row_count = stats.get("row_count", 0) + return row_count > 0 + + except Exception as e: + logger.error(f"vector_name_exists error, {str(e)}") + return False def delete_vector_name(self, vector_name: str): """Delete vector name."""