Skip to content

feat(knowledge-base): add standalone PPTX parsing with slide provenance - #2980

Open
yumestk wants to merge 2 commits into
oceanbase:masterfrom
yumestk:feat/pptx-parser-2854
Open

yumestk wants to merge 2 commits into
oceanbase:masterfrom
yumestk:feat/pptx-parser-2854

Conversation

@yumestk

@yumestk yumestk commented Dec 2, 2026

Copy link
Copy Markdown

Which issue or RFC does this PR close?

Refs #2854 and #2848. Registry and Worker integration are tracked in #2856.

Rationale for this change

The knowledge base needs a bounded PPTX parser that can return source locations and exact slide totals. This change implements the standalone adapter so the integration can consume parsed blocks, coverage, and preflight facts through the shared parser contract.

What changes are included in this PR?

  • Add PPTX_ADAPTER in pc_knowledge_base.pptx. Resolve slides through OPC relationships in presentation order, including hidden slides. Resolve ASCII case-equivalent part names consistently and reject ambiguous members and repeated slide references.
  • Extract text from shapes, nested groups, and tables. Preserve source shape order and half-open row and column spans for table anchors, including merged regions.
  • Report uncovered content by feature and retain an anchor for each warning. Add ZIP, XML, and extraction limits with deterministic input errors.
  • Add PPTX tests for provenance, coverage, encrypted and malformed input, resource limits, the exact 50,000,000-byte input boundary, and 1,000/1,001-slide preflight counts. Use the existing locked defusedxml dependency.

Are there any user-facing changes?

This patch provides the standalone adapter. Registry selection, upload, Worker processing and publication, and retrieval are part of #2856. Worker preflight should consume the exact PreflightCounts.slides value for the same input and apply the 1,000-slide product limit before extraction. The adapter supports Transitional PPTX text and tables. Notes, charts, SmartArt, images, and embedded objects report coverage gaps. Geometry and embedded payload extraction remain outside the adapter.

How was this change tested?

A-01 through A-04 passed within the standalone parser scope. Local validation used CPython 3.12.14 and the locked knowledge-base and knowledge-base-formats extras. The final patch was also replayed on upstream master 0b60e52acfcefe2fe64cca52249db83c98d9a3ba.

  • python -m pytest -q tests/knowledge_base/test_pptx.py passed 46 tests.
  • python -m pytest -q -rs tests/knowledge_base passed 96 tests. Six native SQL cases were skipped because the backends were unavailable.
  • Generated the existing wind.pptx, parsed it with the adapter, and ran python -m evaluation.knowledge_base parse <results> --subset. Text, location, and coverage all matched.
  • Ruff format and lint checks and ty check --no-force-exclude plugins/knowledge-base passed. The independent verifier reproduced the case-equivalence defect before the fix and reran the final tests and scorer in a separate checkout.

Remote CI has not been verified. The existing general unit and knowledge-base jobs both lack the formats extra. Local pytest collection reproduces ModuleNotFoundError: No module named 'defusedxml' in both dependency selections. The proposed setup change is to enable the existing locked extra in both test environments. Public confirmation of the updated #2849 evaluation manifest is pending.

AI usage statement

OpenAI Codex (GPT-6) assisted with implementation, tests, and documentation. A separate Codex verifier independently reviewed and verified the final patch.

@CLAassistant

CLAassistant commented Dec 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standalone parser passes the focused tests and a real generated PPTX with a hidden slide and merged table. The dependency setup issue already noted in the description is reproducible and still needs resolution before merging.

Span,
serialize_context_locator,
)
from pc_knowledge_base.pptx import PPTX_ADAPTER

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Make the new test module collectable in the CI dependency environment. In a fresh environment, uv run --locked --extra knowledge-base --group knowledge-base-tests pytest tests/knowledge_base/test_pptx.py --collect-only -q fails here with ModuleNotFoundError: No module named defusedxml. The knowledge-base job installs exactly these extras/groups; defusedxml is only in knowledge-base-formats. This new unconditional import therefore prevents the suite from collecting. Coordinate installation of the existing formats extra in the jobs that collect this test, and verify the resulting CI setup before merging.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since changes to shared CI configuration are outside the scope of #2854, may I include the minimal CI fix in this PR, or should it be handled by the CI maintainers separately?

@hireview001 hireview001 added the module:knowledge-base Primary module: knowledge base import, processing and retrieval label Dec 2, 2026
@hireview001

Copy link
Copy Markdown
Collaborator

The affected modules are Knowledge base. @Zxf-xufeng, please coordinate follow-up. Knowledge base: @Zxf-xufeng @Alanxtl. Please coordinate the review of the affected changes.

folder = posixpath.dirname(part)
for relation in _relationships(package, relation_part).values():
feature = _RELATION_FEATURES.get(relation.get("Type", ""))
if feature is None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Report coverage gaps for inherited slide content

For a slide with local text and visible content inherited from its layout/master, this branch skips the slideLayout relationship, omitting inherited text and images while reporting full coverage without warnings. Inspect the applicable layout/master parts within the resource budgets and report an anchored coverage gap for content left unextracted.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 44c79f03. The parser now checks the applicable layout and master within the existing XML limits, caches shared parts, and reports gaps on the affected slide. Regression tests cover inherited text and images, placeholder prompts, hidden shapes, and background overrides. The PPTX suite and wind.pptx scorer passed locally.

"".join(
"\n" if item.tag == f"{_A}br" else item.findtext(f"{_A}t", "")
for item in paragraph
if item.tag in (f"{_A}r", f"{_A}fld", f"{_A}br")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Warn when skipping inline equations

When a shape or table cell mixes normal text with an inline a14:m equation, this filter discards the equation and neither caller records a gap, so _extract counts the slide as fully covered without warnings. Detect unhandled inline content and emit an anchored unsupported_content warning that reduces slide coverage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 44c79f03. Ordinary text stays in order, and skipped inline equations now produce an unsupported_content warning at the original shape or table cell. Regression tests cover both paths, including an equation-only cell. The independent check also verified a native PowerPoint file that wraps the text box in mc:AlternateContent.

@yumestk
yumestk requested a review from Alanxtl as a code owner December 3, 2026 07:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:knowledge-base Primary module: knowledge base import, processing and retrieval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants