From 9bcc7cff891efb21266d3757c031a10279b9a0de Mon Sep 17 00:00:00 2001 From: Savio Dsouza Date: Wed, 15 Jul 2026 19:18:09 +0530 Subject: [PATCH] Refactor TOC entry update logic in page_index.py --- pageindex/page_index.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pageindex/page_index.py b/pageindex/page_index.py index 6521e63..235144b 100644 --- a/pageindex/page_index.py +++ b/pageindex/page_index.py @@ -755,22 +755,17 @@ def process_toc_no_page_numbers(toc_content, toc_page_list, page_list, start_in toc_with_page_number = copy.deepcopy(toc_content) for group_text in group_texts: - current_entries = { - entry["structure"]: entry - for entry in toc_with_page_number - } llm_result = add_page_number_to_toc(group_text, toc_with_page_number, model) + if len(llm_result) != len(toc_with_page_number): + raise ValueError( + "LLM returned a different number of TOC entries than expected." + ) valid_indices = _extract_chunk_marker_set(group_text) - for update in llm_result: - key = update.get("structure") + for idx, current in enumerate(toc_with_page_number): + update = llm_result[idx] - if key not in current_entries: - continue - - current = current_entries[key] - if current.get("physical_index") is not None: continue @@ -785,7 +780,6 @@ def process_toc_no_page_numbers(toc_content, toc_page_list, page_list, start_in continue current["physical_index"] = raw - toc_with_page_number = list(current_entries.values()) logger.info(f'add_page_number_to_toc: {toc_with_page_number}') toc_with_page_number = convert_physical_index_to_int(toc_with_page_number)