Skip to content

API Reference parrot.knowledge.pageindex.layout_structure

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

parrot.knowledge.pageindex.layout_structure

View source

Deterministic PDF structure candidates (FEAT-845 M3): bookmarks, printed headings, page fallback.

Pure functions over a LayoutProfile and the revision's Segment list — no I/O.

Class CandidateScore

Confidence of one deterministic structure candidate.

Fields:

Field Type Default Description
source Literal['bookmarks', 'layout']
confidence float
entries int
anchored int
rejected Optional[str] None
dropped int 0

Alias LayoutProfile

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

Attribute MAX_HEADINGS_PER_PAGE

Attribute MAX_HEADING_WORDS

Attribute MIN_CONTAINED_CHARS

Alias Segment

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

Alias StructureMode

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

Class StructureReport

How a PDF's structure was chosen (returned by the builder and import_pdf).

Fields:

Field Type Default Description
source StructureSource
mode StructureMode
min_confidence float
confidence Optional[float] None
candidates list[CandidateScore]
inserted_headings int 0
body_size Optional[int] None
running_lines int 0
llm_used bool False
llm_error Optional[str] None

Class StructureResult

A chosen deterministic structure: PageIndex nodes carrying a transient anchor.

Fields:

Field Type Default Description
source StructureSource
structure list[dict]
report StructureReport

Alias StructureSource

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

Function build_structure

Return the selected deterministic structure or None when no candidate qualifies.

build_structure(profile: LayoutProfile, segments: Sequence[Segment], *, mode: StructureMode = 'auto', min_confidence: float = 0.6) -> Optional[StructureResult]

Parameter Type Default Description
profile LayoutProfile
segments Sequence[Segment]
mode StructureMode 'auto'
min_confidence float 0.6

Returns: Optional[StructureResult]

Function heading_title

Remove ATX and emphasis markers and collapse whitespace.

heading_title(text: str) -> str

Parameter Type Default Description
text str

Returns: str

Function insert_layout_headings

Apply the hybrid rule by inserting compatible unbookmarked layout headings.

insert_layout_headings(bookmark_items: list[dict], profile: LayoutProfile, segments: Sequence[Segment]) -> tuple[list[dict], int]

Parameter Type Default Description
bookmark_items list[dict]
profile LayoutProfile
segments Sequence[Segment]

Returns: tuple[list[dict], int]

Function items_to_tree

Build a nested PageIndex tree with LLM-path page-range conventions.

items_to_tree(items: Sequence[dict], segments: Sequence[Segment], profile: LayoutProfile) -> list[dict]

Parameter Type Default Description
items Sequence[dict]
segments Sequence[Segment]
profile LayoutProfile

Returns: list[dict]

Attribute logger

Alias normalize_title

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

Function page_structure

Return a document root with one Page <n> child per page.

page_structure(page_count: int, doc_name: str) -> list[dict]

Parameter Type Default Description
page_count int
doc_name str

Returns: list[dict]

Alias running_key

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

Function score_bookmarks

Score and anchor usable bookmarks against segments from their pages.

score_bookmarks(profile: LayoutProfile, segments: Sequence[Segment]) -> tuple[CandidateScore, list[dict]]

Parameter Type Default Description
profile LayoutProfile
segments Sequence[Segment]

Returns: tuple[CandidateScore, list[dict]]

Function score_layout

Score non-running heading segments using cleanliness, density, and starting position.

score_layout(profile: LayoutProfile, segments: Sequence[Segment]) -> tuple[CandidateScore, list[dict]]

Parameter Type Default Description
profile LayoutProfile
segments Sequence[Segment]

Returns: tuple[CandidateScore, list[dict]]

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