Skip to content

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

Open
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/gorgonia-golearn-82dce730
Open

Simplify rulebased router: remove redundant types and score aggregation#2016
dgageot wants to merge 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

- 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.

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