Manage cognitive datasets for organizing memories and knowledge in the context graph
Datasets provide logical organization for cognitive memories and knowledge. Create datasets with different scopes and permissions to organize information by team, project, or use case.
from kubiya import ControlPlaneClientclient = ControlPlaneClient(api_key="your-api-key")# Delete dataset and all its memoriessuccess = client.datasets.delete_dataset(dataset_id="dataset-abc123def456")if success: print("✅ Dataset deleted successfully")else: print("❌ Failed to delete dataset")
Deleting a dataset permanently removes all memories stored in it. This operation cannot be undone.
from kubiya import ControlPlaneClientfrom datetime import datetime, timedeltadef cleanup_old_datasets( client: ControlPlaneClient, days_threshold: int = 90, dry_run: bool = True): """Delete datasets older than threshold with no recent activity.""" datasets = client.datasets.list_datasets() now = datetime.utcnow() to_delete = [] for dataset in datasets: created_at = datetime.fromisoformat(dataset['created_at'].replace('Z', '+00:00')) age_days = (now - created_at.replace(tzinfo=None)).days # Simple heuristic: delete if old and name suggests temporary if age_days > days_threshold and any(word in dataset['name'].lower() for word in ['temp', 'test', 'tmp']): to_delete.append(dataset) print(f"=== Dataset Cleanup ===") print(f"Threshold: {days_threshold} days") print(f"Found {len(to_delete)} datasets to delete") if not dry_run: for dataset in to_delete: success = client.datasets.delete_dataset(dataset_id=dataset['id']) if success: print(f"✅ Deleted: {dataset['name']} ({dataset['id']})") else: print(f"❌ Failed to delete: {dataset['name']}") else: print("\nDRY RUN - Would delete:") for dataset in to_delete: print(f" - {dataset['name']} (age: {(now - datetime.fromisoformat(dataset['created_at'].replace('Z', '+00:00')).replace(tzinfo=None)).days} days)") return to_delete# Usageclient = ControlPlaneClient(api_key="your-api-key")# Dry run firstcleanup_old_datasets(client, days_threshold=90, dry_run=True)# Actual cleanup# cleanup_old_datasets(client, days_threshold=90, dry_run=False)
from kubiya import ControlPlaneClientfrom kubiya.resources.exceptions import GraphErrorclient = ControlPlaneClient(api_key="your-api-key")# Handle creation errorstry: dataset = client.datasets.create_dataset( name="my-dataset", scope="org" )except GraphError as e: if "already exists" in str(e).lower(): print("Dataset with this name already exists") else: print(f"Failed to create dataset: {e}")# Handle not found errorstry: dataset = client.datasets.get_dataset(dataset_id="non-existent-id")except GraphError as e: if "not found" in str(e).lower(): print("Dataset not found") else: print(f"Error accessing dataset: {e}")# Handle permission errorstry: client.datasets.delete_dataset(dataset_id="restricted-dataset")except GraphError as e: if "permission" in str(e).lower() or "forbidden" in str(e).lower(): print("Insufficient permissions to delete this dataset") else: print(f"Delete failed: {e}")
# Organization-wide knowledgeclient.datasets.create_dataset( name="company-policies", scope="org" # Everyone can access)# Team-specific knowledgeclient.datasets.create_dataset( name="devops-procedures", scope="role", allowed_roles=["devops", "sre"] # Only specific teams)# Personal notesclient.datasets.create_dataset( name="personal-notes", scope="user" # Only you can access)
dataset = client.datasets.create_dataset( name="production-incidents", description="Historical production incidents with root causes, resolutions, and preventive measures. Updated after each incident closure.", scope="org")
# For datasets that will contain large amounts of datadataset = client.datasets.create_dataset(name="large-logs", scope="org")# Store data...# Check status before queryingstatus = client.datasets.get_dataset_status(dataset_id=dataset['id'])if status['status'] != 'ready': print(f"Dataset still processing: {status['progress']}%")