Repository navigation
fix(retrieval): map Arabic-Indic and other non-ASCII digits to ASCII - #44
Merged
Merged
Conversation
#33 made tokenize() Unicode-aware and joined thousands separators in fidelity, but non-ASCII decimal digits stayed as-is: an Arabic source writing '١٢٬٥٠٠' and a claim writing '12,500' tokenized to '١٢٥٠٠' and '12500', so a correct claim was flagged missing_numbers=['12500'] and its content_cov dropped. BM25 likewise could not find '٢٠٢٤' from a '2024' query. The non-ASCII fold path now maps every Unicode decimal digit (Nd: Arabic-Indic, Persian, Devanagari, ...) to its ASCII digit. The ASCII fast path is unchanged. Follow-up to review F10 / the minor fidelity number item (T8). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What changed
Follow-up to #33 (review F10 + the minor
fidelitynumber item, task T8). #33 already shipped the Unicode-aware tokenizer (casefold, NFKD mark-folding, CJK bigrams) and thousands-separator joining ('12,500' == '12500', including the Arabic separator U+066C). Its own follow-up list noted one gap left open: Arabic-Indic digits were not mapped to ASCII.Reproduced on
origin/main(f497835):grounding_score('بلغت الإيرادات 12,500 دولار [S1].', 'بلغت الإيرادات ١٢٬٥٠٠ دولار')→missing_numbers: ['12500'],num_cov: 0.0,content_cov: 0.75. A correct claim is flagged as a fabricated statistic and fed to self-repair.tokenize('عام ٢٠٢٤')→['عام', '٢٠٢٤'], so a BM25 query for2024can't find an Arabic document that writes the year in Arabic-Indic digits.Fix:
retrieval._fold(the non-ASCII path only) now maps every Unicode decimal digit (category Nd: Arabic-Indic U+0660–0669, Persian U+06F0–06F9, Devanagari, …) to its ASCII digit viaunicodedata.decimal. The ASCII fast path is untouched.fidelity.tokenizealready routes through it, so the grouped-number join plus the digit map makes١٢٬٥٠٠≡12,500≡12500. The onlyfidelity.pychange is the module docstring.Files:
passiveworkers/retrieval.py,passiveworkers/fidelity.py(docstring),tests/test_fidelity.py,tests/test_retrieval.py.Tests (fail on old code)
test_fidelity.py::test_arabic_indic_digits_match_ascii_digitstest_retrieval.py::test_tokenize_maps_non_ascii_digits_to_asciitest_retrieval.py::test_bm25_finds_arabic_indic_year_from_ascii_queryI checked this by running them with
retrieval.py/fidelity.pyreverted toorigin/main:3 failed, 41 passed. With the fix:44 passed.Verification (venv with
.[all,dev], Python 3.12)python -m py_compile $(git ls-files '*.py')→ exit 0ruff check . && pytest tests/ -q --cov=passiveworkers --cov-fail-under=75→ exit 0. Output:All checks passed!,743 passed, 1 skipped,Total coverage: 83.39%.Not verified / known limits
वर्ष→वरष). Query and document fold the same way, so matching still works, but tokens aren't real words. Arabic stop-words are still not filtered. Thai and other unspaced non-CJK scripts are still not segmented.٤٫٢) splits like ASCII4.2does. That is consistent with the existing decimal policy (significant_numbersignores decimals).🤖 Generated with Claude Code