Permanently delete a knowledge base entry, including:
The uploaded file and metadata
All generated vector embeddings
Query history and access statistics
Category associations
This operation is irreversible. The original file, all vectors, and associated metadata will be permanently deleted. Make sure to download the file first if you need to preserve it.
async function deleteKnowledgeBase(id) { const response = await fetch( `http://localhost:8080/api/knowledgebase/${id}`, { method: 'DELETE' } ); const result = await response.json(); if (result.code === 200) { console.log('Knowledge base deleted successfully'); } else { console.error('Delete failed:', result.message); } return result;}// Usageawait deleteKnowledgeBase(1);
async function deleteWithConfirmation(id, name) { const confirmed = window.confirm( `Are you sure you want to delete "${name}"?\n\n` + 'This will permanently remove the file and all vectors. ' + 'This action cannot be undone.' ); if (!confirmed) { return { cancelled: true }; } const response = await fetch( `http://localhost:8080/api/knowledgebase/${id}`, { method: 'DELETE' } ); return await response.json();}// Usageconst result = await deleteWithConfirmation(1, 'Technical Documentation');if (!result.cancelled && result.code === 200) { alert('Knowledge base deleted successfully');}
import requestsdef delete_knowledge_base(kb_id): """Delete a knowledge base entry.""" response = requests.delete( f'http://localhost:8080/api/knowledgebase/{kb_id}' ) result = response.json() if result['code'] == 200: print(f"Knowledge base {kb_id} deleted successfully") else: print(f"Delete failed: {result['message']}") return result# Usagedelete_knowledge_base(1)
import requestsimport osdef delete_with_backup(kb_id, backup_dir='backups'): """Delete knowledge base after backing up the file.""" # First, get metadata info_response = requests.get( f'http://localhost:8080/api/knowledgebase/{kb_id}' ) if info_response.status_code != 200: print("Knowledge base not found") return info = info_response.json()['data'] filename = info['originalFilename'] # Download and backup os.makedirs(backup_dir, exist_ok=True) backup_path = os.path.join(backup_dir, f"{kb_id}-{filename}") download_response = requests.get( f'http://localhost:8080/api/knowledgebase/{kb_id}/download', stream=True ) with open(backup_path, 'wb') as f: for chunk in download_response.iter_content(chunk_size=8192): f.write(chunk) print(f"Backed up to: {backup_path}") # Now delete delete_response = requests.delete( f'http://localhost:8080/api/knowledgebase/{kb_id}' ) result = delete_response.json() if result['code'] == 200: print(f"Knowledge base {kb_id} deleted successfully") else: print(f"Delete failed: {result['message']}") return result# Usagedelete_with_backup(1)
import requestsdef delete_category(category_name, confirm=True): """Delete all knowledge bases in a specific category.""" # Get all knowledge bases in category response = requests.get( f'http://localhost:8080/api/knowledgebase/category/{category_name}' ) kb_list = response.json()['data'] if not kb_list: print(f"No knowledge bases found in category '{category_name}'") return print(f"Found {len(kb_list)} knowledge bases in '{category_name}':") for kb in kb_list: print(f" - {kb['name']} (ID: {kb['id']})") if confirm: confirmation = input(f"\nDelete all {len(kb_list)} items? [yes/no]: ") if confirmation.lower() != 'yes': print("Cancelled") return # Delete each one deleted_count = 0 for kb in kb_list: delete_response = requests.delete( f'http://localhost:8080/api/knowledgebase/{kb["id"]}' ) if delete_response.json()['code'] == 200: print(f"✓ Deleted: {kb['name']}") deleted_count += 1 else: print(f"✗ Failed: {kb['name']}") print(f"\nDeleted {deleted_count}/{len(kb_list)} knowledge bases")# Usagedelete_category('Old Documentation')