Skip to content

Budget-aware retrieval: oversized filtering, MMR budgeting, chain output budgeting#148

Merged
gvonness-apolitical merged 2 commits intomainfrom
feat/budget-aware-retrieval
Mar 4, 2026
Merged

Budget-aware retrieval: oversized filtering, MMR budgeting, chain output budgeting#148
gvonness-apolitical merged 2 commits intomainfrom
feat/budget-aware-retrieval

Conversation

@gvonness-apolitical
Copy link
Contributor

Summary

  • Oversized chunk filtering: Chunks individually larger than the query's maxTokens are excluded a priori — filtered before MMR in search, and passed through (but not scored) in chain walking so the chain doesn't break at large nodes
  • Budget-aware MMR: The greedy selection loop tracks remaining token budget and skips candidates that exceed it, preventing large chunks from consuming diversity slots they can't fill. Applies below MMR threshold too
  • Budget-aware chain formatting: Chain output assembly iterates through chunks in order and only includes those that fit within the remaining budget — no partial chunks returned
  • Documentation: Updated CHANGELOG (v0.9.2), traversal algorithm reference (pseudocode, design decisions, pipeline diagram), how-it-works guide (search/chain pipeline steps, MMR section), and MCP tools reference (token limits section)

Test plan

  • npm run build && npm test — 2038 tests pass
  • 11 new tests: 4 chain-walker oversized passthrough, 4 MMR budget-aware selection, 3 chain-assembler budget-aware formatting
  • search max_tokens:500 with large chunks in memory → no chunk exceeding 500 tokens in response
  • recall through a chain containing an oversized node → chain continues past it, node excluded from output

…g, chain output budgeting

Retrieval pipelines now enforce token budgets at multiple stages instead of
only at final assembly. Oversized chunks (individually > maxTokens) are
filtered before MMR in search and passed through without scoring in chains.
MMR tracks remaining budget during greedy selection. Chain formatting drops
chunks that would exceed the remaining budget. Version bump to 0.9.2.
@gvonness-apolitical gvonness-apolitical merged commit 0857a69 into main Mar 4, 2026
3 checks passed
@gvonness-apolitical gvonness-apolitical deleted the feat/budget-aware-retrieval branch March 4, 2026 14:12
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