fix: add encoding="utf-8" to graph store persist/load methods#21360
Open
Grizouforever wants to merge 1 commit intorun-llama:mainfrom
Open
fix: add encoding="utf-8" to graph store persist/load methods#21360Grizouforever wants to merge 1 commit intorun-llama:mainfrom
Grizouforever wants to merge 1 commit intorun-llama:mainfrom
Conversation
… methods SimplePropertyGraphStore and SimpleGraphStore open files for persistence without specifying encoding, which causes failures on Windows where the default encoding may not be UTF-8. This adds explicit encoding="utf-8" to all fs.open() calls in persist() and from_persist_path() for both graph store classes. Also fixes SimpleGraphStore.from_persist_path using "rb" (binary mode) instead of text mode, which is inconsistent with json.load() expecting a text stream on some fsspec backends. Fixes run-llama#21109 Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Description
Fixes #21109
SimplePropertyGraphStore.persist()/from_persist_path()andSimpleGraphStore.persist()/from_persist_path()open files without specifyingencoding="utf-8". On Windows, Python'sopen()defaults to the system encoding (oftencp1252), which causesUnicodeDecodeError/UnicodeEncodeErrorwhen the graph data contains non-ASCII characters.Changes
encoding="utf-8"to allfs.open()calls inpersist()andfrom_persist_path()for bothSimplePropertyGraphStoreandSimpleGraphStoreSimpleGraphStore.from_persist_path()using binary mode ("rb") instead of text mode —json.load()expects a text stream, and binary mode is inconsistent with the write path which uses"w"Files changed
llama-index-core/llama_index/core/graph_stores/simple_labelled.py(SimplePropertyGraphStore)llama-index-core/llama_index/core/graph_stores/simple.py(SimpleGraphStore)Related issue
Closes #21109 — same root cause as PR #21111 (stale since March 2025), but this PR also fixes the older
SimpleGraphStoreclass and the"rb"mode inconsistency.