跳到主要内容

DatasetsManager.create()

添加于: @mastra/core@1.4.0

创建新数据集。使用 Standard JSON Schema(Zod、Valibot、ArkType 等)定义 schema。

使用示例
使用示例的直接链接

import { Mastra } from '@mastra/core'
import { z } from 'zod'

const mastra = new Mastra({/* storage config */})

// Create with metadata
const dataset = await mastra.datasets.create({
name: 'QA evaluation set',
description: 'Question-answer pairs for testing',
metadata: { team: 'ml' },
})

// Create with Zod schema (library that supports Standard JSON Schema)
const typedDataset = await mastra.datasets.create({
name: 'Typed QA set',
inputSchema: z.object({
question: z.string(),
context: z.string().optional(),
}),
groundTruthSchema: z.object({
answer: z.string(),
}),
})

参数
参数的直接链接

name:

string
数据集的显示名称。

description?:

string
数据集的描述。

inputSchema?:

StandardJSONSchemaV1
条目输入的 Standard JSON Schema。

groundTruthSchema?:

StandardJSONSchemaV1
条目 ground truth 的 Standard JSON Schema。

metadata?:

Record<string, unknown>
任意元数据。

返回值
返回值的直接链接

result:

Promise<Dataset>
新创建数据集的 Dataset 实例。