dataset

package
v2.8.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateOption

type CreateOption func(cfg *createConfig)

func WithCSVDelimiter

func WithCSVDelimiter(delimiter rune) CreateOption

func WithCSVExpectedOutputColumns

func WithCSVExpectedOutputColumns(cols []string) CreateOption

func WithCSVMetadataColumns

func WithCSVMetadataColumns(cols []string) CreateOption

func WithDescription

func WithDescription(description string) CreateOption

func WithProjectName

func WithProjectName(projectName string) CreateOption

WithProjectName sets the project name for the dataset. This overrides the global project name configured via DD_LLM_OBS_ML_APP or tracer.WithLLMObsProjectName().

type Dataset

type Dataset struct {
	// contains filtered or unexported fields
}

Dataset represents a dataset for DataDog LLM Observability experiments.

func Create

func Create(ctx context.Context, name string, records []Record, opts ...CreateOption) (*Dataset, error)

Create initializes a Dataset and pushes it to DataDog.

Example
package main

import (
	"context"
	"log"

	"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
	"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)

func main() {
	if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
		log.Fatal(err)
	}
	defer tracer.Stop()

	ctx := context.Background()

	// First, create the dataset
	ds, err := dataset.Create(
		ctx,
		"capitals-of-the-world",
		[]dataset.Record{
			{
				Input: map[string]any{
					"question": "What is the capital of China?",
				},
				ExpectedOutput: "Beijing",
				Metadata: map[string]any{
					"difficulty": "easy",
				},
			},
			{
				Input: map[string]any{
					"question": "Which city serves as the capital of South Africa?",
				},
				ExpectedOutput: "Pretoria",
				Metadata: map[string]any{
					"difficulty": "medium",
				},
			},
		},
		dataset.WithDescription("Questions about world capitals"),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Finally, push the dataset to DataDog
	if err := ds.Push(ctx); err != nil {
		log.Fatal(err)
	}
}

func CreateFromCSV

func CreateFromCSV(ctx context.Context, name, csvPath string, inputCols []string, opts ...CreateOption) (*Dataset, error)

CreateFromCSV creates a new dataset from a CSV file.

Notes:

  • CSV files must have a header row
  • Maximum field size is 10MB
  • All columns not specified in input_data_columns or expected_output_columns are automatically treated as metadata
  • The dataset is automatically pushed to Datadog after creation

func Pull

func Pull(ctx context.Context, name string, opts ...PullOption) (*Dataset, error)

Pull fetches the given Dataset from DataDog.

func (*Dataset) Append

func (d *Dataset) Append(records ...Record)

Append adds new records to the Dataset.

Example
package main

import (
	"context"
	"log"

	"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
	"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)

func main() {
	if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
		log.Fatal(err)
	}
	defer tracer.Stop()

	ctx := context.Background()

	// First, create the dataset
	ds, err := dataset.Create(
		ctx,
		"capitals-of-the-world",
		[]dataset.Record{
			{
				Input: map[string]any{
					"question": "What is the capital of China?",
				},
				ExpectedOutput: "Beijing",
				Metadata: map[string]any{
					"difficulty": "easy",
				},
			},
			{
				Input: map[string]any{
					"question": "Which city serves as the capital of South Africa?",
				},
				ExpectedOutput: "Pretoria",
				Metadata: map[string]any{
					"difficulty": "medium",
				},
			},
		},
		dataset.WithDescription("Questions about world capitals"),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Add a new question
	ds.Append(dataset.Record{
		Input: map[string]any{
			"question": "What is the capital of China?",
		},
		ExpectedOutput: "Beijing",
		Metadata: map[string]any{
			"difficulty": "easy",
		},
	})

	// Finally, push the dataset to DataDog
	if err := ds.Push(ctx); err != nil {
		log.Fatal(err)
	}
}

func (*Dataset) Delete

func (d *Dataset) Delete(index int)

Delete deletes the record at the given index.

func (*Dataset) ID

func (d *Dataset) ID() string

ID returns the dataset id.

func (*Dataset) Len

func (d *Dataset) Len() int

Len returns the length of the dataset records.

func (*Dataset) Name

func (d *Dataset) Name() string

Name returns the dataset name.

func (*Dataset) Push

func (d *Dataset) Push(ctx context.Context) error

Push pushes the Dataset changes to DataDog. For large changes (>5MB), it uses bulk upload via CSV. For smaller changes, it uses batch update API.

func (*Dataset) Record

func (d *Dataset) Record(idx int) (Record, bool)

Record returns the record at the given index.

func (*Dataset) Records

func (d *Dataset) Records() iter.Seq2[int, Record]

Records returns an iterator with copies of the records in the Dataset. To modify the records, use the Append, Update or Delete methods.

Warning: Do not call any of the methods that modify the records while in the loop, or you will cause a deadlock.

func (*Dataset) URL

func (d *Dataset) URL() string

URL returns the url to access the dataset in DataDog.

func (*Dataset) Update

func (d *Dataset) Update(index int, update RecordUpdate)

Update updates the item at the given index.

Example
package main

import (
	"context"
	"log"

	"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
	"github.com/DataDog/dd-trace-go/v2/llmobs/dataset"
)

func main() {
	if err := tracer.Start(tracer.WithLLMObsEnabled(true)); err != nil {
		log.Fatal(err)
	}
	defer tracer.Stop()

	ctx := context.Background()

	// First, create the dataset
	ds, err := dataset.Create(
		ctx,
		"capitals-of-the-world",
		[]dataset.Record{
			{
				Input: map[string]any{
					"question": "What is the capital of China?",
				},
				ExpectedOutput: "Beijing",
				Metadata: map[string]any{
					"difficulty": "easy",
				},
			},
			{
				Input: map[string]any{
					"question": "Which city serves as the capital of South Africa?",
				},
				ExpectedOutput: "Pretoria",
				Metadata: map[string]any{
					"difficulty": "medium",
				},
			},
		},
		dataset.WithDescription("Questions about world capitals"),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Update the difficulty of the first question
	ds.Update(0, dataset.RecordUpdate{
		Input:          nil, // leave unchanged
		ExpectedOutput: nil, // leave unchanged
		Metadata:       map[string]any{"difficulty": "medium"},
	})

	// Finally, push the dataset to DataDog
	if err := ds.Push(ctx); err != nil {
		log.Fatal(err)
	}
}

func (*Dataset) Version

func (d *Dataset) Version() int

Version returns the dataset version.

type PullOption

type PullOption func(cfg *pullConfig)

func WithPullProjectName

func WithPullProjectName(projectName string) PullOption

WithPullProjectName sets the project name for pulling the dataset. This overrides the global project name configured via DD_LLM_OBS_ML_APP or tracer.WithLLMObsProjectName().

type Record

type Record struct {
	Input          any
	ExpectedOutput any
	Metadata       any
	// contains filtered or unexported fields
}

Record represents a record in a Dataset.

func (*Record) ID

func (r *Record) ID() string

ID returns the record id.

func (*Record) Version

func (r *Record) Version() int

Version returns the record version.

type RecordUpdate

type RecordUpdate struct {
	Input          any
	ExpectedOutput any
	Metadata       any
}

RecordUpdate is used to represent partial record updates. Use nil to signal no modifications to a given field. Use empty values to signal deletion (e.g. empty strings or empty maps).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL