Automate Knowledge Boxes (KBs) Creation and Deletion
This guide provides a script to automate the creation and deletion of Knowledge Boxes (KBs) using Agentic RAG's API.
Prerequisites
You need a NUA key with specific access rights. Ensure the "Allow management of Knowledge Boxes" option is selected when creating the NUA key.
Setup
First, ensure you have the necessary imports and constants defined:
import requests
MANAGEMENT_API = "https://rag.progress.cloud/api/v1"
ZONE = "europe-1"
ZONE_MANAGEMENT_API = f"https://{ZONE}.rag.progress.cloud/api/v1"
ACCOUNT_ID = "YOUR-ACCOUNT-ID"
NUA_API_KEY = "YOUR-NUA-KEY"
Functions Overview
1. List Knowledge Boxes (KBs)
List all KBs for an account and zone (zone depends on the NUA Key).
def list_kbs():
url = f"{ZONE_MANAGEMENT_API}/account/{ACCOUNT_ID}/kbs"
response = requests.get(url, headers={"X-NUCLIA-NUAKEY": f"Bearer {NUA_API_KEY}"})
response.raise_for_status()
return response.json()
2. Create a Knowledge Box (KB)
Create a new KB with the specified title and slug.
def create_kb(title, slug):
url = f"{ZONE_MANAGEMENT_API}/account/{ACCOUNT_ID}/kbs"
payload = {
"title": title,
"slug": slug,
"learning_configuration": {
"anonymization_model": "disabled",
"semantic_model": "multilingual-2024-05-06",
},
}
response = requests.post(
url,
json=payload,
headers={"X-NUCLIA-NUAKEY": f"Bearer {NUA_API_KEY}"},
)
response.raise_for_status()
return response.json()
3. Delete a Knowledge Box (KB)
Delete a KB with the specified slug.
def delete_kb(kb_id):
url = f"{ZONE_MANAGEMENT_API}/account/{ACCOUNT_ID}/kb/{kb_id}"
response = requests.delete(url, headers={"X-NUCLIA-NUAKEY": f"Bearer {NUA_API_KEY}"})
response.raise_for_status()