Skip to content

feat(fusion): complete learned RRF weights with FitResult, N-retriever grid, bayesian fitting, and save/load (#49) - #223

Merged
codeforstartups merged 1 commit into
codeforstartups:developmentfrom
shivamm-gupta:issue-49-learned-fusion-weights
Sep 19, 2026
Merged

codeforstartups merged 1 commit into
codeforstartups:developmentfrom
shivamm-gupta:issue-49-learned-fusion-weights

Conversation

@shivamm-gupta

Copy link
Copy Markdown
Collaborator

Description

Completes the Learned Fusion Weights feature by addressing gaps in the original implementation (PR #204). Adds a structured FitResult return type, generalises grid search to N retrievers, introduces bayesian optimisation as a fitting strategy, and provides save/load serialisation for production workflows.

Related issue

Closes #49

Changes

FitResult dataclass

  • New structured return type for fit() with weights, score, method, and n_evaluations fields
  • to_dict() for dict conversion, save() / load() for JSON persistence
  • Exported from the dynavec package

Fixed _fit_grid() for N retrievers

  • Previously hardcoded for exactly 2 retrievers ([w1, 1-w1])
  • Now generalises to N-dimensional simplex via stars-and-bars partitioning
  • Retains the fast 1-D sweep path for the 2-retriever case

New _fit_bayesian() method

  • Uses scipy.optimize.minimize (Nelder-Mead) on a softmax-parameterised weight simplex
  • Gracefully falls back to random search with a warning if scipy is not installed
  • No new required dependency — scipy is optional

Updated notebook

  • Added method comparison table (grid vs random vs bayesian)
  • Added save/load workflow demo
  • Added FitResult inspection examples
  • Added 3-retriever grid search demo

Test coverage: 5 → 14 tests

  • FitResult dataclass fields and return type
  • Grid search for 2 and 3 retrievers
  • Random and bayesian fitting
  • Save/load JSON roundtrip
  • Error handling edge cases

Testing

  • Tests pass locally (uv run --no-sync pytest -q — all pass)
  • Ruff checks pass
  • Documentation updated (notebook)

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

…r grid, bayesian fitting, and save/load (codeforstartups#49)

- Add FitResult dataclass with to_dict(), save(), and load() methods
- Fix _fit_grid() to work with 3+ retrievers via simplex discretization
- Add _fit_bayesian() method using scipy Nelder-Mead with graceful fallback
- Export FitResult from dynavec package
- Expand test suite: 5 → 14 tests (grid/random/bayesian, serialization, edge cases)
- Update notebook with method comparison, save/load workflow, and 3-retriever demo
@shivamm-gupta
shivamm-gupta force-pushed the issue-49-learned-fusion-weights branch from d2665c2 to b682ffc Compare September 19, 2026 02:48

@codeforstartups codeforstartups left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Rounds out the learned-fusion work from #204 nicely (#49): a FitResult dataclass with JSON save()/load(), N-retriever grid search, and an optional Bayesian (Nelder-Mead on a softmax simplex) method that gracefully falls back to random with a warning when scipy is not installed — good defensive design. Verified locally: ruff clean, 14 fusion tests pass, CI green. Merging — thanks @shivamm-gupta! 🙌

@codeforstartups
codeforstartups merged commit 39ecac8 into codeforstartups:development Sep 19, 2026
3 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.

Learned fusion weights

2 participants