Skip to content

feat(index): configurable chunk size/overlap + embedder-window clamp (bo-jsxi)#33

Merged
scbrown merged 1 commit into
mainfrom
bo-jsxi-chunk-config
Jun 28, 2026
Merged

feat(index): configurable chunk size/overlap + embedder-window clamp (bo-jsxi)#33
scbrown merged 1 commit into
mainfrom
bo-jsxi-chunk-config

Conversation

@scbrown

@scbrown scbrown commented Jun 28, 2026

Copy link
Copy Markdown
Owner

What

Makes line-based chunking configurable via [index].chunk_size / chunk_overlap and 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=10 in parser.rs). A 50-line dense-code chunk can exceed the embedder's max_seq — 256 for the default all-MiniLM-L6-v2, 512 for bge-small/gte-small — and the embedder truncates the overflow silently, degrading retrieval for the dropped tail.

How

  • Config: [index].chunk_size (50) + chunk_overlap (10).
  • Parser: with_chunking(size, overlap, max_chunk_tokens) — sanitizes overlap < size and size >= 1. chunk_by_lines uses them.
  • Clamp: when 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.
  • Wiring: new Embedder::max_seq() accessor; index/watch/webhook pass the live window into the parser.

Tests

  • estimate_tokens heuristic; with_chunking overlap/size sanitization
  • configurable size+overlap chunk boundaries
  • clamp splits a dense 50-line window into multiple chunks, every chunk <= cap, full coverage start→end
  • config parse + defaults

cargo build/clippy clean (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

…(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
@scbrown
scbrown merged commit b8a7e98 into main Jun 28, 2026
5 checks passed
@scbrown
scbrown deleted the bo-jsxi-chunk-config branch June 28, 2026 02:35
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.

1 participant