Description of the Bug
The build_graph function calls _convert_sets_for_json(graph) immediately before returning the graph object. Because Python objects are passed by reference, this permanently mutates the graph's internal node and edge attributes (pages and chunks) from mutable Python set objects into sorted list objects. If this graph object is kept in memory to process additional chunks later, subsequent calls will attempt to invoke .add() on a list, resulting in an unhandled AttributeError crash.
Steps to Reproduce
Initialize or pass a list of chunks to build_graph(chunks).
Keep the returned graph object in memory.
Attempt to process a new batch of text chunks using the same graph object via a loop or sequential function calls.
Observe the unhandled exception when an entity is encountered a second time.
Expected Behavior
The core nx.Graph object should maintain its data types (set) consistently throughout its in-memory lifecycle so it can be appended to or modified safely. Data type conversion for serialization constraints should only happen on a transient copy of the graph or natively during the serialization routine inside save_graph.
Screenshots / Logs
No response
Environment
GSSoC '26
Description of the Bug
The build_graph function calls _convert_sets_for_json(graph) immediately before returning the graph object. Because Python objects are passed by reference, this permanently mutates the graph's internal node and edge attributes (pages and chunks) from mutable Python set objects into sorted list objects. If this graph object is kept in memory to process additional chunks later, subsequent calls will attempt to invoke .add() on a list, resulting in an unhandled AttributeError crash.
Steps to Reproduce
Initialize or pass a list of chunks to build_graph(chunks).
Keep the returned graph object in memory.
Attempt to process a new batch of text chunks using the same graph object via a loop or sequential function calls.
Observe the unhandled exception when an entity is encountered a second time.
Expected Behavior
The core nx.Graph object should maintain its data types (set) consistently throughout its in-memory lifecycle so it can be appended to or modified safely. Data type conversion for serialization constraints should only happen on a transient copy of the graph or natively during the serialization routine inside save_graph.
Screenshots / Logs
No response
Environment
GSSoC '26