mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-29 14:57:35 +00:00
Change Milvus truncate method
Changed truncate method for milvus vector store. Now keeps the collection and only delete the data.
This commit is contained in:
parent
0ecfeabd8e
commit
a666ae2709
@ -727,15 +727,30 @@ class MilvusStore(VectorStoreBase):
|
|||||||
metadata_filter_expr = metadata_filters[0]
|
metadata_filter_expr = metadata_filters[0]
|
||||||
return metadata_filter_expr
|
return metadata_filter_expr
|
||||||
|
|
||||||
def truncate(self):
|
def truncate(self):
|
||||||
"""Truncate milvus collection."""
|
"""检测pymilvus安装"""
|
||||||
logger.info(f"begin truncate milvus collection:{self.collection_name}")
|
try:
|
||||||
from pymilvus import utility
|
from pymilvus import Collection, utility
|
||||||
|
except ImportError:
|
||||||
|
raise ValueError(
|
||||||
|
"Could not import pymilvus python package. "
|
||||||
|
"Please install it with `pip install pymilvus`."
|
||||||
|
)
|
||||||
|
"""安全清空 Milvus summary collection 中所有数据,但不删除 collection 本身"""
|
||||||
|
logger.info(f"Begin truncate Milvus collection: {self.collection_name}")
|
||||||
|
# 先判断 collection 是否存在
|
||||||
if utility.has_collection(self.collection_name):
|
if utility.has_collection(self.collection_name):
|
||||||
utility.drop_collection(self.collection_name)
|
collection = Collection(self.collection_name)
|
||||||
|
# Load collection 必须调用,才能执行 delete
|
||||||
|
collection.load()
|
||||||
|
# 通过pk_id删除所有数据
|
||||||
|
collection.delete("pk_id >= 0")
|
||||||
|
# flush 确保数据删除被提交
|
||||||
|
collection.flush()
|
||||||
|
logger.info(f"Truncate Milvus collection {self.collection_name} success")
|
||||||
|
else:
|
||||||
|
logger.warning(f"Collection {self.collection_name} not found, skip truncate.")
|
||||||
|
|
||||||
logger.info(f"truncate milvus collection {self.collection_name} success")
|
|
||||||
|
|
||||||
def full_text_search(
|
def full_text_search(
|
||||||
self, text: str, topk: int = 10, filters: Optional[MetadataFilters] = None
|
self, text: str, topk: int = 10, filters: Optional[MetadataFilters] = None
|
||||||
|
Loading…
Reference in New Issue
Block a user