Files
Mutual_Fund/nl2sql/operations.py
T

24 lines
693 B
Python

"""NL2SQL Milvus 运维操作。"""
from __future__ import annotations
from nl2sql.milvus_collections import NL2SQL_COLLECTION
INVALID_VECTOR_FILTER = "is_valid == false or is_deprecated == true"
async def cleanup_invalid_vectors(milvus_client) -> int:
"""删除无效或已废弃的元数据向量,并返回删除前的数量。"""
rows = await milvus_client.query(
collection_name=NL2SQL_COLLECTION,
filter=INVALID_VECTOR_FILTER,
output_fields=["id"],
)
count = len(rows or [])
if count:
await milvus_client.delete(
collection_name=NL2SQL_COLLECTION,
filter=INVALID_VECTOR_FILTER,
)
return count