This commit is contained in:
2025-09-07 08:04:43 +08:00
parent adb4416ca2
commit ee76c69ac8
2 changed files with 32 additions and 16 deletions

View File

@@ -1,7 +1,16 @@
import json
import logging
from VikingDBMemoryService import VikingDBMemoryService, MEMORY_COLLECTION_NAME
from Config.Config import VOLC_ACCESSKEY, VOLC_SECRETKEY
# 控制日志输出
logger = logging.getLogger('CollectionMemory')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)
def drop_existing_collection(collection_name):
# 初始化记忆库服务
memory_service = VikingDBMemoryService(
@@ -13,23 +22,23 @@ def drop_existing_collection(collection_name):
try:
# 检查集合是否存在
print(f"正在检查集合 '{collection_name}'...")
logger.info(f"正在检查集合 '{collection_name}'...")
memory_service.get_collection(collection_name)
print(f"集合 '{collection_name}' 已存在,准备删除...")
logger.info(f"集合 '{collection_name}' 已存在,准备删除...")
# 删除集合
response = memory_service.drop_collection(collection_name)
print(f"删除响应: {json.dumps(response, ensure_ascii=False, indent=2)}")
print(f"集合 '{collection_name}' 删除成功")
logger.info(f"删除响应: {json.dumps(response, ensure_ascii=False, indent=2)}")
logger.info(f"集合 '{collection_name}' 删除成功")
return True
except Exception as e:
error_msg = str(e)
if "collection not exist" in error_msg:
print(f"集合 '{collection_name}' 不存在,无需删除")
logger.info(f"集合 '{collection_name}' 不存在,无需删除")
return False
else:
print(f"操作失败: {error_msg}")
logger.error(f"操作失败: {error_msg}")
raise
if __name__ == "__main__":