Dataset 類別
新增於: @mastra/core@1.4.0
Dataset 類別提供方法,用於管理單一資料集的項目 CRUD、版本及實驗。可透過 mastra.datasets.get() 或 mastra.datasets.create() 取得。
使用範例使用範例 的直接連結
加入項目並執行實驗加入項目並執行實驗 的直接連結
src/mastra/datasets/usage.ts
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`)
管理版本及歷史記錄管理版本及歷史記錄 的直接連結
src/mastra/datasets/versioning.ts
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 執行個體。請透過 DatasetsManager 取得:
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
// or
const dataset = await mastra.datasets.create({ name: 'My dataset' })
屬性屬性 的直接連結
如要取得完整資料集記錄(名稱、描述、結構描述、版本及時間戳記),請呼叫 dataset.getDetails()。
id:
string
資料集的唯一識別碼。 唯讀。