opik.EvaluationDataset
kedro_datasets_experimental.opik.EvaluationDataset ¶
EvaluationDataset(
dataset_name,
credentials,
filepath=None,
sync_policy="local",
metadata=None,
)
Bases: AbstractDataset
Kedro dataset for Opik evaluation datasets.
Connects to an Opik evaluation dataset and returns an opik.Dataset
on load(), which can be passed to opik.evaluation.evaluate() to
run experiments. Supports an optional local JSON/YAML file as the
authoring surface for evaluation items.
On load / save behaviour:
- On load: Creates the remote dataset if it does not exist,
synchronises based on
sync_policy, and returns anopik.Dataset. - On save: Inserts all items to the remote dataset via Opik's
upsert-by-ID API. Items with a UUID v7
idupdate the existing remote row in-place; items without a UUID v7idcreate a new remote row on every call. Inlocalmode, items are also merged into the local file (new items take precedence). Inremotemode, only the remote insert occurs.
Item format:
The local file and save() data must be a list of dicts. Each item
accepts the following keys:
input(required) — the evaluation input payload.-
id— identifier used for local deduplication. The upload behaviour depends on whetheridis a valid UUID v7:- Valid UUID v7: forwarded to Opik. Opik's API upserts by item ID — the first sync creates the remote row; subsequent syncs update that same row in-place if the content has changed. The remote row keeps the same UUID across all syncs. Whenever content changes, the existing remote row is updated in-place, while no new row is created.
- All other values (human-readable strings, UUIDs of other
versions,
None, empty string, or noidkey): stripped before upload. Opik auto-generates a new UUID v7. Unchanged content is deduplicated by content hash (no-op), but changed content creates a new remote row while the previous one remains, leading to row accumulation over time.
-
expected_output— ground-truth value for scoring. metadata— arbitrary metadata dict attached to the item.
[
{
"id": "q1",
"input": {"text": "cancel my order"},
"expected_output": "cancel_order",
"metadata": {"source": "production"}
}
]
Sync policies:
-
local (default): The local file is the source of truth. On
load(), all local items are re-inserted to remote on every sync. Opik's API upserts by item ID, so the outcome depends on whether each item carries a UUID v7id:- Items with a UUID v7
idare updated in-place on the remote — content changes replace the existing row; unchanged items are a no-op. - Items without a UUID v7
id(non-UUID values are stripped) are deduplicated by content hash — unchanged content is a no-op, but changed content creates a new remote row (the previous row remains), leading to row accumulation over time.save()inserts to remote and merges into the local file (new data takes precedence).
- Items with a UUID v7
-
remote: The remote Opik dataset is the sole source of truth.
load()fetches the remote dataset as-is with no local file interaction.save()inserts all items to remote without writing to any local file. If the remote dataset does not exist yet, it is created empty — no items are pushed from the local file. To seed a new remote dataset, run withsync_policy="local"at least once, or create and populate the dataset directly via the Opik UI.
Examples:
Using catalog YAML configuration:
# Local sync policy — local file seeds and syncs to remote
evaluation_dataset:
type: kedro_datasets_experimental.opik.EvaluationDataset
dataset_name: intent-detection-eval
filepath: data/evaluation/intent_items.json
sync_policy: local
credentials: opik_credentials
metadata:
project: intent-detection
# Remote sync policy — Opik is the source of truth
production_eval:
type: kedro_datasets_experimental.opik.EvaluationDataset
dataset_name: intent-detection-eval
sync_policy: remote
credentials: opik_credentials
Using Python API:
from kedro_datasets_experimental.opik import EvaluationDataset
dataset = EvaluationDataset(
dataset_name="intent-detection-eval",
credentials={"api_key": "..."}, # pragma: allowlist secret
filepath="data/evaluation/intent_items.json",
)
# Load returns an opik.Dataset for running experiments
from opik.evaluation import evaluate
eval_dataset = dataset.load()
evaluate(
dataset=eval_dataset,
task=my_task,
scoring_functions=[my_scorer],
experiment_name="my-experiment",
)
# Save new evaluation items
dataset.save(
[
{"id": "q1", "input": {"text": "cancel order"}, "expected_output": "cancel"},
]
)
# Same as in the other example, "q1" is not a UUID v7 and will be stripped on upload
Parameters:
-
dataset_name(str) –Name of the evaluation dataset in Opik.
-
credentials(dict[str, str]) –Opik authentication credentials. Required:
api_key. Optional:workspace,host,project_name. -
filepath(str | None, default:None) –Path to a local JSON/YAML file for authoring evaluation items. Supports
.json,.yaml, and.ymlextensions. WhenNone, no local file interaction occurs. -
sync_policy(Literal['local', 'remote'], default:'local') –Controls the source of truth for reads and whether a local file is involved:
"local"(default) — all local items are re-inserted to remote onload();save()inserts to remote and merges into the local file (new data takes precedence)."remote"—load()fetches remote as-is;save()inserts to remote without local file interaction. -
metadata(dict[str, Any] | None, default:None) –Optional metadata dict stored locally and returned by
_describe(). Note: Opik'screate_dataset()does not accept a metadata argument, so this value is not propagated to the remote dataset.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
file_dataset
property
¶
file_dataset
Return a JSON or YAML file dataset based on the filepath extension.
_describe ¶
_describe()
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
538 539 540 541 542 543 544 | |
_exists ¶
_exists()
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
_get_or_create_remote_dataset ¶
_get_or_create_remote_dataset()
Ensure the remote Opik dataset exists, creating it if not found.
Returns the latest Dataset object.
Raises:
-
DatasetError–If the Opik API returns an unexpected error or is unreachable.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
_merge_items
staticmethod
¶
_merge_items(existing, new)
Merge new items into an existing list, deduplicating by id.
Items without an id key are always appended. For items with an
id, new items take precedence — existing entries with the same
id are replaced in place.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
_strip_id
staticmethod
¶
_strip_id(item)
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
274 275 276 | |
_sync_local_to_remote ¶
_sync_local_to_remote(dataset)
Insert all local items into the remote dataset.
Reads the local file and inserts all items into the remote dataset.
The Opik SDK deduplicates by content hash, so re-inserting unchanged
items is a no-op. Returns a refreshed Dataset object. If the dataset's
id is a valid UUID v7, the same remote row is updated in-place on every sync.
Otherwise, a new remote row will be created.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
_upload_items ¶
_upload_items(dataset, items)
Insert items into the remote Opik dataset.
Upload behaviour depends on whether an item carries a UUID v7 id:
- Valid UUID v7: forwarded to Opik. Opik's REST API calls
create_or_updateby item ID — the first call creates the remote row; subsequent calls update that same row in-place if the content has changed. Whenever content changes, the existing remote row is updated in-place, while no new row is created. - All other values (human-readable strings, UUIDs of other
versions,
None, empty string, or noidkey): stripped before upload. Opik auto-generates a new UUID v7. Unchanged content is deduplicated by content hash (no-op), but changed content creates a new remote row while the previous one remains.
Callers are responsible for validating items before calling this method.
Raises:
-
DatasetError–If the Opik API returns an error or the server is unreachable during insert.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
_validate_init_params
staticmethod
¶
_validate_init_params(credentials, filepath, sync_policy)
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
213 214 215 216 217 218 219 220 221 222 | |
_validate_items
staticmethod
¶
_validate_items(items)
Validate that all items contain the required input key.
Raises:
-
DatasetError–If any item is missing the
inputkey.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
278 279 280 281 282 283 284 285 286 287 288 289 | |
load ¶
load()
Load the Opik dataset, syncing local items to remote if sync_policy is local.
Creates the remote dataset if it does not exist. In local mode, all
local items are re-inserted to remote on every load via Opik's
create_or_update API (upsert by item ID). On items with a valid UUID v7
id, update the existing remote row in-place, and no new row is created.
On items where the id is not a valid UUID v7 (including missing, None, or empty),
the id is stripped before upload and Opik auto-generates a new UUID v7.
Unchanged content is deduplicated (no-op), but changed content creates a
new remote row while the previous one remains.
Returns:
-
Dataset–The Opik dataset ready for use in experiments.
Raises:
-
DatasetError–If the Opik API returns an unexpected error or the server is unreachable.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
preview ¶
preview()
Generate a JSON-compatible preview of the local evaluation data for Kedro-Viz.
Returns:
-
JSONPreview–A Kedro-Viz-compatible object containing a serialized JSON string. Returns a descriptive message if filepath is not configured or does not exist.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
546 547 548 549 550 551 552 553 | |
save ¶
save(data)
Insert items into the Opik dataset and optionally update the local file.
In remote mode, only the remote upload occurs. In local mode,
items are also merged into the local file.
Parameters:
-
data(list[dict[str, Any]]) –List of dicts, each containing at least an
inputkey.
Raises:
-
DatasetError–If the Opik API call fails or any item is missing
input.
Source code in kedro_datasets_experimental/opik/evaluation_dataset.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |