Class: Braintrust::Resources::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/resources/dataset.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Dataset

Returns a new instance of Dataset.



6
7
8
# File 'lib/braintrust/resources/dataset.rb', line 6

def initialize(client:)
  @client = client
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Braintrust::Models::Dataset

Create a new dataset. If there is an existing dataset in the project with the same name as the one specified in the request, will return the existing dataset unmodified

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the dataset. Within a project, dataset names are unique

  • :description (String)

    Textual description of the dataset

  • :project_id (String)

    Unique identifier for the project that the dataset belongs under

Returns:



22
23
24
25
26
27
28
29
# File 'lib/braintrust/resources/dataset.rb', line 22

def create(params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/dataset"
  req[:body] = params
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end

#delete(dataset_id, opts = {}) ⇒ Braintrust::Models::Dataset

Delete a dataset object by its id

Parameters:

  • dataset_id (String)

    Dataset id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



107
108
109
110
111
112
113
# File 'lib/braintrust/resources/dataset.rb', line 107

def delete(dataset_id, opts = {})
  req = {}
  req[:method] = :delete
  req[:path] = "/v1/dataset/#{dataset_id}"
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end

#feedback(dataset_id, params = {}, opts = {}) ⇒ nil

Log feedback for a set of dataset events

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :feedback (Array<Feedback>)

    A list of dataset feedback items

Returns:

  • (nil)


125
126
127
128
129
130
131
132
# File 'lib/braintrust/resources/dataset.rb', line 125

def feedback(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/dataset/#{dataset_id}/feedback"
  req[:body] = params
  req[:model] = NilClass
  @client.request(req, opts)
end

#fetch(dataset_id, params = {}, opts = {}) ⇒ Braintrust::Models::DatasetFetchResponse

Fetch the events in a dataset. Equivalent to the POST form of the same path, but with the parameters in the URL query rather than in the request body

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :limit (Integer)

    limit the number of traces fetched

    Fetch queries may be paginated if the total result size is expected to be large (e.g. project_logs which accumulate over a long time). Note that fetch queries only support pagination in descending time order (from latest to earliest _xact_id. Furthermore, later pages may return rows which showed up in earlier pages, except with an earlier _xact_id. This happens because pagination occurs over the whole version history of the event log. You will most likely want to exclude any such duplicate, outdated rows (by id) from your combined result set.

    The limit parameter controls the number of full traces to return. So you may end up with more individual rows than the specified limit if you are fetching events containing traces.

  • :max_root_span_id (String)

    DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' argument going forwards.

    Together, max_xact_id and max_root_span_id form a pagination cursor

    Since a paginated fetch query returns results in order from latest to earliest, the cursor for the next page can be found as the row with the minimum (earliest) value of the tuple (_xact_id, root_span_id). See the documentation of limit for an overview of paginating fetch queries.

  • :max_xact_id (String)

    DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' argument going forwards.

    Together, max_xact_id and max_root_span_id form a pagination cursor

    Since a paginated fetch query returns results in order from latest to earliest, the cursor for the next page can be found as the row with the minimum (earliest) value of the tuple (_xact_id, root_span_id). See the documentation of limit for an overview of paginating fetch queries.

  • :version (String)

    Retrieve a snapshot of events from a past time

    The version id is essentially a filter on the latest event transaction id. You can use the max_xact_id returned by a past fetch as the version to reproduce that exact fetch.

Returns:



183
184
185
186
187
188
189
190
# File 'lib/braintrust/resources/dataset.rb', line 183

def fetch(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/dataset/#{dataset_id}/fetch"
  req[:query] = params
  req[:model] = Braintrust::Models::DatasetFetchResponse
  @client.request(req, opts)
end

#fetch_post(dataset_id, params = {}, opts = {}) ⇒ Braintrust::Models::DatasetFetchPostResponse

Fetch the events in a dataset. Equivalent to the GET form of the same path, but with the parameters in the request body rather than in the URL query

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :cursor (String)

    An opaque string to be used as a cursor for the next page of results, in order from latest to earliest.

    The string can be obtained directly from the cursor property of the previous fetch query

  • :filters (Array<Filter>)

    A list of filters on the events to fetch. Currently, only path-lookup type filters are supported, but we may add more in the future

  • :limit (Integer)

    limit the number of traces fetched

    Fetch queries may be paginated if the total result size is expected to be large (e.g. project_logs which accumulate over a long time). Note that fetch queries only support pagination in descending time order (from latest to earliest _xact_id. Furthermore, later pages may return rows which showed up in earlier pages, except with an earlier _xact_id. This happens because pagination occurs over the whole version history of the event log. You will most likely want to exclude any such duplicate, outdated rows (by id) from your combined result set.

    The limit parameter controls the number of full traces to return. So you may end up with more individual rows than the specified limit if you are fetching events containing traces.

  • :max_root_span_id (String)

    DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' argument going forwards.

    Together, max_xact_id and max_root_span_id form a pagination cursor

    Since a paginated fetch query returns results in order from latest to earliest, the cursor for the next page can be found as the row with the minimum (earliest) value of the tuple (_xact_id, root_span_id). See the documentation of limit for an overview of paginating fetch queries.

  • :max_xact_id (String)

    DEPRECATION NOTICE: The manually-constructed pagination cursor is deprecated in favor of the explicit 'cursor' returned by object fetch requests. Please prefer the 'cursor' argument going forwards.

    Together, max_xact_id and max_root_span_id form a pagination cursor

    Since a paginated fetch query returns results in order from latest to earliest, the cursor for the next page can be found as the row with the minimum (earliest) value of the tuple (_xact_id, root_span_id). See the documentation of limit for an overview of paginating fetch queries.

  • :version (String)

    Retrieve a snapshot of events from a past time

    The version id is essentially a filter on the latest event transaction id. You can use the max_xact_id returned by a past fetch as the version to reproduce that exact fetch.

Returns:



248
249
250
251
252
253
254
255
# File 'lib/braintrust/resources/dataset.rb', line 248

def fetch_post(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/dataset/#{dataset_id}/fetch"
  req[:body] = params
  req[:model] = Braintrust::Models::DatasetFetchPostResponse
  @client.request(req, opts)
end

#insert(dataset_id, params = {}, opts = {}) ⇒ Braintrust::Models::DatasetInsertResponse

Insert a set of events into the dataset

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :events (Array<Event::UnnamedTypeWithunionParent11|Event::UnnamedTypeWithunionParent12>)

    A list of dataset events to insert

Returns:



267
268
269
270
271
272
273
274
# File 'lib/braintrust/resources/dataset.rb', line 267

def insert(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/dataset/#{dataset_id}/insert"
  req[:body] = params
  req[:model] = Braintrust::Models::DatasetInsertResponse
  @client.request(req, opts)
end

#list(params = {}, opts = {}) ⇒ Braintrust::ListObjects<Braintrust::Models::Dataset>

List out all datasets. The datasets are sorted by creation date, with the most recently-created datasets coming first

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :dataset_name (String)

    Name of the dataset to search for

  • :ending_before (String)

    Pagination cursor id.

    For example, if the initial item in the last page you fetched had an id of foo, pass ending_before=foo to fetch the previous page. Note: you may only pass one of starting_after and ending_before

  • :ids (Array<String>|String)

    Filter search results to a particular set of object IDs. To specify a list of IDs, include the query param multiple times

  • :limit (Integer)

    Limit the number of objects to return

  • :org_name (String)

    Filter search results to within a particular organization

  • :project_name (String)

    Name of the project to search for

  • :starting_after (String)

    Pagination cursor id.

    For example, if the final item in the last page you fetched had an id of foo, pass starting_after=foo to fetch the next page. Note: you may only pass one of starting_after and ending_before

Returns:



91
92
93
94
95
96
97
98
99
# File 'lib/braintrust/resources/dataset.rb', line 91

def list(params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/dataset"
  req[:query] = params
  req[:page] = Braintrust::ListObjects
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end

#replace(params = {}, opts = {}) ⇒ Braintrust::Models::Dataset

NOTE: This operation is deprecated and will be removed in a future revision of the API. Create or replace a new dataset. If there is an existing dataset in the project with the same name as the one specified in the request, will return the existing dataset unmodified, will replace the existing dataset with the provided fields

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the dataset. Within a project, dataset names are unique

  • :description (String)

    Textual description of the dataset

  • :project_id (String)

    Unique identifier for the project that the dataset belongs under

Returns:



290
291
292
293
294
295
296
297
# File 'lib/braintrust/resources/dataset.rb', line 290

def replace(params = {}, opts = {})
  req = {}
  req[:method] = :put
  req[:path] = "/v1/dataset"
  req[:body] = params
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end

#retrieve(dataset_id, opts = {}) ⇒ Braintrust::Models::Dataset

Get a dataset object by its id

Parameters:

  • dataset_id (String)

    Dataset id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



37
38
39
40
41
42
43
# File 'lib/braintrust/resources/dataset.rb', line 37

def retrieve(dataset_id, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/dataset/#{dataset_id}"
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end

#summarize(dataset_id, params = {}, opts = {}) ⇒ Braintrust::Models::DatasetSummarizeResponse

Summarize dataset

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :summarize_data (Boolean)

    Whether to summarize the data. If false (or omitted), only the metadata will be returned.

Returns:



310
311
312
313
314
315
316
317
# File 'lib/braintrust/resources/dataset.rb', line 310

def summarize(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/dataset/#{dataset_id}/summarize"
  req[:query] = params
  req[:model] = Braintrust::Models::DatasetSummarizeResponse
  @client.request(req, opts)
end

#update(dataset_id, params = {}, opts = {}) ⇒ Braintrust::Models::Dataset

Partially update a dataset object. Specify the fields to update in the payload. Any object-type fields will be deep-merged with existing content. Currently we do not support removing fields or setting them to null.

Parameters:

  • dataset_id (String)

    Dataset id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :description (String)

    Textual description of the dataset

  • :name (String)

    Name of the dataset. Within a project, dataset names are unique

Returns:



58
59
60
61
62
63
64
65
# File 'lib/braintrust/resources/dataset.rb', line 58

def update(dataset_id, params = {}, opts = {})
  req = {}
  req[:method] = :patch
  req[:path] = "/v1/dataset/#{dataset_id}"
  req[:body] = params
  req[:model] = Braintrust::Models::Dataset
  @client.request(req, opts)
end