You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
List block in a partitioned Markdown doc identified as a Title element under special conditions #3280
I noticed that when the number of characters per line is very short in a list block in a Markdown document, the list is identified as a Title instead of a NarrativeText.
It prevents the chunking by title to work properly afterwards as I expect all content under a Markdown header to become a CompositeText to be indexed with an embedding function.
It is reproducible with the following python code:
The "official" John Gruber spec and reference implementation specifies this behavior, that a list requires a blank line before it. The gist is that a word-wrapped line that just happens to start with a "-" or "*" should not be interpreted as a list item, like:
The computed value of 7
* 3 equals 21.
In practice, Markdown parsers are more clever about this and are able to distinguish author intent reliably without the blank line before the list.
Note that using the markdown_it package (already a dependency I believe, possibly for ingest), we get a "correct" conversion with or without the blank line.
My general impression, after poking around a bit, is that the markdown package is overly dogmatic, like adhering closely to the "original" standard from 2005 or so. I think what we care about is that the maximum number of legitimate Markdown files parse as they would be expected to, like how they appear on GitHub or whatever other site they came from.
This "defacto-standard" behavior is what the CommonMark standard articulates and markdown_it is CommonMark compliant. It's also somewhat more modern, being only 1 decade old rather than 2 :)
I'm inclined to think we'd be better off in general using the markdown_it package since I believe it would parse more Markdown documents the way the author intended and the way they appear when rendered on their source.
Btw, @nickphilip what was the provenance of that problematic Markdown?
Is that something you just typed in by hand for experimentation purposes or did you have an actual "mis"-partitioning from a document from say StackOverflow or something?
@scanny - I found the issue testing unstructured.io against Markdown documents from public repos, as I noticed that my RAG app was not getting the expected context.
Great assessment of the root cause. Your workaround makes sense, but the fix would be preferable if one uses the runner (pipeline). Thanks!
@MthwRobinson After noodling this a bit and a little more research, I think there are four possible courses:
support "traditional" (maybe "legacy") Markdown (what we're doing today)
support CommonMark Markdown
support GFM (GitHub Flavored Markdown)
support multiple using a partitioning option of some sort
I think the right answer is 2 (CommonMark).
it solves this particular problem
it generally does the expected thing with traditional markdown
it does not interpret a single newline as a <br> element (the way GFM does)
I'm not sure there's a perfect answer, but I think CommonMark provides the broadest coverage for what we care about when partitioning and so is a good step in the right direction. I think we'd all prefer to avoid a new partitioning option until we can show a compelling use case that requires it.
Taking a look at this. The plan is to switch the Markdown-to-HTML converter used by partition_md to CommonMark via markdown-it-py, following the direction in this thread, keeping table parsing enabled by default. The extensions option gets remapped onto the new converter, and the change comes with tests covering the issue's document, single-item and ordered lists, and the chunking-by-title behavior. I'll open a PR once the fix and tests are verified locally.
Activity
MthwRobinson commentedon Jul 1, 2024
@nickphilip - Thanks for reporting this, we'll take a look as soon as we're able.
scanny commentedon Jul 1, 2024
@MthwRobinson Turns out this behavior is produced by the
markdownpackage, which is whatpartition_md()uses to convert Markdown to HTML.Adding a blank line before the list results in the expected behavior:
The "official" John Gruber spec and reference implementation specifies this behavior, that a list requires a blank line before it. The gist is that a word-wrapped line that just happens to start with a "-" or "*" should not be interpreted as a list item, like:
In practice, Markdown parsers are more clever about this and are able to distinguish author intent reliably without the blank line before the list.
Note that using the
markdown_itpackage (already a dependency I believe, possibly for ingest), we get a "correct" conversion with or without the blank line.My general impression, after poking around a bit, is that the
markdownpackage is overly dogmatic, like adhering closely to the "original" standard from 2005 or so. I think what we care about is that the maximum number of legitimate Markdown files parse as they would be expected to, like how they appear on GitHub or whatever other site they came from.This "defacto-standard" behavior is what the CommonMark standard articulates and
markdown_itis CommonMark compliant. It's also somewhat more modern, being only 1 decade old rather than 2 :)I'm inclined to think we'd be better off in general using the
markdown_itpackage since I believe it would parse more Markdown documents the way the author intended and the way they appear when rendered on their source.scanny commentedon Jul 1, 2024
@nickphilip In the meantime, a workaround for this would be:
Basically converting the MD to HTML yourself and then using
partition_html()on the result.scanny commentedon Jul 2, 2024
Btw, @nickphilip what was the provenance of that problematic Markdown?
Is that something you just typed in by hand for experimentation purposes or did you have an actual "mis"-partitioning from a document from say StackOverflow or something?
nickphilip commentedon Jul 3, 2024
@scanny - I found the issue testing unstructured.io against Markdown documents from public repos, as I noticed that my RAG app was not getting the expected context.
Great assessment of the root cause. Your workaround makes sense, but the fix would be preferable if one uses the runner (pipeline). Thanks!
scanny commentedon Jul 3, 2024
@nickphilip when you say "public repos", does that imply this would be GFM (GitHub Flavored markdown) you're parsing?
scanny commentedon Jul 3, 2024
@MthwRobinson After noodling this a bit and a little more research, I think there are four possible courses:
I think the right answer is 2 (CommonMark).
<br>element (the way GFM does)I'm not sure there's a perfect answer, but I think CommonMark provides the broadest coverage for what we care about when partitioning and so is a good step in the right direction. I think we'd all prefer to avoid a new partitioning option until we can show a compelling use case that requires it.
mirzasnowy commentedon Oct 31, 2026
Taking a look at this. The plan is to switch the Markdown-to-HTML converter used by partition_md to CommonMark via markdown-it-py, following the direction in this thread, keeping table parsing enabled by default. The extensions option gets remapped onto the new converter, and the change comes with tests covering the issue's document, single-item and ordered lists, and the chunking-by-title behavior. I'll open a PR once the fix and tests are verified locally.