Skip to content

feat(rerank): per-pool rerank callback for vector search#57

Merged
techiejd merged 19 commits into
mainfrom
feat/rerank-callback
May 19, 2026
Merged

feat(rerank): per-pool rerank callback for vector search#57
techiejd merged 19 commits into
mainfrom
feat/rerank-callback

Conversation

@techiejd
Copy link
Copy Markdown
Owner

Summary

  • Adds optional rerank: { multiplier, callback } on each pool's embeddingConfig. When set, the plugin fetches Math.floor(limit * multiplier) candidates from the adapter, hands them to the user-supplied callback, and trims the callback's output to the caller's limit. Provider-agnostic — bring your own Voyage / Cohere / local cross-encoder.
  • Non-rerank path is unchanged: limit is forwarded to the adapter as-is (possibly undefined), preserving existing direct payload-API caller behavior. The ?? 10 default only applies inside the rerank branch.
  • multiplier must be a finite number >= 1 (floats allowed, Math.floor applied). Invalid configs are rejected at plugin init with a pool-named error. Callback errors propagate to the caller — no silent fallback.
  • Minor bump across all four fixed packages via changeset.

Test plan

  • pnpm test:int dev/specs/vectorSearchRerank.spec.ts — 8 tests: callback invocation + ordering, multiplier (int and float) expanding fetch, limit omitted defaults to 10, no-rerank baseline, trim when callback returns more than limit, return-fewer when callback returns fewer, error propagation.
  • pnpm test:int dev/specs/rerankValidation.spec.ts — 6 tests: multiplier 0 / -1 / NaN / Infinity / non-function callback all throw; valid config builds cleanly.
  • pnpm test:int — full integration suite, 29 files / 81 tests passing.
  • pnpm build:types — typecheck clean.

techiejd added 19 commits May 18, 2026 23:00
Adds opt-in RerankConfig { multiplier, callback } on EmbeddingConfig.
Pipeline fetches Math.floor(limit * multiplier) candidates, hands them
to the user callback, then trims to limit. Errors propagate.
10-task TDD plan covering types, wiring, validation, tests, README,
and changeset. Implements the design at
docs/superpowers/specs/2026-05-18-rerank-callback-design.md.
- Task 1: move RerankFn/RerankConfig re-export here so Task 2's red test
  fails on the wiring assertion, not module resolution
- Task 2: baseline call now uses a no-rerank handlers instance so the
  callback fires exactly once and the reversal assertion is meaningful
- Task 3: non-rerank path forwards `limit` as-is (no `?? 10`), preserving
  existing behavior for direct payload-API callers; `?? 10` only applies
  on the rerank path
….callback

- Merge orphan tail-note into bulkEmbeddingsFns JSDoc where it semantically belongs (also fixes a stale name reference)
- Add JSDoc to RerankConfig.callback for consistency with other *Fn fields
…pulated

Without cron+autoRun, vectorization jobs queue but never execute, leaving
the mock adapter empty. Test 1's ordering assertion then compares
[].reverse() to [] — trivially equal. Mirror the autoRun pattern used in
vectorSearch.spec.ts so search() returns real seeded chunks.
- Defend the example callback against undefined from results[r.index]
- Split trailing paragraph into Multiplier / Limit / Errors / Validation
  and call out the default-limit divergence vs the non-rerank path
- Add Reranking entry to the Features list and Table of Contents
@techiejd techiejd merged commit 19ea3a0 into main May 19, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request May 19, 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