Repository navigation
feat(backend): add opt-in metadata extraction for declarative backends - #5543
LowmistLMT wants to merge 1 commit into
Conversation
… declarative backends Signed-off-by: lmtyy <3512819960@qq.com>
|
✅ DCO Check Passed Thanks @lmtyy, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit The PR adds an opt-in Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 6398672621. It read the code and did not run it.
Checked opt-in metadata extraction across Markdown, HTML, EPUB, and OpenDocument backends, verifying that default conversions remain unchanged, frontmatter parsing handles invalid YAML safely, and metadata merges into existing document metadata without data loss.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Add an opt-in
extract_metadata: bool = Falseoption onBaseBackendOptionsand a structuredDocumentMetadataPydantic model to extract document-level metadata across four pure-Python declarative backends (Markdown, EPUB, HTML/MHTML, and OpenDocument ODT/ODP/ODS) with zero new dependencies.Related to #2273 and docling-project/docling-core#544.
Summary of changes
docling/datamodel/document_metadata.py: Added a typedDocumentMetadataPydantic model (title,authors,date,language,description,keywords,publisher,identifier) with normalization, deduplication, andDocumentMetadata.from_mapping()/attach_document_metadata()helpers. Metadata is stored underdoc.body.meta["docling__document_metadata"](merging into any existingdoc.body.metakeys rather than overwriting them, following the existingvlm_pipeline.pyconvention).docling/datamodel/backend_options.py: Addedextract_metadata: bool = FalsetoBaseBackendOptionsso existing outputs remain unchanged by default.docling/backend/md_backend.py: Preserved parsed YAML frontmatter instead of discarding it and attached structured metadata whenextract_metadata=True(including when delegating HTML-block Markdown).docling/backend/epub_backend.py: Wired OPF Dublin Core metadata (dc:title, multipledc:creator/dc:subject,dc:date,dc:language,dc:description,dc:publisher,dc:identifier) intodoc.body.metawhenextract_metadata=True, addressing the existingTODOinconvert().docling/backend/html_backend.py: Extracted<title>,<html lang|xml:lang>,<link rel="canonical">, and standard<meta>tags (OpenGraph, Dublin Core, Google Scholarcitation_*,article:*,author,keywords,description), splitting comma-separatedauthor/keywordsvalues while preserving commas inside single-author fields such ascitation_author.docling/backend/opendocument_backend.py: Extractedodfdodocument metadata (dc:title,dc:creator/meta:initial-creator,dc:date/meta:creation-date,dc:language,dc:description/dc:subject,meta:keywordincluding comma-separated values) in_OdfBaseBackendfor ODT, ODP, and ODS.tests/test_document_metadata.py: Added offline unit tests covering all four backend families, opt-in default behavior, existingdoc.body.metapreservation, empty/malformed inputs, and model normalization.Usage example
Checklist:
Review evidence:
self.metadatawith aTODOcomment but did not attach it toDoclingDocument; HTML and OpenDocument backends did not extract document-level metadata intodoc.body.meta.extract_metadata=False(default), document trees and exports are completely unchanged. Whenextract_metadata=True, all four declarative backend families populatedoc.body.meta["docling__document_metadata"]with a normalizedDocumentMetadatapayload while preserving any pre-existingdoc.body.metaentries and existing document-tree structure.extract_metadata=Falseby default).uv.lockis unchanged.NO_PROXY=.localhost uv run pytest -v tests/test_document_metadata.py tests/test_backend_markdown.py tests/test_backend_epub.py tests/test_backend_html.py tests/test_backend_opendocument.pytest_document_metadata.py: 6/6,test_backend_markdown.py: 93/93,test_backend_epub.py: 25/25,test_backend_html.py: 173/173,test_backend_opendocument.py: 101/101).make check— all 9 checks passed (ruff format --check,ruff check,ty checkwith 0 new warnings vs.HEAD,tach check,check_tach_module_coverage.py,check_max_lines.py,check_skill_routes.py,dprint check,uv lock --locked).make validateandgit diff --check— passed.BaseBackendOptions).