20 lines
825 B
Python
20 lines
825 B
Python
"""Milvus knowledge-document deletion helpers."""
|
|
from __future__ import annotations
|
|
|
|
from rag.milvus_collections import KNOWLEDGE_COLLECTIONS
|
|
from config.database.milvus import client as configured_milvus_client
|
|
|
|
|
|
def _escape_filter_value(value: str) -> str:
|
|
return value.replace("\\", "\\\\").replace('"', '\\"')
|
|
|
|
|
|
async def delete_document_vectors(doc_id: str, *, milvus_client=None) -> None:
|
|
"""Delete every knowledge chunk with ``doc_id`` from project collections."""
|
|
if not doc_id or not doc_id.strip():
|
|
raise ValueError("doc_id must not be empty")
|
|
client = milvus_client or configured_milvus_client()
|
|
expression = f'doc_id == "{_escape_filter_value(doc_id)}"'
|
|
for collection_name in KNOWLEDGE_COLLECTIONS:
|
|
await client.delete(collection_name=collection_name, filter=expression)
|