Support external rerank endpoints#1090
Conversation
Signed-off-by: Erik Bogado <erikbogado@gmail.com>
|
@ErikBPF is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe reranker now supports configurable external ChangesExternal reranking
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant rerank
participant RerankEndpoint
participant LocalPipeline
Client->>rerank: rerank candidate documents
rerank->>RerankEndpoint: POST /rerank
RerankEndpoint-->>rerank: ranked indices and scores
rerank-->>Client: reordered results
rerank->>LocalPipeline: use local reranking when external result is unavailable
LocalPipeline-->>rerank: locally scored results
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/state/reranker.ts`:
- Around line 13-22: Prevent apiKey in the rerank request from unconditionally
falling back to OPENAI_API_KEY. Update the baseUrl/apiKey selection so the
OpenAI credential is used only when RERANK_BASE_URL matches the configured
OpenAI endpoint; otherwise require RERANK_API_KEY and send no fallback
credential to third-party hosts.
- Around line 34-36: Validate and normalize RERANK_TIMEOUT_MS once before
constructing the AbortSignal in the reranking flow, accepting only a positive
finite numeric timeout and defaulting invalid, zero, or missing values to 30_000
milliseconds. Use the validated value in AbortSignal.timeout instead of passing
the raw environment string.
In `@test/reranker.test.ts`:
- Around line 39-47: Reset all rerank-related environment variables, including
OPENAI_API_KEY, in a beforeEach hook as well as afterEach. Update the test setup
around the existing lifecycle hooks so each test starts with a clean environment
and remains independent of ambient variables or execution order.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 14c7b9dd-4b05-4b04-b0c2-26cad90dca9d
📒 Files selected for processing (4)
.env.exampleREADME.mdsrc/state/reranker.tstest/reranker.test.ts
Restrict OPENAI_API_KEY reuse to matching OpenAI endpoints and normalize invalid reranker timeouts before creating abort signals.
Support external rerank endpoints
Summary
/rerankendpointsWhy
Deployments with centralized multilingual rerankers currently need to patch the
worker because reranking is fixed to the bundled English-oriented Xenova model.
An optional HTTP endpoint allows BGE-class or provider-hosted rerankers without
changing default behavior.
Fixes #1081.
Configuration
When
RERANK_BASE_URLis absent, behavior remains unchanged and the localreranker is used.
Validation
npx vitest run test/reranker.test.ts: 11 passednpm run build: passednpm run skills:check: 15 skills passednpm testunder Node 20: 1,422 passednpm testunder Node 22: 1,422 passednpm run test:integration: 17 passedgit diff --check main...HEAD: passedReview notes
Summary by CodeRabbit