docs/src/content/en/reference/datasets/addItems.mdx
Added in: @mastra/[email protected]
Adds multiple items to the dataset in a single bulk operation.
import { Mastra } from '@mastra/core'
const mastra = new Mastra({
/* storage config */
})
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
const items = await dataset.addItems({
items: [
{ input: { question: 'What is AI?' }, groundTruth: { answer: 'Artificial Intelligence' } },
{ input: { question: 'What is ML?' }, groundTruth: { answer: 'Machine Learning' } },
{ input: { question: 'What is DL?' }, metadata: { category: 'deep-learning' } },
],
})
console.log(`Added ${items.length} items`)
<PropertiesTable content={[ { name: 'items', type: 'Array<object>', description: 'Array of items to add. Each item has the same shape as the dataset.addItem() input.', properties: [ { type: 'DatasetItem', parameters: [ { name: 'input', type: 'unknown', description: 'Input data for the item.', }, { name: 'groundTruth', type: 'unknown', isOptional: true, description: 'Expected output or ground truth.', }, { name: 'metadata', type: 'Record<string, unknown>', isOptional: true, description: 'Arbitrary metadata.', }, ], }, ], }, ]} />
<PropertiesTable content={[ { name: 'result', type: 'Promise<DatasetItem[]>', description: 'Array of created dataset items. See dataset.addItem() for the item shape.', }, ]} />