Qrels¶
A judge's create_qrels() returns Qrels — (topic_id, doc_id, grade) rows. Define extractor functions in a QrelsSpec, build with build_qrels, verify with Qrels.verify(...), and serialize to TREC format with write_qrel_file. For generated text without a corpus id, derive a stable id with doc_id_md5.
Qrels and rows¶
autojudge_base.qrels.Qrels
dataclass
¶
Collection of relevance judgments.
Qrels are intentionally policy-free
- doc_id is opaque
- no assumptions about corpus vs generated content
- no assumptions about how grades are produced
verify ¶
Source code in src/autojudge_base/qrels/qrels.py
43 44 | |
autojudge_base.qrels.QrelRow
dataclass
¶
Spec and builder¶
autojudge_base.qrels.QrelsSpec
dataclass
¶
autojudge_base.qrels.build_qrels ¶
Source code in src/autojudge_base/qrels/qrels.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
Verification and I/O¶
autojudge_base.qrels.QrelsVerification ¶
Fluent verifier for qrels.
Chain verification methods to run multiple checks:
QrelsVerification(qrels, expected_topic_ids).complete_topics().no_duplicates()
Or run all checks:
QrelsVerification(qrels, expected_topic_ids).all()
Each method raises QrelsVerificationError on failure (fail-fast).
Initialize verifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qrels
|
Qrels
|
The qrels to verify |
required |
expected_topic_ids
|
Sequence[str]
|
The expected topic IDs to verify against |
required |
warn
|
Optional[bool]
|
If True, print warnings instead of raising exceptions |
False
|
Source code in src/autojudge_base/qrels/verification.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
complete_topics ¶
complete_topics() -> QrelsVerification
Verify every expected topic has at least one qrel row.
Raises:
| Type | Description |
|---|---|
QrelsVerificationError
|
If any topic is missing qrels |
Source code in src/autojudge_base/qrels/verification.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
no_extra_topics ¶
no_extra_topics() -> QrelsVerification
Verify no qrels exist for non-expected topics.
Raises:
| Type | Description |
|---|---|
QrelsVerificationError
|
If qrels exist for unknown topics |
Source code in src/autojudge_base/qrels/verification.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
no_duplicates ¶
no_duplicates() -> QrelsVerification
Verify no duplicate (topic_id, doc_id) pairs exist.
Raises:
| Type | Description |
|---|---|
QrelsVerificationError
|
If duplicates are found |
Source code in src/autojudge_base/qrels/verification.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
all ¶
all() -> QrelsVerification
Run all verification checks.
Checks run in order (fail-fast): 1. no_duplicates - no duplicate (topic_id, doc_id) pairs 2. complete_topics - every expected topic has qrels 3. no_extra_topics - no qrels for unknown topics
Returns:
| Type | Description |
|---|---|
QrelsVerification
|
self for chaining |
Source code in src/autojudge_base/qrels/verification.py
118 119 120 121 122 123 124 125 126 127 128 129 130 | |
autojudge_base.qrels.QrelsVerificationError ¶
Bases: Exception
Raised when qrels verification fails.
autojudge_base.qrels.write_qrel_file ¶
Write qrels in standard TREC format:
topic_id iteration doc_id grade
Notes: - The iteration field is always '0' (historical artifact, ignored by TREC tools). - Ordering is deterministic (sorted by topic_id, then doc_id).
Source code in src/autojudge_base/qrels/qrels.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |