Skip to main content

dataset.addItems()

Added in: @mastra/core@1.4.0

Adds multiple items to the dataset in a single bulk operation.

Usage example
Direct link to Usage example

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`)

Parameters
Direct link to Parameters

items:

Array<object>
Array of items to add. Each item has the same shape as the dataset.addItem() input.
DatasetItem

input:

unknown
Input data for the item.

groundTruth?:

unknown
Expected output or ground truth.

metadata?:

Record<string, unknown>
Arbitrary metadata.

Returns
Direct link to Returns

result:

Promise<DatasetItem[]>
Array of created dataset items. See dataset.addItem() for the item shape.
On this page