feat(retain): configurable chunk overflow factor (#2136)#2141
Closed
nicoloboschi wants to merge 1 commit into
Closed
feat(retain): configurable chunk overflow factor (#2136)#2141nicoloboschi wants to merge 1 commit into
nicoloboschi wants to merge 1 commit into
Conversation
The factor that keeps a single JSONL line / conversation turn whole when it overflows the chunk-size budget was hardcoded at 1.5x. Expose it as HINDSIGHT_API_RETAIN_CHUNK_OVERFLOW_FACTOR (default 1.5, hierarchical / per-bank) so longer structured messages can stay within a single chunk without globally inflating RETAIN_CHUNK_SIZE. chunk_text / _chunk_conversation / _chunk_jsonl now take an overflow_factor param (default = the module constant); the bank-config-driven call sites in the orchestrator and fact extractor pass config.retain_chunk_overflow_factor. _resolve_retain_chunk_size becomes _resolve_retain_chunk_params, returning a RetainChunkParams dataclass (size + factor) so the chunk-offset counting in memory_engine matches the orchestrator's actual chunking when an oversized unit is present. Closes #2136
99bf3fd to
1896f2f
Compare
Collaborator
Author
|
Closing in favor of #2139, which already closes #2136 with a more complete implementation (typed bank-template API, OpenAPI, generated clients, control-plane UI, CLI). #2139 uses an absolute char cap ( |
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.
Closes #2136.
What
Makes the chunk overflow factor configurable. Previously hardcoded at
1.5, this factor controls how far a single JSONL line or conversation turn may exceed the chunk-size budget while still being kept whole (before falling back to splitting it as text).New flag:
HINDSIGHT_API_RETAIN_CHUNK_OVERFLOW_FACTOR(default1.5, hierarchical / per-bank overridable).Why
Per the issue: when ingesting JSONL where some messages are larger but still comfortably within the extraction model's context, the only way to avoid splitting them today is to raise the global chunk size. Raising the overflow factor instead (e.g. to
3.0) keeps longer structured messages intact in a single chunk — preserving role/time/filename context — while keeping a smaller default chunk size everywhere else.How
config.py— env constant, default, dataclass field,_CONFIGURABLE_FIELDSentry,from_env()wiring, and_parse_chunk_overflow_factor()(validates>= 1.0, fails fast otherwise).fact_extraction.py—chunk_text/_chunk_conversation/_chunk_jsonltake anoverflow_factorparam (default = the existing module constant). The three bank-config-driven call sites passconfig.retain_chunk_overflow_factor.orchestrator.py— bothchunk_textcall sites thread the resolved factor through.memory_engine.py—_resolve_retain_chunk_size→_resolve_retain_chunk_params, returning aRetainChunkParamsdataclass (chunk size + factor) so the chunk-offset counting matches the orchestrator's actual chunking when an oversized unit is present.configuration.md(+ regenerated docs skill).Tests
test_chunking.py— a raisedoverflow_factorkeeps a JSONL line / conversation turn whole that the default would split.test_config_validation.py— default, env override, and< 1.0rejection.test_hierarchical_config.py— new field is configurable; count assertion 38 → 39.All affected non-DB tests pass; lint + ty clean.