

# Kelola kumpulan data
<a name="datasets-manage"></a>

Topik ini mencakup pembuatan, pengambilan, daftar, pembaruan, dan penghapusan kumpulan data.

## Buat kumpulan data
<a name="datasets-create"></a>

`CreateDataset`API membuat dataset evaluasi baru. Ini adalah operasi asinkron (HTTP 202) — transisi dataset dari ke setelah konsumsi selesai. `CREATING` `ACTIVE`

 **Parameter yang diperlukan:** `datasetName` (hanya alfanumerik dan garis bawah,`^[a-zA-Z][a-zA-Z0-9_]{0,47}$`),`schemaType`, dan `source` (contoh sebaris atau URI S3).

 **Parameter opsional:**`description`, `kmsKeyArn` (kunci enkripsi terkelola pelanggan, tidak dapat diubah setelah pembuatan — lihat [enkripsi Dataset](datasets-encryption.md)),. `tags`

Contoh berikut menunjukkan cara membuat dataset:

**Example**  

1. 

   ```
   # Add a dataset to your project
   agentcore add dataset --name my_eval_dataset \
       --schema-type AGENTCORE_EVALUATION_PREDEFINED_V1
   
   # Edit the generated JSONL file with your scenarios
   # File location: agentcore/datasets/my_eval_dataset.jsonl
   
   # Deploy to create the dataset in your AWS account
   agentcore deploy
   ```

   Ini membuat file JSONL lokal dan mendaftarkan kumpulan data dalam konfigurasi proyek Anda. Jalankan `agentcore deploy` untuk membuat sumber daya kumpulan data dan menyinkronkan contoh ke layanan.
**catatan**  
Jalankan ini dari dalam direktori AgentCore proyek (dibuat dengan`agentcore create`).

1. 

   ```
   from bedrock_agentcore.evaluation import DatasetClient
   
   client = DatasetClient(region_name="us-west-2")
   
   # Create with inline examples (polls until ACTIVE)
   ds = client.create_dataset_and_wait(
       datasetName="customer_support_scenarios",
       schemaType="AGENTCORE_EVALUATION_PREDEFINED_V1",
       source={
           "inlineExamples": {
               "examples": [
                   {
                       "scenario_id": "TC-01",
                       "turns": [{"input": "What is my balance?", "expected_response": "Your balance is $50."}],
                       "assertions": ["Response includes a dollar amount"],
                   }
               ]
           }
       },
   )
   print(f"Dataset ID: {ds['datasetId']}, Status: {ds['status']}")
   
   # Create with S3 source
   ds = client.create_dataset_and_wait(
       datasetName="my_s3_dataset",
       schemaType="AGENTCORE_EVALUATION_PREDEFINED_V1",
       source={"s3Source": {"s3Uri": "s3://my-bucket/scenarios.jsonl"}},
   )
   ```
**catatan**  
Untuk konsumsi S3, setiap baris dalam file JSONL harus menyertakan bidang. `exampleId` Bucket S3 harus dapat diakses menggunakan kredensi pemanggil.

1. 

   ```
   import boto3
   import time
   
   client = boto3.client('bedrock-agentcore-control')
   
   response = client.create_dataset(
       datasetName='customer_support_scenarios',
       schemaType='AGENTCORE_EVALUATION_PREDEFINED_V1',
       source={
           'inlineExamples': {
               'examples': [
                   {
                       'scenario_id': 'TC-01',
                       'turns': [{'input': 'What is my balance?', 'expected_response': 'Your balance is $50.'}],
                       'assertions': ['Response includes a dollar amount'],
                   }
               ]
           }
       }
   )
   dataset_id = response['datasetId']
   
   # Create with S3 source
   response = client.create_dataset(
       datasetName='my_s3_dataset',
       schemaType='AGENTCORE_EVALUATION_PREDEFINED_V1',
       source={
           's3Source': {'s3Uri': 's3://my-bucket/scenarios.jsonl'}
       }
   )
   
   # Poll until ACTIVE
   while True:
       ds = client.get_dataset(datasetId=dataset_id)
       if ds['status'] in ('ACTIVE', 'CREATE_FAILED'):
           break
       time.sleep(2)
   ```

1. 

   ```
   # Create with inline examples
   aws bedrock-agentcore-control create-dataset \
       --dataset-name "customer_support_scenarios" \
       --schema-type AGENTCORE_EVALUATION_PREDEFINED_V1 \
       --source '{"inlineExamples": {"examples": [{"scenario_id": "TC-01", "turns": [{"input": "What is my balance?", "expected_response": "Your balance is $50."}], "assertions": ["Response includes a dollar amount"]}]}}'
   
   # Create with S3 source
   aws bedrock-agentcore-control create-dataset \
       --dataset-name "my_s3_dataset" \
       --schema-type AGENTCORE_EVALUATION_PREDEFINED_V1 \
       --source '{"s3Source": {"s3Uri": "s3://my-bucket/scenarios.jsonl"}}'
   
   # Poll until ACTIVE
   aws bedrock-agentcore-control get-dataset \
       --dataset-id my-dataset-id
   ```

## Dapatkan dataset
<a name="datasets-get"></a>

`GetDataset`API mengambil metadata kumpulan data, status, jumlah contoh, dan URL unduhan yang telah ditetapkan sebelumnya untuk konten kumpulan data. Secara default membaca Draf; tentukan `datasetVersion` untuk versi yang diterbitkan.

`downloadUrl`Ini adalah URL S3 presigned untuk file lengkap`dataset.jsonl`. Anda dapat mengunduhnya dengan permintaan HTTP GET biasa tanpa header otentikasi.

Contoh berikut menunjukkan cara mendapatkan dataset:

**Example**  

1. 

   ```
   # Show dataset deployment status and metadata
   agentcore status --type dataset
   
   # Download dataset content to your local JSONL file (default: Draft)
   agentcore dataset download --name my_eval_dataset
   
   # Download a specific published version
   agentcore dataset download --name my_eval_dataset --version 1
   ```

1. 

   ```
   from bedrock_agentcore.evaluation import DatasetClient
   
   client = DatasetClient(region_name="us-west-2")
   
   # Get dataset (default: Draft)
   ds = client.get_dataset(datasetId="my-dataset-id")
   print(f"Status: {ds['status']}, Examples: {ds['exampleCount']}")
   print(f"Download URL: {ds['downloadUrl']}")
   
   # Get a specific published version
   ds_v1 = client.get_dataset(datasetId="my-dataset-id", datasetVersion="1")
   ```

1. 

   ```
   import boto3
   
   client = boto3.client('bedrock-agentcore-control')
   
   response = client.get_dataset(datasetId='my-dataset-id')
   print(f"Status: {response['status']}, Examples: {response['exampleCount']}")
   
   # Download the dataset content via presigned URL
   if 'downloadUrl' in response:
       import requests
       data = requests.get(response['downloadUrl'])
       print(data.text)
   
   # Get a specific published version
   response = client.get_dataset(datasetId='my-dataset-id', datasetVersion='1')
   ```

1. 

   ```
   # Get dataset (default: Draft)
   aws bedrock-agentcore-control get-dataset \
       --dataset-id my-dataset-id
   
   # Get a specific published version
   aws bedrock-agentcore-control get-dataset \
       --dataset-id my-dataset-id \
       --dataset-version 1
   ```

## Daftar kumpulan data
<a name="datasets-list"></a>

`ListDatasets`API menampilkan daftar kumpulan data yang dipaginasi di akun dan Wilayah Anda.

Contoh berikut menunjukkan cara membuat daftar kumpulan data:

**Example**  

1. 

   ```
   agentcore status --type dataset
   ```

1. 

   ```
   from bedrock_agentcore.evaluation import DatasetClient
   
   client = DatasetClient(region_name="us-west-2")
   
   response = client.list_datasets()
   for dataset in response["datasets"]:
       print(f"  {dataset['datasetName']} ({dataset['status']})")
   ```

1. 

   ```
   import boto3
   
   client = boto3.client('bedrock-agentcore-control')
   
   response = client.list_datasets()
   for dataset in response['datasets']:
       print(f"  {dataset['datasetName']} ({dataset['status']})")
   ```

1. 

   ```
   aws bedrock-agentcore-control list-datasets
   ```

## Perbarui kumpulan data
<a name="datasets-update"></a>

`UpdateDataset`API memperbarui metadata kumpulan data. Ini adalah operasi sinkron (HTTP 200). Hanya `description` dan `tags` dapat diperbarui. `datasetName`,`schemaType`, dan `kmsKeyArn` tidak dapat diubah setelah penciptaan.

Dataset harus dalam`ACTIVE`,`UPDATE_FAILED`, atau `CREATE_FAILED` status.

Contoh berikut menunjukkan cara memperbarui metadata kumpulan data:

**Example**  

1. Untuk memperbarui kumpulan data dengan AgentCore CLI, edit konfigurasi kumpulan data di file `agentcore.json` Anda secara langsung, lalu terapkan ulang:

   ```
   agentcore deploy
   ```

   Buka`agentcore.json`, temukan dataset dalam `datasets` array, modifikasi`description`, lalu jalankan`agentcore deploy`. Perubahan berlaku setelah penerapan.
**catatan**  
Jalankan ini dari dalam direktori AgentCore proyek (dibuat dengan`agentcore create`).

1. 

   ```
   from bedrock_agentcore.evaluation import DatasetClient
   
   client = DatasetClient(region_name="us-west-2")
   
   client.update_dataset(datasetId="my-dataset-id", description="Updated description")
   ```

1. 

   ```
   import boto3
   
   client = boto3.client('bedrock-agentcore-control')
   
   client.update_dataset(datasetId='my-dataset-id', description='Updated description')
   ```

1. 

   ```
   aws bedrock-agentcore-control update-dataset \
       --dataset-id my-dataset-id \
       --description "Updated description"
   ```

## Hapus kumpulan data
<a name="datasets-delete"></a>

`DeleteDataset`API menghapus dataset. Ini adalah operasi asinkron (HTTP 202).
+  **Hapus penuh** (hilangkan`datasetVersion`): Menghapus semua versi, Draf, dan catatan kumpulan data.
+  **Version-specific delete** (tentukan `datasetVersion` sebagai integer): Menghapus hanya versi yang diterbitkan.

Dataset harus dalam`ACTIVE`,, `CREATE_FAILED``UPDATE_FAILED`, atau `DELETE_FAILED` status.

**catatan**  
Hanya nomor versi integer yang diterima untuk penghapusan khusus versi.

Contoh berikut menunjukkan cara menghapus dataset:

**Example**  

1. 

   ```
   # Delete a specific published version
   agentcore dataset remove-version 1 --name my_eval_dataset
   
   # Delete entire dataset
   agentcore remove dataset --name my_eval_dataset
   agentcore deploy
   ```

1. 

   ```
   from bedrock_agentcore.evaluation import DatasetClient
   
   client = DatasetClient(region_name="us-west-2")
   
   # Delete a specific published version
   client.delete_dataset_and_wait(datasetId="my-dataset-id", datasetVersion="1")
   
   # Delete entire dataset (polls until complete)
   client.delete_dataset_and_wait(datasetId="my-dataset-id")
   ```

1. 

   ```
   import boto3
   
   client = boto3.client('bedrock-agentcore-control')
   
   # Delete a specific published version
   client.delete_dataset(datasetId='my-dataset-id', datasetVersion='1')
   
   # Delete entire dataset
   client.delete_dataset(datasetId='my-dataset-id')
   ```

1. 

   ```
   # Delete a specific published version
   aws bedrock-agentcore-control delete-dataset \
       --dataset-id my-dataset-id \
       --dataset-version 1
   
   # Delete entire dataset
   aws bedrock-agentcore-control delete-dataset \
       --dataset-id my-dataset-id
   ```