From 457bf1838bbecc4a438257319d4a252d7f453b53 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 21 Jul 2026 18:46:15 +0800 Subject: [PATCH] fix: restore format_structure output normalization in the SDK index path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both legacy entry points deliberately finish with format_structure — whitelisting public fields, fixing key order, pruning empty 'nodes'. build_index skipped it, so the SDK stored raw trees: empty nodes lists on every markdown leaf, internal keys leaking into get_document output, and a different shape from the same document indexed via page_index(). --- pageindex/index/pipeline.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pageindex/index/pipeline.py b/pageindex/index/pipeline.py index 13dbbc4..b6a3cd2 100644 --- a/pageindex/index/pipeline.py +++ b/pageindex/index/pipeline.py @@ -67,7 +67,7 @@ def build_index(parsed: ParsedDocument, model: str = None, opt=None) -> dict: Routes to the appropriate strategy and runs enhancement.""" from .utils import (write_node_id, add_node_text, remove_structure_text, generate_summaries_for_structure, generate_doc_description, - create_clean_structure_for_description) + create_clean_structure_for_description, format_structure) from ..config import IndexConfig, max_concurrency_scope, llm_params_scope if opt is None: @@ -122,6 +122,12 @@ def build_index(parsed: ParsedDocument, model: str = None, opt=None) -> dict: if text_present and not opt.if_add_node_text: remove_structure_text(structure) + if strategy == "level_based": + order = ['title', 'node_id', 'line_num', 'summary', 'prefix_summary', 'text', 'nodes'] + else: + order = ['title', 'node_id', 'start_index', 'end_index', 'summary', 'text', 'nodes'] + result["structure"] = format_structure(structure, order=order) + return result