fix: keep exported embedding vectors independent of source elements

AF
10h ago
+44-1

Summary

Text.to_dict() returns the original embeddings list. Editing a serialized vector therefore changes the source element, and later edits to the source change an already exported dictionary. Batch exports can also share the same vector object.

Copy the vector when serializing it. Keep the existing output values and the omission of absent/empty embeddings. Regression coverage exercises NarrativeText, Title, TableChunk and elements_to_dicts().

The related #4626 restores embeddings during rehydration; this change handles ownership of vectors exported to dictionaries.

Validation

  • On original production code, this change's regressions produce 7 failures and 2 passing controls.
  • A fork validation branch containing both independent fixes runs these regressions against the pinned original production files first: 11 fail and 4 controls pass. Restoring the final source, the new regressions and existing element, base chunking, chunk dispatch and HTML conversion suites report 549 passed, 1 skipped on Python 3.12.
  • Ruff 0.17.5 check and format check pass with this repository's configuration. Source-integrity checks confirm the files are restored after baseline verification.
  • Validation run and JUnit artifacts.

Checklist

  • The PR title is a user-facing release-note entry with a conventional commit prefix.
  • Maintainer: please apply the bug category label.