Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text splitter for Markdown files by header #5860

Merged
merged 6 commits into from
Jun 12, 2023

Conversation

rlancemartin
Copy link
Collaborator

@rlancemartin rlancemartin commented Jun 7, 2023

This creates a new kind of text splitter for markdown files.

The user can supply a set of headers that they want to split the file on.

We define a new text splitter class, MarkdownHeaderTextSplitter, that does a few things:

(1) For each line, it determines the associated set of user-specified headers
(2) It groups lines with common headers into splits

See notebook for example usage and test cases.

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need sorted(splits, key=lambda x: (-len(x[0]), -x[0].count('#')))

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh probably best reviewd by writing a bunch of test cases and ensuring it works

@rlancemartin rlancemartin changed the title Notebook testing markdown header splitting Text splitter for Markdown files by header Jun 11, 2023
@rlancemartin
Copy link
Collaborator Author

tbh probably best reviewd by writing a bunch of test cases and ensuring it works

Done. Added to notebook.

@rlancemartin
Copy link
Collaborator Author

not sure we need sorted(splits, key=lambda x: (-len(x[0]), -x[0].count('#')))

Re-organized code a bit; we no longer do this.

@rlancemartin rlancemartin force-pushed the rlm/markdown_splitter branch 4 times, most recently from 450efd1 to 06894b4 Compare June 11, 2023 01:58
@rlancemartin rlancemartin force-pushed the rlm/markdown_splitter branch 11 times, most recently from 4840d6b to 3365aaf Compare June 12, 2023 21:39
@rlancemartin rlancemartin merged commit b023f0c into langchain-ai:master Jun 12, 2023
Undertone0809 pushed a commit to Undertone0809/langchain that referenced this pull request Jun 19, 2023
This creates a new kind of text splitter for markdown files.

The user can supply a set of headers that they want to split the file
on.

We define a new text splitter class, `MarkdownHeaderTextSplitter`, that
does a few things:

(1) For each line, it determines the associated set of user-specified
headers
(2) It groups lines with common headers into splits

See notebook for example usage and test cases.
This was referenced Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants