Internal
Creates a new DatasetManager instance.
Configuration object containing the API client
Retrieves a dataset by name with all its items and experiment functionality.
This method fetches a dataset and all its associated items, with support for automatic pagination to handle large datasets efficiently. The returned dataset object includes enhanced functionality for linking items to traces and running experiments directly on the dataset.
The name of the dataset to retrieve
Optional
options: { fetchItemsPageSize: number }Optional configuration for data fetching
Number of items to fetch per page (default: 50)
Promise resolving to enhanced dataset with items, linking, and experiment capabilities
const dataset = await langfuse.dataset.get("my-evaluation-dataset");
console.log(`Dataset ${dataset.name} has ${dataset.items.length} items`);
// Access dataset properties
console.log(dataset.description);
console.log(dataset.metadata);
const dataset = await langfuse.dataset.get("qa-dataset");
for (const item of dataset.items) {
console.log("Question:", item.input);
console.log("Expected Answer:", item.expectedOutput);
// Each item has a link function for connecting to traces
// await item.link(span, "experiment-name");
}
const dataset = await langfuse.dataset.get("benchmark-dataset");
const result = await dataset.runExperiment({
name: "GPT-4 Benchmark",
runName: "GPT-4 Benchmark v1.2", // optional exact run name
description: "Evaluating GPT-4 on our benchmark tasks",
task: async ({ input }) => {
const response = await openai.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: input }]
});
return response.choices[0].message.content;
},
evaluators: [
async ({ output, expectedOutput }) => ({
name: "exact_match",
value: output === expectedOutput ? 1 : 0
})
]
});
console.log(await result.format());
// For very large datasets, use smaller page sizes
const largeDataset = await langfuse.dataset.get(
"large-dataset",
{ fetchItemsPageSize: 100 }
);
Manager for dataset operations in Langfuse.
Provides methods to retrieve datasets and their items, with automatic pagination handling and convenient linking functionality for experiments.