-
Notifications
You must be signed in to change notification settings - Fork 176
Documents separator groups for recursive chunking strategy #3848
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
Open
kosabogi
wants to merge
2
commits into
main
Choose a base branch
from
add-separator-groups-documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−6
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -161,11 +161,64 @@ PUT _inference/sparse_embedding/word_chunks | |||||
| stack: ga 9.1 | ||||||
| ``` | ||||||
|
|
||||||
| The `recursive` strategy splits the input text based on a configurable list of separator patterns (for example, newlines or Markdown headers). The chunker applies these separators in order, recursively splitting any chunk that exceeds the `max_chunk_size` word limit. If no separator produces a small enough chunk, the strategy falls back to sentence-level splitting. | ||||||
| The `recursive` strategy splits the input text based on a configurable list of separator patterns, such as paragraph boundaries or Markdown structural elements like headings and horizontal rules. The chunker applies these separators in order, recursively splitting any chunk that exceeds the `max_chunk_size` word limit. If no separator produces a small enough chunk, the strategy falls back to [sentence-level splitting](#sentence). | ||||||
|
|
||||||
| ##### Markdown separator group | ||||||
| You can configure the `recursive` strategy using either: | ||||||
| - [Predefined separator groups](#separator-groups): [`plaintext`](#plaintext) or [`markdown`](#markdown) | ||||||
| - [Custom separators](#custom-separators): Define your own regular expression patterns | ||||||
|
|
||||||
| The following example creates an {{infer}} endpoint with the `elasticsearch` service that deploys the ELSER model and configures chunking with the `recursive` strategy using the markdown separator group and a maximum of 200 words per chunk. | ||||||
| ##### Predefined separator groups [separator-groups] | ||||||
|
|
||||||
| Predefined separator groups provide optimized patterns for common text formats: [`plaintext`](#plaintext) for simple line-structured text without markup, and [`markdown`](#markdown) for Markdown-formatted content. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or maybe "is for" |
||||||
|
|
||||||
| ###### `plaintext` | ||||||
|
|
||||||
| The `plaintext` separator group splits text at paragraph boundaries, first attempting to split on double newlines (paragraph breaks), then falling back to single newlines when chunks are still too large. | ||||||
|
|
||||||
| :::{dropdown} Regular expression patterns for the `plaintext` separator group | ||||||
|
|
||||||
| 1. `(?<!\\n)\\n\\n(?!\\n)`: Splits on consecutive newlines that indicate paragraph breaks. | ||||||
| 2. `(?<!\\n)\\n(?!\\n)`: Splits on single newlines when double newlines don't produce small enough chunks. | ||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| The following example configures chunking with the `recursive` strategy using the `plaintext` separator group and a maximum of 200 words per chunk. | ||||||
|
|
||||||
| ```console | ||||||
| PUT _inference/sparse_embedding/recursive_plaintext_chunks | ||||||
| { | ||||||
| "service": "elasticsearch", | ||||||
| "service_settings": { | ||||||
| "model_id": ".elser_model_2", | ||||||
| "num_allocations": 1, | ||||||
| "num_threads": 1 | ||||||
| }, | ||||||
| "chunking_settings": { | ||||||
| "strategy": "recursive", | ||||||
| "max_chunk_size": 200, | ||||||
| "separator_group": "plaintext" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ###### `markdown` | ||||||
|
|
||||||
| The `markdown` separator group splits text based on Markdown structural elements, processing separators hierarchically from highest to lowest level: H1 through H6 headings, then horizontal rules. | ||||||
|
|
||||||
| :::{dropdown} Regular expression patterns for the `markdown` separator group | ||||||
|
|
||||||
| 1. `\n# `: Splits on level 1 headings (H1). | ||||||
| 2. `\n## `: Splits on level 2 headings (H2). | ||||||
| 3. `\n### `: Splits on level 3 headings (H3). | ||||||
| 4. `\n#### `: Splits on level 4 headings (H4). | ||||||
| 5. `\n##### `: Splits on level 5 headings (H5). | ||||||
| 6. `\n###### `: Splits on level 6 headings (H6). | ||||||
| 7. `\n^(?!\\s*$).*\\n-{1,}\\n`: Splits on horizontal rules created with hyphens. | ||||||
| 8. `\n^(?!\\s*$).*\\n={1,}\\n`: Splits on horizontal rules created with equals signs. | ||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| The following example configures chunking with the `recursive` strategy using the `markdown` separator group and a maximum of 200 words per chunk. | ||||||
|
|
||||||
| ```console | ||||||
| PUT _inference/sparse_embedding/recursive_markdown_chunks | ||||||
|
|
@@ -184,10 +237,9 @@ PUT _inference/sparse_embedding/recursive_markdown_chunks | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ##### Custom separator group | ||||||
|
|
||||||
| The following example creates an {{infer}} endpoint with the `elasticsearch` service that deploys the ELSER model and configures chunking with the `recursive` strategy. It uses a custom list of separators to split plaintext into chunks of up to 180 words. | ||||||
| ##### Custom separators | ||||||
|
|
||||||
| If the [predefined separator groups](#separator-groups) don't meet your needs, you can define custom separators using regular expressions. The following example configures chunking with the `recursive` strategy using a custom list of separators to split text into chunks of up to 180 words. | ||||||
|
|
||||||
| ```console | ||||||
| PUT _inference/sparse_embedding/recursive_custom_chunks | ||||||
|
|
@@ -236,3 +288,5 @@ PUT _inference/sparse_embedding/none_chunking | |||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe capitalize to match the following line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or else make "Custom separators" lower case?