Skip to content

feat: add configurable embedding chunk limit#73

Merged
jflowers merged 1 commit into
unbound-force:mainfrom
em-redhat:opsx/upgrade-embedding-model-r2
Jun 26, 2026
Merged

feat: add configurable embedding chunk limit#73
jflowers merged 1 commit into
unbound-force:mainfrom
em-redhat:opsx/upgrade-embedding-model-r2

Conversation

@em-redhat

Copy link
Copy Markdown
Contributor

Summary

Implements #53 — configurable embedding chunk limit with preparation for Granite Embedding R2 model upgrade.

New Capability

  • Configurable chunk limit: DEWEY_CHUNK_MAX_CHARS env var and embedding.max_chunk_chars config field control the maximum chunk character limit sent to the embedding model. Default increased from 768 to 12288 (~8192 tokens).

Changes

  • PrepareChunk now accepts a maxChars int parameter instead of using a package-level constant (eliminates global state)
  • Configured chunk limit threaded through GenerateEmbeddings → all 11 production call sites via tool structs and server options
  • dewey doctor displays an informational advisory when the legacy granite-embedding:30m model is configured
  • dewey init template includes the new max_chunk_chars config option
  • Defensive guard for negative/zero maxChars in PrepareChunk
  • Extracted resolveMaxChunkChars() helper (DRY env var parsing)

Guard Clause

Default model stays granite-embedding:30m — R2 is not yet on Ollama. TODO comment tracks the pending update.

Tests

  • 6 new config resolution tests (env var, config file, default, invalid, zero, negative)
  • 4 new chunker boundary tests (small/large limit, exact boundary, no-truncation)
  • 2 new doctor advisory tests (helper function + INFO marker)

Documentation

OpenSpec Artifacts

  • openspec/changes/upgrade-embedding-model-r2/ — proposal, design, specs, tasks

- Add MaxChunkChars field to ProviderConfig with config/env resolution
  (DEWEY_CHUNK_MAX_CHARS env var, embedding.max_chunk_chars config field)
- Change PrepareChunk to accept maxChars parameter, removing global constant
- Thread configured chunk limit through GenerateEmbeddings to all 11
  production call sites via tool structs and server options
- Add defensive guard for negative/zero maxChars in PrepareChunk
- Add legacy model advisory to dewey doctor (INFO marker for granite-embedding:30m)
- Extract resolveMaxChunkChars() helper to DRY env var parsing
- Default chunk limit increases from 768 to 12288 (~8192 tokens)
- Default model stays granite-embedding:30m (R2 not yet on Ollama, unbound-force#53)
- Add 12 new tests: config resolution, chunker boundaries, doctor advisory
- Update AGENTS.md and README.md with new env var and config field

Refs: unbound-force#53

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Any findings were already pre-existing and outside of the scope of this PR

@jflowers jflowers merged commit 48ec14e into unbound-force:main Jun 26, 2026
2 checks passed
@em-redhat em-redhat moved this from In Review 👀 to Done ✔️ in Unbound Force Planning Jun 29, 2026
@em-redhat em-redhat deleted the opsx/upgrade-embedding-model-r2 branch June 29, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants