MarkdownChunking returns content at or below chunk_size as one chunk in its default mode. For longer content, it uses Unstructured to partition Markdown and group the resulting elements toward chunk_size. Set split_on_headings=True to split on every ATX heading from H1 through H6. Set an integer from 1 to 6 to split on ATX headings through that level.
1
Create a Python file
markdown_chunking.py
2
Set up your virtual environment
3
Install dependencies
4
Export your OpenAI API key
5
Run PgVector
6
Run the script
Choose a Mode
In heading mode, sections longer than
chunk_size are split by paragraphs, then by words, and repeat an existing heading. A long indivisible word or prepended overlap can make the final chunk longer than chunk_size. Overlap is prepended without an added separator.