docs/src/content/en/reference/datasets/dataset.mdx
Added in: @mastra/[email protected]
The Dataset class provides methods for item CRUD, versioning, and experiment management on a single dataset. Obtained via mastra.datasets.get() or mastra.datasets.create().
import { Mastra } from '@mastra/core'
const mastra = new Mastra({
/* storage config */
})
const dataset = await mastra.datasets.create({
name: 'QA pairs',
})
// Add items
await dataset.addItems({
items: [
{ input: { question: 'What is AI?' }, groundTruth: { answer: 'Artificial Intelligence' } },
{ input: { question: 'What is ML?' }, groundTruth: { answer: 'Machine Learning' } },
],
})
// Run an experiment
const summary = await dataset.startExperiment({
targetType: 'agent',
targetId: 'my-agent',
scorers: ['accuracy'],
})
console.log(`${summary.succeededCount}/${summary.totalItems} succeeded`)
import { Mastra } from '@mastra/core'
const mastra = new Mastra({
/* storage config */
})
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
// List versions
const { versions } = await dataset.listVersions()
// List items at a specific version
const items = await dataset.listItems({ version: 2 })
// Get item change history
const history = await dataset.getItemHistory({ itemId: 'item-id' })
Dataset isn't instantiated directly. Obtain one via DatasetsManager:
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
// or
const dataset = await mastra.datasets.create({ name: 'My dataset' })
For the full dataset record (name, description, schemas, version, timestamps), call dataset.getDetails().
<PropertiesTable content={[ { name: 'id', type: 'string', description: 'The unique identifier of the dataset. Read-only.', }, ]} />