Skip to content

feat: make mainExpandBy and separatorExpandBy configurable options#276

Open
Theroxenes wants to merge 2 commits into
danny-avila:mainfrom
Theroxenes:feat/search-expand-configs
Open

feat: make mainExpandBy and separatorExpandBy configurable options#276
Theroxenes wants to merge 2 commits into
danny-avila:mainfrom
Theroxenes:feat/search-expand-configs

Conversation

@Theroxenes

Copy link
Copy Markdown

Summary

Web search highlights are expanded on both sides by expandHighlights to give
the model surrounding context, using hardcoded mainExpandBy = 300 /
separatorExpandBy = 150 (chars per side). This expansion can be the dominant
contributor 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:

Expansion (main/separator) Post-expansion bytes/source Ratio vs. reranked chunks
300 / 150 (current default) ~4,200 ~6.7×
100 / 50 ~1,700 ~2.8×

A ~58% per-source reduction, with highlight coherence roughly preserved.

This PR exposes the two parameters via config, following the existing
topResults / strategies / safeSearch convention (config-only — no env
var). Defaults are unchanged, so the change is non-breaking.

expandHighlights already 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: add mainExpandBy / separatorExpandBy to ProcessSourcesConfig
    (inherited by SearchToolConfig).
  • tool.ts: destructure both from config with defaults (300/150) and pass them
    to the expandHighlights call.
  • source-processing.test.ts: add coverage for default expansion, smaller →
    shorter highlights, larger → longer, zero → chunk-only, and the
    processor→expand path.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • npx jest src/tools/search — all existing + new tests pass.
  • npx tsc --noEmit, npx eslint src/tools/search/ clean.
  • Verified end-to-end against a real search pipeline: setting smaller expansion
    values produces correspondingly shorter highlights in the formatted output,
    with the core reranked passage preserved.

@Theroxenes Theroxenes changed the title Make mainExpandBy and separatorExpandBy configurable options feat: make mainExpandBy and separatorExpandBy configurable options Jun 27, 2026
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