feat: make mainExpandBy and separatorExpandBy configurable options#276
Open
Theroxenes wants to merge 2 commits into
Open
feat: make mainExpandBy and separatorExpandBy configurable options#276Theroxenes wants to merge 2 commits into
Theroxenes wants to merge 2 commits into
Conversation
8 tasks
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
Web search highlights are expanded on both sides by
expandHighlightsto givethe model surrounding context, using hardcoded
mainExpandBy = 300/separatorExpandBy = 150(chars per side). This expansion can be the dominantcontributor to web search payload size.
Measured on a real search (local SearXNG + Firecrawl-compatible scraper +
CrossEncoder reranker), per source, holding the reranked chunks constant and
varying only the expansion params:
A ~58% per-source reduction, with highlight coherence roughly preserved.
This PR exposes the two parameters via config, following the existing
topResults/strategies/safeSearchconvention (config-only — no envvar). Defaults are unchanged, so the change is non-breaking.
expandHighlightsalready accepts these parameters with the correct defaults;this PR simply threads config values to the existing call site rather than
adding new machinery.
Changes
types.ts: addmainExpandBy/separatorExpandBytoProcessSourcesConfig(inherited by
SearchToolConfig).tool.ts: destructure both from config with defaults (300/150) and pass themto the
expandHighlightscall.source-processing.test.ts: add coverage for default expansion, smaller →shorter highlights, larger → longer, zero → chunk-only, and the
processor→expand path.
Change Type
Testing
npx jest src/tools/search— all existing + new tests pass.npx tsc --noEmit,npx eslint src/tools/search/clean.values produces correspondingly shorter highlights in the formatted output,
with the core reranked passage preserved.