Repository navigation
fix(novelty): the faithfulness check sees the heading and lead-in of the cited spans - #1017
Conversation
…the cited spans (intel#1009) verify_atoms judged an atom against its cited spans alone, so a list item lost its lead-in ("Use dpnp for:") and a sentence like "Prefer this over plain NumPy" lost the sentence naming its subject, and supported atoms read as unsupported or distorted. The prompt now has a CONTEXT block with the heading path of the first cited span and its lead-in: for a list item or table row the nearest earlier span that is neither, otherwise the span just before it. The block is stated as only for resolving references; SOURCE is still the cited text and a changed polarity or number stays distorted or unsupported. The prompt and context helper move to novelty/verify_context.py to keep atoms.py under the 800-line cap. Cached verdicts for the old prompt are asked again. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Found no critical or high issues in this commit. CI at `28778b0`: 1 failing, 1 still running, 19 passing, 2 skipped
Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask. Lower-severity findings not shown (1)1 medium Review details
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1017 +/- ##
========================================
Coverage 95.89% 95.90%
========================================
Files 448 450 +2
Lines 59289 59485 +196
Branches 10224 10256 +32
========================================
+ Hits 56857 57048 +191
- Misses 1511 1513 +2
- Partials 921 924 +3
🚀 New features to boost your workflow:
|
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
vchamarthi
left a comment
There was a problem hiding this comment.
🟡 Not approved yet · reviewed e11cd64
Next: @antonwolfy: settle 1 open question (below). 1 nit optional.
Blocking
- Open question for @antonwolfy: A sentence after a list or table takes the last list item or table row as its lead-in. Decide whether a sentence should also walk back over list items and table rows to reach the lead-in.
Verified on e11cd64: ✅ changed tests: 5 passed, fail on main · ✅ full suite with main merged in: 23938 passed · ✅ merges onto main ·
9 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| List item lead-in | The five tests in tests/test_novelty_verify_context.py pass on the head. A list item gets its heading and the lead-in before its list, a sentence gets the span before it, and a span with no predecessor gets (none) |
tests on the head |
| Tests on main | The same five tests fail on main, where the prompt has no CONTEXT block | same tests on main |
| Merge | The PR merges onto main with no conflict | merge onto main |
| Full test run | The full test run passes with main merged in: 23900 passed, 85 skipped, no failures | full suite, main merged in |
| Verifier wiring | Replacing the context= argument that verify_atoms passes with (none) fails three of the five tests, so the call is pinned |
broke the code, tests caught it |
| Crlf and non-ascii | A CRLF document with a non-ASCII heading and lead-in gives the lead-in Use ß for: with no stray carriage return |
ran it, edge input (text) |
| Span order and duplicates | Cited span ids in any order, with a duplicate, give the lead-in of the first span in document order, and an empty list gives (none) |
ran it, edge input (collections) |
| Unknown span ids | An atom whose span ids match no span is still counted as supported, and its prompt carries (none) as the context |
ran it, edge input (none) |
| Response cache | The response cache key is a hash of the request text, so a prompt with a new CONTEXT block gets a new key and the old cached verdicts are not replayed | ran it |
Settles the review thread on context_for: no test passed span ids that match no span, so returning None instead of "(none)" left the suite green. The new test drives verify_atoms with an unknown id and asserts the CONTEXT block is "(none)". Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@vchamarthi (#1017 (review)): The open question is whether a sentence after a list or table should walk back to the lead-in before it. It does not: the sentence takes the span right before it (the last item or row), the same rule as any other sentence, and the code is unchanged. The text right before a sentence is the nearest place its "these" or "both" can point, and the lead-in is often a few spans away. The nit is settled in 136f12f. |
…ontext Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…tion Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…mparable Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…n after a table Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟢 LGTM · re-checked 3471f57 · nothing required from @antonwolfy
🔀 Merge: safe now · merges cleanly into current main, 13 commits behind; its tests pass on the merge · no open PR conflicts with it
✅ make ci-local --offline: 23,918 passed · schema_compat fails from main drift (schemas added by #829), not from this PR · ✅ context_for on tables, headings and sections: run by hand
The earlier points are fixed; list, table and "this" spans now get the context they need.
Fixed in this branch, up to 3471f57:
- A table row had no header row in its context: 9b9c91c adds
Table header:, and 3471f57 keeps it to table rows, with tests. - The lead-in could be a heading or come from another section: dd23298 skips both, with a test.
- The changelog did not say old faithfulness counts are not comparable: 13260b9 says so.
…f an earlier one Settles the review point that the header lookup walked through the blank line between two tables, so a row of the second table got the first table's header. segment drops blank lines, so the table start is now the delimiter row (|---|---|): the header is the row before the nearest delimiter row in the unbroken run of table rows. A header row itself and a run without a delimiter row get no Table header. Adds a two-table regression test and a header-row test, and names the behaviour in the changelog fragment. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@vlad-perevezentsev (#1017 (review)): Approval that recaps the earlier fixes; it asks for no change. The |
|
Review points answered at codecov has not reported on this head yet. |
A data row of single dashes (`| - | - |`) was taken for the delimiter row, so the row after it got the wrong table header and the row before it none. Delimiter cells now need at least two dashes; a test pins both neighbours of such a row. Signed-off-by: vchamarthi <venkata.sai.gireesh.chamarthi@intel.com>
|
🟢 Ready for re-review · 1 commit on Next: a re-review of the new head. Nothing needed from @antonwolfy. Changes
Verified on the new head: ✅ 1/1 tests fail before the fix, pass after · ✅ full suite with main merged in: 24248 passed · ✅ second reader: nothing raised What each test shows
|
xaleryb
left a comment
There was a problem hiding this comment.
Approved on 28778b0. Read the commits after the earlier approvals (e550111, 28778b0) and ran them on a Linux host merged with current main: the 13 tests of test_novelty_verify_context.py fail against main's source and pass on the merged tree (3 runs); 3,403 novelty/verify/context/span tests pass; ruff and mypy are clean. Probed: a row of the second of two tables gets its own header, aligned delimiters work, a dash-only data row (| - | - |) is not taken for a delimiter. Known and accepted: a delimiter row of single dashes (|-|-|) gives no Table header. CI is green, no open threads.
Summary
verify_atomsjudged each atom against the text of its cited spans alone. Onmaina list item is judged without its lead-in and a sentence without the sentence that names its subject, so atoms the skill states read asunsupportedordistorted. In the report on #1009, 11 of 132 atoms were flagged and a maintainer found none a real distortion. For example the atom "dpnp is recommended for large arrays (>10,000 elements)" was shown only- Large arrays (>10,000 elements)(lead-inUse dpnp for:missing), and "Prefer dpnp over plain NumPy when the arrays are large" only "Prefer this over plain NumPy when the arrays are large ..." (the Purpose sentence that says "this" is dpnp missing).The fix is the issue's first option: the prompt gets a CONTEXT block holding the heading path of the first cited span and its lead-in (for a list item or table row, the nearest earlier span that is neither; otherwise the span just before it). The block says it only resolves references ("this", "both", a list's lead-in) and never supplies the claim; the prompt also says a changed polarity, number or qualifier stays
distortedorunsupportedeven when the context words it otherwise. SOURCE is still the cited text only. The case in the issue where the needed text comes after the cited span (the code block and the line after "Three commands answer most questions") is not covered, and is tracked in #1016.Closes #1009
Changes
dokimi/dokimi/novelty/verify_context.py(new): the faithfulness prompt with its CONTEXT block, andcontext_for, which returnsHeading: <path>,Lead-in: <text>and, for a table row,Table header: <row>lines, or(none). The header is the row before the nearest delimiter row (|---|---|) of the unbroken run of table rows, becausesegmentdrops the blank line between two tables; a row of the second table gets the second table's header, and a header row or a run with no delimiter row gets none. It is a separate module becauseatoms.pywould pass the 800-line cap.dokimi/dokimi/novelty/atoms.py:verify_atomsbuilds the prompt with the context; the tally,max_atoms, theuncheckedhandling and the cache rule are unchanged.dokimi/tests/test_novelty_verify_context.py: a fake client captures the prompt (list item with lead-in and heading, sentence with its predecessor,(none), an atom citing no known span, context not duplicating cited spans, SOURCE holding only cited text).Risk
The verifier prompt changes, so cached faithfulness verdicts for the old prompt are asked again once (paid calls on the next
skill novelty atoms/analyzerun). Verdicts of atoms whose cited spans were already self-contained should not change; ones that depended on a heading or lead-in now readsupported. The prompt grows by the heading path and one span per atom. The open PR #954 also editsatoms.py, but only--max-tokenswording in docstrings and messages far fromverify_atoms, so a merge with it should not conflict.Testing
On a Linux review host, at
e550111d(onmain52160e9):make ci-local: 0 failed, 36 passed, 14 skipped (matrix legs on other Pythons, semgrep, conda-forge, fuzz, jobs not run on a PR). 23973 tests passed, 19 skipped.| Flag | Default |then, after a blank line,| Flag | Maximum |), citing--y: before, the context saidTable header: | Flag | Default |; nowTable header: | Flag | Maximum |. On the previous head the two new two-table tests fail; with the guard that gives a header row noTable headerremoved,test_the_header_row_of_the_second_table_gets_no_table_headerfails.main's code the new test file fails: 5 failed, onthe faithfulness prompt has no CONTEXT block.Noneinstead of(none)when no cited span id is known (the unknown-id test), skipping a run of list items when looking for the lead-in (list item test), dropping the heading line, using the last cited span instead of the first, returning an empty string instead of(none), returning no lead-in, putting extra text in SOURCE.tests/test_novelty_permanent_stop.pyandtests/test_novelty_silent_defaults.py, which driveverify_atoms, pass unchanged.Open questions
None.
Revert
A plain revert restores the old prompt and the cited-spans-only check. Nothing is stored; saved atoms files keep the
faithfulnesslabels they were written with.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)