feat(index): configurable chunk size/overlap + embedder-window clamp (bo-jsxi)#33
Merged
Conversation
…(bo-jsxi) Line-based chunking was hardcoded (chunk_size=50, overlap=10) and a dense 50-line chunk can exceed the embedder's token window (256 for the default all-MiniLM-L6-v2, 512 for bge/gte), causing silent truncation at embed time. - config: [index].chunk_size / chunk_overlap (defaults 50 / 10) - Parser::with_chunking(size, overlap, max_chunk_tokens) — sanitizes overlap < size and size >= 1; chunk_by_lines now uses them - token clamp: when max_chunk_tokens > 0, each line chunk is shrunk to fit the window (estimate ~chars/4) so nothing silently truncates; advance logic guards forward progress when a clamped chunk is shorter than the overlap - Embedder::max_seq() accessor; index/watch/webhook pass the live window into the parser (0 = unknown/API backend = no clamp) - tests: estimate_tokens, overlap/size sanitization, configurable size+overlap boundaries, clamp splits a dense window with every chunk <= cap, config parse Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UHPGrbayqXRFaMHuvs6yLX
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.
What
Makes line-based chunking configurable via
[index].chunk_size/chunk_overlapand clamps every line/markdown-fallback chunk to the embedding model's token window so dense chunks aren't silently truncated at embed time.Why (bo-jsxi)
Chunking was hardcoded (
chunk_size=50,overlap=10inparser.rs). A 50-line dense-code chunk can exceed the embedder'smax_seq— 256 for the defaultall-MiniLM-L6-v2, 512 forbge-small/gte-small— and the embedder truncates the overflow silently, degrading retrieval for the dropped tail.How
[index].chunk_size(50) +chunk_overlap(10).with_chunking(size, overlap, max_chunk_tokens)— sanitizesoverlap < sizeandsize >= 1.chunk_by_linesuses them.max_chunk_tokens > 0, each chunk is shrunk (by line) until its estimated tokens (~chars/4) fit the window; advance logic guards forward progress when a clamped chunk is shorter than the overlap.0= window unknown (API backend) = no clamp.Embedder::max_seq()accessor;index/watch/webhookpass the live window into the parser.Tests
estimate_tokensheuristic;with_chunkingoverlap/size sanitization<= cap, full coverage start→endcargo build/clippyclean (0 errors); config + parser + embedder suites pass.Note: scoped to the line-based + markdown-fallback chunkers named in the bead. Tree-sitter semantic chunks (whole functions) are intentionally not split (splitting breaks semantics); they remain subject to the embedder's existing truncation as before.
🤖 Generated with Claude Code