Repository navigation
fix: read model text files as UTF-8 regardless of platform locale - #786
Open
Aditya17-bot wants to merge 1 commit into
Open
Aditya17-bot wants to merge 1 commit into
Aditya17-bot wants to merge 1 commit into
Conversation
open() without an encoding uses the locale encoding, which is cp1252 on
Windows. Model files are UTF-8, so Bm25(language=...) raised
UnicodeDecodeError for Russian, Greek and Arabic stopwords and silently
garbled German and French ones ("über" read as "über", so it was never
filtered). The same applied to vocab files, IDF files and tokenizer and
preprocessor configs.
Pass encoding="utf-8" to every text-mode open() in the package.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (8)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughPriority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to The affected model and vocabulary files are now read and written independently of the host locale, and the supplied tests cover non-ASCII text handling. No concrete merge-blocking risk is indicated. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
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.
open()withoutencoding=uses the locale encoding, which is cp1252 on Windows. Model files are UTF-8, so on Windows:SparseTextEmbedding("Qdrant/bm25", language="russian")(alsogreek,arabic) fails at init withUnicodeDecodeError: 'charmap' codec can't decode byte 0x8f.germanandfrenchload, but every stopword with an accent comes out garbled (überbecomesüber), so those stopwords are never filtered.The same bare
open()is used for miniCOIL/BM42 stopwords, the IF-SPLADE IDF file,VocabResolvervocab files, and the tokenizer/preprocessor JSON configs. Those configs can contain non-ASCII text too, e.g. SentencePiece's▁. This PR passesencoding="utf-8"to all 15 text-modeopen()calls in the package. Nothing changes on Linux/macOS, where the locale is already UTF-8.Reproduced on Windows 11 / Python 3.12 against the files in
Qdrant/bm25:With the fix,
language="russian"loads 151 stopwords, and"Das ist über alles"withlanguage="german"is all stopwords (empty embedding), as expected.Tests:
tests/test_text_file_encoding.pycovers BM25 stopwords in five languages,VocabResolvertxt/JSON round trips with non-ASCII words, andload_special_tokenswith▁. The test matrix runs onwindows-latest, so these guard the regression there.Note: #684 makes the same one-line change in
Bm25._load_stopwordsas part of Persian support, so whichever lands second has a trivial conflict on that line.