enh: files data controls

This commit is contained in:
Timothy Jaeryang Baek
2026-01-29 19:50:06 +04:00
parent a10ac774ab
commit 93ed4ae2cd
5 changed files with 443 additions and 4 deletions
+18 -1
View File
@@ -282,7 +282,7 @@ def upload_file_handler(
},
"meta": {
"name": name,
"content_type": file.content_type,
"content_type": file.content_type if isinstance(file.content_type, str) else None,
"size": len(contents),
"data": file_metadata,
},
@@ -827,6 +827,23 @@ async def delete_file_by_id(
or has_access_to_file(id, "write", user, db=db)
):
# Clean up KB associations and embeddings before deleting
knowledges = Knowledges.get_knowledges_by_file_id(id, db=db)
for knowledge in knowledges:
# Remove KB-file relationship
Knowledges.remove_file_from_knowledge_by_id(knowledge.id, id, db=db)
# Clean KB embeddings (same logic as /knowledge/{id}/file/remove)
try:
VECTOR_DB_CLIENT.delete(
collection_name=knowledge.id, filter={"file_id": id}
)
if file.hash:
VECTOR_DB_CLIENT.delete(
collection_name=knowledge.id, filter={"hash": file.hash}
)
except Exception as e:
log.debug(f"KB embedding cleanup for {knowledge.id}: {e}")
result = Files.delete_file_by_id(id, db=db)
if result:
try: