Skip to content

Simplify rulebased router: remove redundant types and score aggregation#2016

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/gorgonia-golearn-82dce730
Mar 10, 2026
Merged

Simplify rulebased router: remove redundant types and score aggregation#2016
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/gorgonia-golearn-82dce730

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 9, 2026

  • Remove route struct; store []Provider directly since route.model duplicated provider.ID()
  • Simplify selectProvider: use Size=1 instead of fetching 10 hits and aggregating scores by route (top-1 hit is always the best match)
  • Extract parseRouteIndex helper for doc ID parsing
  • Consolidate index cleanup on error paths with a single defer
  • Remove unused 'route' numeric field from Bleve index
  • Compute filterOutMaxTokens once instead of per providerFactory call
  • Trim verbose comments; update tests to match

Assisted-By: docker-agent

@dgageot dgageot requested a review from a team as a code owner March 9, 2026 18:34
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Assessment: 🟢 APPROVE

This refactoring successfully simplifies the rule-based router implementation by:

  • Removing the redundant route struct and storing []Provider directly
  • Optimizing search to fetch only the top-1 hit instead of 10 (since Bleve returns hits sorted by score)
  • Extracting parseRouteIndex helper for cleaner code organization
  • Consolidating error-path cleanup with a defer pattern
  • Removing the unused 'route' numeric field from the Bleve index
  • Computing filterOutMaxTokens once at the start

The code changes are well-structured and maintain correctness:

  • The defer cleanup pattern correctly uses a local cleanupErr variable to conditionally close the index on error paths
  • The parseRouteIndex function properly validates route indices with defensive checks
  • Test coverage has been updated to match the simplified implementation

No bugs or issues found in the changed code. The refactoring improves code clarity without introducing behavioral changes.

rumpl
rumpl previously approved these changes Mar 10, 2026
trungutt
trungutt previously approved these changes Mar 10, 2026
Copy link
Contributor

@trungutt trungutt left a comment

Choose a reason for hiding this comment

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

Good simplification of the rulebased router. Removing the redundant route struct, switching to top-1 search, and consolidating cleanup with defer are all correct. LGTM.

- Remove route struct; store []Provider directly since route.model
  duplicated provider.ID()
- Simplify selectProvider: use Size=1 instead of fetching 10 hits and
  aggregating scores by route (top-1 hit is always the best match)
- Extract parseRouteIndex helper for doc ID parsing
- Consolidate index cleanup on error paths with a single defer
- Remove unused 'route' numeric field from Bleve index
- Compute filterOutMaxTokens once instead of per providerFactory call
- Trim verbose comments; update tests to match

Assisted-By: docker-agent
@dgageot dgageot dismissed stale reviews from trungutt and rumpl via ad29365 March 10, 2026 08:02
@dgageot dgageot force-pushed the board/gorgonia-golearn-82dce730 branch from 4e497cd to ad29365 Compare March 10, 2026 08:02
@dgageot dgageot merged commit 050398e into docker:main Mar 10, 2026
5 checks passed
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.

3 participants