Sub topic 13
Version and store the dataset
This chapter assumes you can read JSONL, you know the case schema from the earlier chapter, and you have used git. An eval score only means something if you know which cases produced it. If you edit the dataset between two runs, you can't tell whether the app changed or the test did.
What to version
Treat the dataset like code. Three things change over time:
- Cases are added, removed, or corrected.
- Reference answers and tags are revised.
- The split assignment changes if you alter the hashing rule.
Each of these can move a score, so each needs a recorded version.
Store it as plain files
Keep one JSONL file per dataset, with one case per line, in the same git repository as the app or in a dedicated one. Plain text gives you readable diffs, review through pull requests, and history for free. Sort lines by id before saving so that a diff shows only real changes.
Use a database or a dataset platform only when you need access control, very large files, or non-engineers editing cases. Even then, export a JSONL snapshot for each release.
Large files and sensitive content need extra care. Cases from production logs may contain personal data. Redact it before the file is committed. Store images or long documents outside git and reference them by path and hash.
Add a content hash and a manifest
A version number is a label that humans choose. A content hash is computed from the data, so it catches edits nobody announced. Record both in a manifest next to the file.
import hashlib
import json
def dataset_hash(path):
with open(path, encoding="utf-8") as f:
cases = [json.loads(line) for line in f if line.strip()]
cases.sort(key=lambda c: c["id"])
canonical = "\n".join(
json.dumps(c, sort_keys=True, ensure_ascii=False) for c in cases
)
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:12]
def write_manifest(path, version, manifest_path="manifest.json"):
with open(path, encoding="utf-8") as f:
count = sum(1 for line in f if line.strip())
manifest = {
"file": path,
"version": version,
"sha256_prefix": dataset_hash(path),
"cases": count,
}
with open(manifest_path, "w", encoding="utf-8") as f:
json.dump(manifest, f, indent=2)
return manifestSorting and sort_keys=True make the hash independent of line order and key order. Only a change in content alters it.
Rules for changing cases
- Never reuse an
id. If a case's meaning changes, retire the old id and add a new one. - Keep retired cases in the history, not in the active file.
- Do not change a case's split. The id-hashing rule from the splits chapter keeps this stable as long as you don't change
test_percent. - Use a version scheme you can explain. For example, bump the major number when you remove or redefine cases, and the minor number when you only add them.
- Write a changelog line with each release that says what changed and why.
Tie results to the version
Every eval run should save the dataset version and hash with its scores. When two runs differ, compare the hashes first. If they match, the app caused the change. If they differ, rerun the older app on the new dataset before drawing conclusions.
Common errors
- Editing the file by hand without regenerating the manifest.
- Comparing scores from different dataset versions as if they were comparable.
- Committing unredacted production data.
- Letting the test split change because the split rule was edited.
Exercise
You fix a typo in the reference field of case refund-001 and also add 30 new cases. The hash of the file changes. What should you do before running the next eval, and why can't you compare its score directly with last week's score?
Show answer
Bump the dataset version (the removed or changed reference makes this at least a minor bump), regenerate the manifest, and add a changelog entry. The score can't be compared directly because the dataset content differs. Last week's run used the old hash. To measure the app alone, rerun last week's app version on the new dataset.