fix: Fix milvus vector_name_exists bug (#2818)

This commit is contained in:
HYP-hu 2025-07-07 22:52:02 +08:00 committed by GitHub
parent 1eea9c8eec
commit cecac56a26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -649,15 +649,17 @@ class MilvusStore(VectorStoreBase):
def vector_name_exists(self): def vector_name_exists(self):
"""Whether vector name exists.""" """Whether vector name exists."""
try: try:
from pymilvus import utility if not self._milvus_client.has_collection(self.collection_name):
except ImportError: logger.info(f"Collection {self.collection_name} does not exist")
raise ValueError( return False
"Could not import pymilvus python package. "
"Please install it with `pip install pymilvus`."
)
"""is vector store name exist.""" stats = self._milvus_client.get_collection_stats(self.collection_name)
return utility.has_collection(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): def delete_vector_name(self, vector_name: str):
"""Delete vector name.""" """Delete vector name."""