Repository navigation
Keep DOCX tables in the section where they appear - #11
Merged
Merged
Conversation
load_docx read every paragraph first and only then every table, so all table rows ended up in the last section's text under the last heading. Walk the body with iter_inner_content() so paragraphs and tables are handled in document order. Fixes #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong.
load_docx(backend/src/docmind/ingestion/loaders.py) iterateddocument.paragraphsand only afterwardsdocument.tables, so every table row was appended to the buffer of the section still open at the end. A pricing table under "Pricing" ended up in the text of the last section with that section's heading, and the "Pricing" section itself disappeared if it had no paragraphs. Retrieval then cited the wrong section.The fix. Walk the body with
Document.iter_inner_content()(python-docx >= 1.1, already our minimum) and handle paragraphs and tables in the same loop, so table rows go into the section they belong to. Paragraph handling is unchanged.How it was tested. New
test_docx_table_stays_in_its_sectionin backend/tests/test_ingestion.py builds a DOCX with "Pricing" + a table, then "Contacts" + a paragraph, and asserts two sections with the table row under "Pricing". It fails on main (the row lands in "Contacts" and "Pricing" is missing). Full backend suite (119 passed), ruff check, ruff format --check and mypy pass.Fixes #10