Skip to main content

dataset.addItem()

Added in: @mastra/core@1.4.0

Adds a single item to the dataset. Each item has an input, optional ground truth, and optional metadata.

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 item = await dataset.addItem({
input: { question: 'What is TypeScript?' },
groundTruth: { answer: 'A typed superset of JavaScript' },
metadata: { source: 'manual' },
})

console.log(item.id)

Parameters
Direct link to Parameters

input:

unknown
Input data for the item.

groundTruth?:

unknown
Expected output or ground truth for scoring.

metadata?:

Record<string, unknown>
Arbitrary metadata for the item.

Returns
Direct link to Returns

result:

Promise<DatasetItem>
The created dataset item.
DatasetItem

id:

string
Unique identifier of the item.

datasetId:

string
ID of the parent dataset.

datasetVersion:

number
Dataset version when the item was created.

input:

unknown
Input data.

groundTruth?:

unknown
Ground truth data.

metadata?:

Record<string, unknown>
Item metadata.

createdAt:

Date
When the item was created.

updatedAt:

Date
When the item was last updated.
On this page