Skip to content

API Reference parrot.knowledge.pageindex.builder

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.pageindex.builder

View source

PageIndex tree builder — LLM-agnostic port of the page_index pipeline.

Alias ConfigLoader

Re-exported from parrot.knowledge.pageindex.utils.ConfigLoader.

Alias DATA_FRAMING_INSTRUCTION

Re-exported from parrot.knowledge.pageindex.framing.DATA_FRAMING_INSTRUCTION.

Attribute DEFAULT_LLM_CONCURRENCY

Alias LayoutHeaders

Re-exported from parrot.knowledge.pageindex.layout.LayoutHeaders.

Alias LayoutProfile

Re-exported from parrot.knowledge.pageindex.layout.LayoutProfile.

Alias NoTextLayerError

Re-exported from parrot.knowledge.pageindex.layout.NoTextLayerError.

Alias PDFStructureError

Re-exported from parrot.knowledge.pageindex.layout.PDFStructureError.

Alias PageIndexDetection

Re-exported from parrot.knowledge.pageindex.schemas.PageIndexDetection.

Alias PageIndexLLMAdapter

Re-exported from parrot.knowledge.pageindex.llm_adapter.PageIndexLLMAdapter.

Alias PhysicalIndexFix

Re-exported from parrot.knowledge.pageindex.schemas.PhysicalIndexFix.

Alias Segment

Re-exported from parrot.knowledge.pageindex.segments.Segment.

Alias StructureReport

Re-exported from parrot.knowledge.pageindex.layout_structure.StructureReport.

Attribute TAGGED_PAGE_TOKEN_OVERHEAD

Alias TitleAppearanceCheck

Re-exported from parrot.knowledge.pageindex.schemas.TitleAppearanceCheck.

Alias TitleStartCheck

Re-exported from parrot.knowledge.pageindex.schemas.TitleStartCheck.

Alias TocCompletionCheck

Re-exported from parrot.knowledge.pageindex.schemas.TocCompletionCheck.

Alias TocDetectionResult

Re-exported from parrot.knowledge.pageindex.schemas.TocDetectionResult.

Alias UnreadablePDFError

Re-exported from parrot.knowledge.pageindex.layout.UnreadablePDFError.

Alias add_node_text

Re-exported from parrot.knowledge.pageindex.utils.add_node_text.

Function add_page_number_to_toc

Map section titles to physical indices in a document part.

add_page_number_to_toc(part: str | list[str], structure: list[dict] | dict, adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
part str | list[str]
structure list[dict] | dict
adapter PageIndexLLMAdapter

Returns: list[dict]

Alias add_page_offset_to_toc_json

Re-exported from parrot.knowledge.pageindex.utils.add_page_offset_to_toc_json.

Alias add_preface_if_needed

Re-exported from parrot.knowledge.pageindex.utils.add_preface_if_needed.

Alias analyze_layout

Re-exported from parrot.knowledge.pageindex.layout.analyze_layout.

Alias build_node_markdown_map

Re-exported from parrot.knowledge.pageindex.pdf_to_markdown.build_node_markdown_map.

Function build_page_index

Build a PageIndex tree from a PDF using layout candidates before LLM fallback.

build_page_index(doc: str | BytesIO, adapter: Optional[PageIndexLLMAdapter] = None, options: dict | config | None = None, light_adapter: Optional[PageIndexLLMAdapter] = None, llm_concurrency: int = DEFAULT_LLM_CONCURRENCY) -> dict

Parameter Type Default Description
doc str | BytesIO
adapter Optional[PageIndexLLMAdapter] None
options dict | config | None None
light_adapter Optional[PageIndexLLMAdapter] None
llm_concurrency int DEFAULT_LLM_CONCURRENCY

Returns: dict

Alias build_structure

Re-exported from parrot.knowledge.pageindex.layout_structure.build_structure.

Alias calculate_page_offset

Re-exported from parrot.knowledge.pageindex.utils.calculate_page_offset.

Function check_if_toc_extraction_is_complete

Check if a TOC extraction is complete.

check_if_toc_extraction_is_complete(content: str, toc: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
content str
toc str
adapter PageIndexLLMAdapter

Returns: str

Function check_if_toc_transformation_is_complete

Check if a TOC transformation is complete.

check_if_toc_transformation_is_complete(content: str, toc: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
content str
toc str
adapter PageIndexLLMAdapter

Returns: str

Function check_title_appearance

Check if a section title appears on its assigned page.

check_title_appearance(item: dict, page_list: list[tuple[str, int]], start_index: int = 1, adapter: PageIndexLLMAdapter = None) -> dict

Parameter Type Default Description
item dict
page_list list[tuple[str, int]]
start_index int 1
adapter PageIndexLLMAdapter None

Returns: dict

Function check_title_appearance_in_start

Check if a section starts at the beginning of a page.

check_title_appearance_in_start(title: str, page_text: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
title str
page_text str
adapter PageIndexLLMAdapter

Returns: str

Function check_title_appearance_in_start_concurrent

Concurrently check title starts for all items.

check_title_appearance_in_start_concurrent(structure: list[dict], page_list: list[tuple[str, int]], adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
structure list[dict]
page_list list[tuple[str, int]]
adapter PageIndexLLMAdapter

Returns: list[dict]

Function check_toc

Check for TOC presence and extract if found.

check_toc(page_list: list[tuple[str, int]], opt: config, adapter: PageIndexLLMAdapter, light_adapter: Optional[PageIndexLLMAdapter] = None) -> dict[str, Any]

Parameter Type Default Description
page_list list[tuple[str, int]]
opt config
adapter PageIndexLLMAdapter
light_adapter Optional[PageIndexLLMAdapter] None

Returns: dict[str, Any]

Alias convert_page_to_int

Re-exported from parrot.knowledge.pageindex.utils.convert_page_to_int.

Alias convert_physical_index_to_int

Re-exported from parrot.knowledge.pageindex.utils.convert_physical_index_to_int.

Alias create_clean_structure_for_description

Re-exported from parrot.knowledge.pageindex.utils.create_clean_structure_for_description.

Function detect_page_index

Detect if page numbers/indices are present in the TOC.

detect_page_index(toc_content: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
toc_content str
adapter PageIndexLLMAdapter

Returns: str

Alias extract_json

Re-exported from parrot.knowledge.pageindex.utils.extract_json.

Alias extract_markdown_per_page

Re-exported from parrot.knowledge.pageindex.pdf_to_markdown.extract_markdown_per_page.

Alias extract_matching_page_pairs

Re-exported from parrot.knowledge.pageindex.utils.extract_matching_page_pairs.

Function extract_toc_content

Extract full table of contents from raw text.

extract_toc_content(content: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
content str
adapter PageIndexLLMAdapter

Returns: str

Function find_toc_pages

Find the contiguous page range that contains the table of contents.

Probes the first toc_check_page_num pages concurrently (rather than serially) and then walks the result vector to find the first run of consecutive yes pages. If that run reaches the end of the initial window the scan is extended forward in batches of extension_size so a TOC that straddles the boundary is still captured intact.

LLM-call count is identical to the sequential implementation in the worst case; wall-time is dominated by the slowest single probe rather than the sum.

find_toc_pages(start_page_index: int, page_list: list[tuple[str, int]], opt: config, adapter: PageIndexLLMAdapter, extension_size: int = 5) -> list[int]

Parameter Type Default Description
start_page_index int
page_list list[tuple[str, int]]
opt config
adapter PageIndexLLMAdapter
extension_size int 5

Returns: list[int]

Function fix_incorrect_toc

Fix incorrect TOC entries by re-searching nearby pages.

fix_incorrect_toc(toc_with_page_number: list[dict], page_list: list[tuple[str, int]], incorrect_results: list[dict], start_index: int = 1, adapter: PageIndexLLMAdapter = None) -> tuple[list[dict], list[dict]]

Parameter Type Default Description
toc_with_page_number list[dict]
page_list list[tuple[str, int]]
incorrect_results list[dict]
start_index int 1
adapter PageIndexLLMAdapter None

Returns: tuple[list[dict], list[dict]]

Function fix_incorrect_toc_with_retries

Fix incorrect TOC entries with retries.

fix_incorrect_toc_with_retries(toc_with_page_number: list[dict], page_list: list[tuple[str, int]], incorrect_results: list[dict], start_index: int = 1, max_attempts: int = 3, adapter: PageIndexLLMAdapter = None) -> tuple[list[dict], list[dict]]

Parameter Type Default Description
toc_with_page_number list[dict]
page_list list[tuple[str, int]]
incorrect_results list[dict]
start_index int 1
max_attempts int 3
adapter PageIndexLLMAdapter None

Returns: tuple[list[dict], list[dict]]

Alias frame_text

Re-exported from parrot.knowledge.pageindex.framing.frame_text.

Function generate_doc_description

Generate a one-sentence document description.

generate_doc_description(structure: Any, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
structure Any
adapter PageIndexLLMAdapter

Returns: str

Function generate_node_summary

Generate a summary for a single node.

generate_node_summary(node: dict, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
node dict
adapter PageIndexLLMAdapter

Returns: str

Function generate_summaries_for_structure

Generate summaries for all nodes in a tree structure.

generate_summaries_for_structure(structure: Any, adapter: PageIndexLLMAdapter) -> Any

Parameter Type Default Description
structure Any
adapter PageIndexLLMAdapter

Returns: Any

Function generate_toc_continue

Continue TOC generation for the next document part.

generate_toc_continue(toc_content: list[dict], part: str, adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
toc_content list[dict]
part str
adapter PageIndexLLMAdapter

Returns: list[dict]

Function generate_toc_init

Generate initial TOC from document content when no TOC exists.

generate_toc_init(part: str, adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
part str
adapter PageIndexLLMAdapter

Returns: list[dict]

Alias get_json_content

Re-exported from parrot.knowledge.pageindex.utils.get_json_content.

Alias get_page_tokens

Re-exported from parrot.knowledge.pageindex.utils.get_page_tokens.

Alias get_pdf_name

Re-exported from parrot.knowledge.pageindex.utils.get_pdf_name.

Attribute logger

Function meta_processor

Main processing orchestrator for different TOC modes.

meta_processor(page_list: list[tuple[str, int]], mode: str | None = None, toc_content: str | None = None, toc_page_list: list[int] | None = None, start_index: int = 1, opt: config | None = None, adapter: PageIndexLLMAdapter = None, light_adapter: Optional[PageIndexLLMAdapter] = None) -> list[dict]

Parameter Type Default Description
page_list list[tuple[str, int]]
mode str | None None
toc_content str | None None
toc_page_list list[int] | None None
start_index int 1
opt config | None None
adapter PageIndexLLMAdapter None
light_adapter Optional[PageIndexLLMAdapter] None

Returns: list[dict]

Alias page_list_to_group_text

Re-exported from parrot.knowledge.pageindex.utils.page_list_to_group_text.

Alias page_structure

Re-exported from parrot.knowledge.pageindex.layout_structure.page_structure.

Alias post_processing

Re-exported from parrot.knowledge.pageindex.utils.post_processing.

Function process_large_node_recursively

Recursively split large nodes into sub-trees.

process_large_node_recursively(node: dict, page_list: list[tuple[str, int]], opt: config, adapter: PageIndexLLMAdapter, light_adapter: Optional[PageIndexLLMAdapter] = None) -> dict

Parameter Type Default Description
node dict
page_list list[tuple[str, int]]
opt config
adapter PageIndexLLMAdapter
light_adapter Optional[PageIndexLLMAdapter] None

Returns: dict

Function process_no_toc

Process document without existing TOC.

process_no_toc(page_list: list[tuple[str, int]], start_index: int = 1, adapter: PageIndexLLMAdapter = None) -> list[dict]

Parameter Type Default Description
page_list list[tuple[str, int]]
start_index int 1
adapter PageIndexLLMAdapter None

Returns: list[dict]

Function process_none_page_numbers

Fill in missing physical indices for items that lack them.

process_none_page_numbers(toc_items: list[dict], page_list: list[tuple[str, int]], start_index: int = 1, adapter: PageIndexLLMAdapter = None) -> list[dict]

Parameter Type Default Description
toc_items list[dict]
page_list list[tuple[str, int]]
start_index int 1
adapter PageIndexLLMAdapter None

Returns: list[dict]

Function process_toc_no_page_numbers

Process TOC that exists but lacks page numbers.

process_toc_no_page_numbers(toc_content: str, toc_page_list: list[int], page_list: list[tuple[str, int]], start_index: int = 1, adapter: PageIndexLLMAdapter = None) -> list[dict]

Parameter Type Default Description
toc_content str
toc_page_list list[int]
page_list list[tuple[str, int]]
start_index int 1
adapter PageIndexLLMAdapter None

Returns: list[dict]

Function process_toc_with_page_numbers

Process TOC that has page numbers.

process_toc_with_page_numbers(toc_content: str, toc_page_list: list[int], page_list: list[tuple[str, int]], toc_check_page_num: int = 20, adapter: PageIndexLLMAdapter = None) -> list[dict]

Parameter Type Default Description
toc_content str
toc_page_list list[int]
page_list list[tuple[str, int]]
toc_check_page_num int 20
adapter PageIndexLLMAdapter None

Returns: list[dict]

Alias remove_page_number

Re-exported from parrot.knowledge.pageindex.utils.remove_page_number.

Alias remove_structure_text

Re-exported from parrot.knowledge.pageindex.utils.remove_structure_text.

Alias score_bookmarks

Re-exported from parrot.knowledge.pageindex.layout_structure.score_bookmarks.

Alias score_layout

Re-exported from parrot.knowledge.pageindex.layout_structure.score_layout.

Alias segment_pages

Re-exported from parrot.knowledge.pageindex.segments.segment_pages.

Function single_toc_item_index_fixer

Find the correct physical index for a misaligned section.

single_toc_item_index_fixer(section_title: str, content: str, adapter: PageIndexLLMAdapter) -> int | None

Parameter Type Default Description
section_title str
content str
adapter PageIndexLLMAdapter

Returns: int | None

Alias structure_to_list

Re-exported from parrot.knowledge.pageindex.utils.structure_to_list.

Function toc_detector_single_page

Detect if a page contains a table of contents.

toc_detector_single_page(content: str, adapter: PageIndexLLMAdapter) -> str

Parameter Type Default Description
content str
adapter PageIndexLLMAdapter

Returns: str

Function toc_extractor

Extract TOC content and check for page indices.

toc_extractor(page_list: list[tuple[str, int]], toc_page_list: list[int], adapter: PageIndexLLMAdapter) -> dict[str, Any]

Parameter Type Default Description
page_list list[tuple[str, int]]
toc_page_list list[int]
adapter PageIndexLLMAdapter

Returns: dict[str, Any]

Function toc_index_extractor

Add physical_index to TOC items from tagged document content.

toc_index_extractor(toc: list[dict], content: str, adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
toc list[dict]
content str
adapter PageIndexLLMAdapter

Returns: list[dict]

Function toc_transformer

Transform raw TOC text into structured JSON.

toc_transformer(toc_content: str, adapter: PageIndexLLMAdapter) -> list[dict]

Parameter Type Default Description
toc_content str
adapter PageIndexLLMAdapter

Returns: list[dict]

Function tree_parser

Parse page list into a hierarchical tree.

tree_parser(page_list: list[tuple[str, int]], opt: config, adapter: PageIndexLLMAdapter, light_adapter: Optional[PageIndexLLMAdapter] = None) -> list[dict]

Parameter Type Default Description
page_list list[tuple[str, int]]
opt config
adapter PageIndexLLMAdapter
light_adapter Optional[PageIndexLLMAdapter] None

Returns: list[dict]

Alias validate_and_truncate_physical_indices

Re-exported from parrot.knowledge.pageindex.utils.validate_and_truncate_physical_indices.

Function verify_toc

Verify TOC accuracy by checking title appearances.

Checks a random sample of indexed TOC items rather than every entry — for long documents (e.g. 100+ TOC items) the full sweep was costing one LLM call per section. sample_size caps the population; when the list has fewer indexed items, every item is checked.

verify_toc(page_list: list[tuple[str, int]], list_result: list[dict], start_index: int = 1, adapter: PageIndexLLMAdapter = None, sample_size: int = 20) -> tuple[float, list[dict]]

Parameter Type Default Description
page_list list[tuple[str, int]]
list_result list[dict]
start_index int 1
adapter PageIndexLLMAdapter None
sample_size int 20

Returns: tuple[float, list[dict]]

Alias write_node_id

Re-exported from parrot.knowledge.pageindex.utils.write_node_id.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally