Rewrite the explanation of chunking strategies - #8249
Open
SKHDev195 wants to merge 2 commits into
Open
Conversation
timgrein
reviewed
Sep 11, 2026
Comment on lines
+168
to
+173
| 1 Elasticsearch 7 index 13 are 19 enables | ||
| 2 stores 8 is 14 distributed 20 horizontal | ||
| 3 data 9 divided 15 across 21 scaling. | ||
| 4 in 10 into 16 nodes. 22 Replicas | ||
| 5 indices. 11 shards. 17 This 23 provide | ||
| 6 Each 12 Shards 18 distribution 24 redundancy. |
There was a problem hiding this comment.
Maybe this just looks weird in the markdown diff, but shouldn't this read from left to right instead of top to bottom and then left to right?
timgrein
reviewed
Sep 11, 2026
Comment on lines
+371
to
+375
| "^(#{1,6})\\s", | ||
| "\\n\\n", | ||
| "\\n[-*]\\s", | ||
| "\\n\\d+\\.\\s", | ||
| "\\n" |
There was a problem hiding this comment.
EOL comments would help to understand what these regexes do, otherwise it's a bit hard to understand IMO
timgrein
reviewed
Sep 11, 2026
Comment on lines
+247
to
+264
| Text: | ||
|
|
||
| ``` | ||
| Elasticsearch stores data in indices. Each index is divided into shards. (11 words) | ||
| ← \n\n | ||
| Shards are distributed across nodes. This distribution enables horizontal | ||
| scaling. (10 words) | ||
| ← \n\n | ||
| Replicas provide redundancy. (3 words) | ||
| ``` | ||
|
|
||
| Chunks: | ||
|
|
||
| ``` | ||
| Chunk 1: Elasticsearch stores data in indices. Each index is divided into shards. | ||
| Chunk 2: Shards are distributed across nodes. This distribution enables horizontal scaling. | ||
| Chunk 3: Replicas provide redundancy. | ||
| ``` |
There was a problem hiding this comment.
I checked for correctness together with Claude against the codebase and found:
Actual behavior: RecursiveChunker.mergeChunkOffsetsUpToMaxChunkSize() greedily merges adjacent chunks when their combined word count fits
within max_chunk_size. After splitting on \n\n:
- Chunk 2 (10 words) + Chunk 3 (3 words) = 13 words ≤ 20 → they are merged.
Real result with max_chunk_size: 20:
Chunk 1: Elasticsearch stores data in indices. Each index is divided into shards. (11 words)
Chunk 2: [separator]\nShards are distributed across nodes. [...] Replicas provide redundancy. (13 words)
This is confirmed by the test testChunkInputRequiresOneSplitWithMerges in RecursiveChunkerTests.java:61, where 3 sentences of 10 words each
and max_chunk_size=20 produces only 2 chunks (first two merged).
Comment on lines
+313
to
+334
| # Elasticsearch | ||
|
|
||
| ## Storage | ||
|
|
||
| Elasticsearch stores data in indices. Each index is divided into shards. | ||
|
|
||
| ## Distribution | ||
|
|
||
| Shards are distributed across nodes. This distribution enables horizontal scaling. | ||
|
|
||
| ## Redundancy | ||
|
|
||
| Replicas provide redundancy. | ||
| ``` | ||
|
|
||
| Chunks: | ||
|
|
||
| ``` | ||
| Chunk 1: ## Storage / Elasticsearch stores data in indices. Each index is divided into shards. | ||
| Chunk 2: ## Distribution / Shards are distributed across nodes. This distribution enables horizontal scaling. | ||
| Chunk 3: ## Redundancy / Replicas provide redundancy. | ||
| ``` |
There was a problem hiding this comment.
Another finding by Claude:
The PR shows 3 chunks, one per ## Heading. Actual behavior:
The separators for MARKDOWN (SeparatorGroup.java:30-39) are \n# , \n## , etc. Splitting on \n## produces:
- # Elasticsearch\n → 1 word
- \n## Storage\n\n...shards.\n\n → 1 ("Storage") + 11 = 12 words
- \n## Distribution\n\n...scaling.\n\n → 1 + 10 = 11 words
- \n## Redundancy\n\nReplicas provide redundancy. → 1 + 3 = 4 words
Greedy merge with max_chunk_size: 20:
- 1 + 12 = 13 ≤ 20 → merge into Chunk 1 (13 words): contains # Elasticsearch + ## Storage section
- 13 + 11 = 24 > 20 → emit Chunk 1, start new
- 11 + 4 = 15 ≤ 20 → merge into Chunk 2 (15 words): contains ## Distribution + ## Redundancy sections
Real result:
Chunk 1: # Elasticsearch\n\n## Storage\n\nElasticsearch stores data in indices. Each index is divided into shards. (13 words)
Chunk 2: \n## Distribution\n\n...scaling.\n\n## Redundancy\n\nReplicas provide redundancy. (15 words)
Contributor
Elastic Docs AI PR menuCheck the box to run an AI review for this pull request.
Powered by GitHub Agentic Workflows and docs-actions. For more information, reach out to the docs team. |
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.
Summary
Rewrites and expands the "Configuring chunking" section of explore-analyze/elastic-inference/inference-api.md to make chunking strategies easier to understand and choose between.
Changes:
max_chunk_size: 20) to each strategy showing exactly how sample text is split.Generative AI disclosure
Tool(s) and model(s) used: Claude Code (Claude Opus 5)