fix: restore format_structure output normalization in the SDK index path

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().
This commit is contained in:
Ray 2026-07-21 18:46:15 +08:00
parent 8c7f622112
commit 457bf1838b

View file

@ -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