Description of the Bug
The utility function _convert_sets_for_json runs Python's built-in sorted() function on the collections of pages and chunks. If the input documents contain mixed data types across different chunks—such as an integer for a page number (12) in one chunk and a string identifier ("appendix_a") in another—the sorted() function will throw a fatal TypeError because Python does not support direct less-than comparisons between strings and integers.
Steps to Reproduce
Pass a list of chunks where chunk_1 has {"page": 1, ...} and chunk_2 has {"page": "cover", ...}.
Run build_graph(chunks) or execute _convert_sets_for_json on a graph containing these mixed types.
Observe the TypeError: '<' not supported between instances of 'str' and 'int' crash.
Expected Behavior
The sorting mechanism should gracefully handle variation in metadata types without crashing the pipeline. It should apply a uniform string fallback key (e.g., key=str) during sorting to ensure arbitrary page or chunk metadata structures do not interrupt graph persistence.
Screenshots / Logs
No response
Environment
=
GSSoC '26
Description of the Bug
The utility function _convert_sets_for_json runs Python's built-in sorted() function on the collections of pages and chunks. If the input documents contain mixed data types across different chunks—such as an integer for a page number (12) in one chunk and a string identifier ("appendix_a") in another—the sorted() function will throw a fatal TypeError because Python does not support direct less-than comparisons between strings and integers.
Steps to Reproduce
Pass a list of chunks where chunk_1 has {"page": 1, ...} and chunk_2 has {"page": "cover", ...}.
Run build_graph(chunks) or execute _convert_sets_for_json on a graph containing these mixed types.
Observe the TypeError: '<' not supported between instances of 'str' and 'int' crash.
Expected Behavior
The sorting mechanism should gracefully handle variation in metadata types without crashing the pipeline. It should apply a uniform string fallback key (e.g., key=str) during sorting to ensure arbitrary page or chunk metadata structures do not interrupt graph persistence.
Screenshots / Logs
No response
Environment
=
GSSoC '26