Repository navigation
fix: granite33 citation spans wrong for duplicate sentences (#851) - #872
Merged
Merged
Conversation
…ve-computing#851) str.find() without an offset always returned the first occurrence, so when the same sentence appeared more than once in the response, every citation after the first got response_begin/response_end pointing at the first occurrence. Introduce search_offset that advances past each consumed sentence. When find() misses after search_offset the sentence appears only once (multiple citations on one sentence); fall back to searching from the start so those citations share the correct span. Adds two regression tests to TestAddCitationResponseSpans: - test_duplicate_sentences_each_get_own_span - test_multiple_citations_on_same_sentence_share_span Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
Contributor
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
Contributor
Author
planetf1
enabled auto-merge
April 16, 2026 11:29
Merged
via the queue into
generative-computing:main
with commit Apr 20, 2026
0fd342e
16 of 17 checks passed
akihikokuroda
pushed a commit
to akihikokuroda/mellea
that referenced
this pull request
May 27, 2026
…ve-computing#851) (generative-computing#872) str.find() without an offset always returned the first occurrence, so when the same sentence appeared more than once in the response, every citation after the first got response_begin/response_end pointing at the first occurrence. Introduce search_offset that advances past each consumed sentence. When find() misses after search_offset the sentence appears only once (multiple citations on one sentence); fall back to searching from the start so those citations share the correct span. Adds two regression tests to TestAddCitationResponseSpans: - test_duplicate_sentences_each_get_own_span - test_multiple_citations_on_same_sentence_share_span Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: granite33 citation spans wrong for duplicate sentences
Type of PR
Description
_add_citation_response_spansusedstr.find(sentence)without anoffset, so it always matched the first occurrence of a sentence in
the response. When the same sentence appeared more than once — each
cited separately — every citation after the first ended up pointing at
the wrong span.
Example: a response containing "The sky is blue." twice, once
cited by document 1 and once by document 2:
The fix introduces
search_offsetthat advances past each consumedsentence. If
find()returns nothing after the offset the sentenceappears only once in the response (multiple citations on the same
sentence); the code falls back to searching from the start so those
citations correctly share the same span.
Note: the related
response_endoff-by-one (using the full responselength instead of the sentence length) was already fixed in #845.
Performance
No meaningful impact:
find(text, offset)scans fromoffsetrather than from the start, so it examines less of the stringthan the original
find(text).find()calls — when the offset overshoots(e.g. multiple citations on the same sentence) we do one extra call.
This path is unusual and both calls operate on C-level Boyer-Moore-Horspool
search over a few hundred characters at most.
characters; the citation count is small (single digits in practice).
nltk.sent_tokenizedominates thisfunction by orders of magnitude; the
str.find()calls are negligibleby comparison.
Testing
Attribution