diff --git a/lightrag/kg/milvus_impl.py b/lightrag/kg/milvus_impl.py index eecf679a..2226784f 100644 --- a/lightrag/kg/milvus_impl.py +++ b/lightrag/kg/milvus_impl.py @@ -546,12 +546,12 @@ class MilvusVectorDBStorage(BaseVectorStorage): if not self._client.has_collection(self.namespace): logger.error(f"Collection {self.namespace} does not exist") raise ValueError(f"Collection {self.namespace} does not exist") - + # Load the collection if it's not already loaded # In Milvus, collections need to be loaded before they can be searched self._client.load_collection(self.namespace) logger.debug(f"Collection {self.namespace} loaded successfully") - + except Exception as e: logger.error(f"Failed to load collection {self.namespace}: {e}") raise @@ -637,10 +637,10 @@ class MilvusVectorDBStorage(BaseVectorStorage): collection_name=self.namespace, schema=schema ) self._create_indexes_after_collection() - + # Load the newly created collection self._ensure_collection_loaded() - + logger.info(f"Successfully force-created collection {self.namespace}") except Exception as create_error: @@ -731,7 +731,7 @@ class MilvusVectorDBStorage(BaseVectorStorage): ) -> list[dict[str, Any]]: # Ensure collection is loaded before querying self._ensure_collection_loaded() - + embedding = await self.embedding_func( [query], _priority=5 ) # higher priority for query @@ -798,7 +798,7 @@ class MilvusVectorDBStorage(BaseVectorStorage): try: # Ensure collection is loaded before querying self._ensure_collection_loaded() - + # Search for relations where entity is either source or target expr = f'src_id == "{entity_name}" or tgt_id == "{entity_name}"' @@ -839,7 +839,7 @@ class MilvusVectorDBStorage(BaseVectorStorage): try: # Ensure collection is loaded before deleting self._ensure_collection_loaded() - + # Delete vectors by IDs result = self._client.delete(collection_name=self.namespace, pks=ids) @@ -865,7 +865,7 @@ class MilvusVectorDBStorage(BaseVectorStorage): try: # Ensure collection is loaded before querying self._ensure_collection_loaded() - + # Include all meta_fields (created_at is now always included) plus id output_fields = list(self.meta_fields) + ["id"] @@ -899,7 +899,7 @@ class MilvusVectorDBStorage(BaseVectorStorage): try: # Ensure collection is loaded before querying self._ensure_collection_loaded() - + # Include all meta_fields (created_at is now always included) plus id output_fields = list(self.meta_fields) + ["id"]