Class: Braintrust::Dataset
- Inherits:
-
Object
- Object
- Braintrust::Dataset
- Includes:
- Enumerable
- Defined in:
- lib/braintrust/dataset.rb
Overview
High-level interface for working with Braintrust datasets. Provides both eager loading and lazy enumeration for efficient access to dataset records.
Defined Under Namespace
Classes: ID
Constant Summary collapse
- DEFAULT_PAGE_SIZE =
Default number of records to fetch per API page
1000
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#each {|Hash| ... } ⇒ Object
Iterate over records lazily (implements Enumerable) Fetches pages on demand for memory efficiency with large datasets.
-
#fetch_all(limit: nil) ⇒ Array<Hash>
Fetch all records eagerly into an array.
-
#id ⇒ String
Get the dataset ID, resolving from name if necessary.
-
#initialize(name: nil, id: nil, project: nil, version: nil, state: nil) ⇒ Dataset
constructor
Initialize a dataset reference.
-
#metadata ⇒ Hash
Get the dataset metadata from the API Makes an API call if metadata hasn’t been fetched yet.
Constructor Details
#initialize(name: nil, id: nil, project: nil, version: nil, state: nil) ⇒ Dataset
Initialize a dataset reference
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/braintrust/dataset.rb', line 42 def initialize(name: nil, id: nil, project: nil, version: nil, state: nil) @name = name @provided_id = id @project = project @version = version @api = API.new(state: state) @resolved_id = nil @metadata = nil validate_params! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/braintrust/dataset.rb', line 34 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
34 35 36 |
# File 'lib/braintrust/dataset.rb', line 34 def project @project end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
34 35 36 |
# File 'lib/braintrust/dataset.rb', line 34 def version @version end |
Instance Method Details
#each {|Hash| ... } ⇒ Object
Iterate over records lazily (implements Enumerable) Fetches pages on demand for memory efficiency with large datasets.
84 85 86 87 |
# File 'lib/braintrust/dataset.rb', line 84 def each(&block) return enum_for(:each) unless block_given? each_record(&block) end |
#fetch_all(limit: nil) ⇒ Array<Hash>
Fetch all records eagerly into an array
75 76 77 78 79 |
# File 'lib/braintrust/dataset.rb', line 75 def fetch_all(limit: nil) records = [] each_record(limit: limit) { |record| records << record } records end |
#id ⇒ String
Get the dataset ID, resolving from name if necessary
56 57 58 59 60 |
# File 'lib/braintrust/dataset.rb', line 56 def id return @provided_id if @provided_id resolve_name! unless @resolved_id @resolved_id end |
#metadata ⇒ Hash
Get the dataset metadata from the API Makes an API call if metadata hasn’t been fetched yet. Note: When initialized with name, metadata is fetched during name resolution. When initialized with ID, this triggers a separate get_by_id call.
67 68 69 70 |
# File 'lib/braintrust/dataset.rb', line 67 def unless @metadata @metadata end |