An experimental, AI generated and so far unreviewed branch is available at:
https://github.com/xwiki-contrib/ai-llm/compare/main...ohrner-it:xwiki-contrib-ai-llm:features/LLMAI-230-Add-a-chunking-method-that-follows-the-document-structure-and-keeps-the-page-hierarchy-and-headings-as-context
It's based on the implementations for LLMAI-176 and LLMAI-229.