42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
删除 Qdrant 集合并重新索引
|
|
"""
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
# 添加项目根目录到 Python 路径
|
|
project_root = os.path.join(os.path.dirname(__file__), "..", "..")
|
|
sys.path.insert(0, os.path.join(project_root, "backend"))
|
|
sys.path.insert(0, project_root)
|
|
|
|
from rag_core import QdrantVectorStore
|
|
from app.model_services import get_embedding_service
|
|
|
|
|
|
async def delete_and_recreate():
|
|
"""删除并重新创建集合"""
|
|
print("="*70)
|
|
print("删除旧集合并重新创建...")
|
|
print("="*70)
|
|
|
|
embeddings = get_embedding_service()
|
|
vs = QdrantVectorStore(collection_name="rag_documents", embeddings=embeddings)
|
|
|
|
# 删除旧集合
|
|
try:
|
|
vs.delete_collection()
|
|
print("✅ 旧集合已删除")
|
|
except Exception as e:
|
|
print(f"⚠️ 删除集合时出错(可能不存在): {e}")
|
|
|
|
# 重新创建
|
|
vs.create_collection()
|
|
print("✅ 新集合已创建")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(delete_and_recreate())
|