Files
dsProject/dsLightRag/Volcengine/T1_DropIndex.py

37 lines
1.3 KiB
Python
Raw Normal View History

2025-09-07 08:00:15 +08:00
import json
2025-09-07 08:02:23 +08:00
from VikingDBMemoryService import VikingDBMemoryService, MEMORY_COLLECTION_NAME
2025-09-07 08:00:15 +08:00
from Config.Config import VOLC_ACCESSKEY, VOLC_SECRETKEY
def drop_existing_collection(collection_name):
# 初始化记忆库服务
memory_service = VikingDBMemoryService(
ak=VOLC_ACCESSKEY,
sk=VOLC_SECRETKEY,
host="api-knowledgebase.mlp.cn-beijing.volces.com",
region="cn-beijing"
)
try:
# 检查集合是否存在
print(f"正在检查集合 '{collection_name}'...")
memory_service.get_collection(collection_name)
print(f"集合 '{collection_name}' 已存在,准备删除...")
# 删除集合
response = memory_service.drop_collection(collection_name)
print(f"删除响应: {json.dumps(response, ensure_ascii=False, indent=2)}")
print(f"集合 '{collection_name}' 删除成功")
return True
except Exception as e:
error_msg = str(e)
if "collection not exist" in error_msg:
print(f"集合 '{collection_name}' 不存在,无需删除")
return False
else:
print(f"操作失败: {error_msg}")
raise
if __name__ == "__main__":
# 可修改为目标集合名称
2025-09-07 08:02:23 +08:00
drop_existing_collection(MEMORY_COLLECTION_NAME)