dllmforge.IE_agent_provenance

Quote-first provenance: recover source_page from source_quote against a Docling index.

The LLM copies a verbatim quote. Page numbers are assigned in code by locating that quote in page-indexed elements (sections, tables, figures, prose).

Functions

apply_quote_provenance(obj[, index, metadata])

Walk a parsed extraction dict and fill source_page from source_quote.

locate_quote(quote, index[, fuzzy_threshold])

Return the best matching index element for a quote, or None.

normalize_index(index)

Accept element_index ({page, type, text}) or page_index ({page, text}).

normalize_text(value)

Collapse whitespace, fix OCR units (50m -> 50 m), lowercase.

public_metadata(meta)

Copy processor metadata without the bulky locator index.

dllmforge.IE_agent_provenance.public_metadata(meta: Dict[str, Any] | None) → Dict[str, Any][source]

Copy processor metadata without the bulky locator index.

dllmforge.IE_agent_provenance.normalize_text(value: str) → str[source]

Collapse whitespace, fix OCR units (50m -> 50 m), lowercase.

dllmforge.IE_agent_provenance.normalize_index(index: Iterable[Dict[str, Any]] | None) → List[Dict[str, Any]][source]

Accept element_index ({page, type, text}) or page_index ({page, text}).

dllmforge.IE_agent_provenance.locate_quote(quote: str, index: Iterable[Dict[str, Any]] | None, fuzzy_threshold: float = 0.55) → Dict[str, Any] | None[source]

Return the best matching index element for a quote, or None.

Long LLM quotes often concatenate a sentence + a table + more prose. Match the whole string first, then each paragraph, and prefer a table hit when the quote contains a markdown table.

dllmforge.IE_agent_provenance.apply_quote_provenance(obj: Any, index: Iterable[Dict[str, Any]] | None = None, metadata: Dict[str, Any] | None = None) → Any[source]

Walk a parsed extraction dict and fill source_page from source_quote.

If index is omitted, metadata['element_index'] or metadata['page_index'] is used. Unmatched quotes get quote_verified=False and source_page=None (do not keep a guessed page).