Skip to content

fix: add encoding="utf-8" to graph store persist/load methods#21360

Open
Grizouforever wants to merge 1 commit intorun-llama:mainfrom
Grizouforever:fix/utf8-encoding-graph-store-persist
Open

fix: add encoding="utf-8" to graph store persist/load methods#21360
Grizouforever wants to merge 1 commit intorun-llama:mainfrom
Grizouforever:fix/utf8-encoding-graph-store-persist

Conversation

@Grizouforever
Copy link
Copy Markdown

Description

Fixes #21109

SimplePropertyGraphStore.persist() / from_persist_path() and SimpleGraphStore.persist() / from_persist_path() open files without specifying encoding="utf-8". On Windows, Python's open() defaults to the system encoding (often cp1252), which causes UnicodeDecodeError / UnicodeEncodeError when the graph data contains non-ASCII characters.

Changes

  • Added encoding="utf-8" to all fs.open() calls in persist() and from_persist_path() for both SimplePropertyGraphStore and SimpleGraphStore
  • Fixed SimpleGraphStore.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 SimpleGraphStore class and the "rb" mode inconsistency.

… 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>
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SimplePropertyGraphStore can't persist utf-8 encoded chars on Windows

1 participant