Skip to content

Go: implement Rerank in Novita driver - #15014

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
ai-mountain:feat/15012-novita-rerank
May 21, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
ai-mountain:feat/15012-novita-rerank

Conversation

@ai-mountain

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes #15012

The Novita Go driver landed in #14850 and shipped a stub Rerank method that returned "novita, no such method", so Novita could not be used as a rerank provider in RAGFlow. This PR fills that gap, in the same way #14895 filled the Embed gap on the same driver.

Novita exposes a public rerank endpoint at POST https://api.novita.ai/openai/v1/rerank that accepts the Cohere-compatible request shape ({model, query, documents, top_n}) with Authorization: Bearer <api_key>. baai/bge-reranker-v2-m3 is documented in Novita's model library with a 1024-token limit.

Changes

  • internal/entity/models/novita.go: implement NovitaModel.Rerank.
  • conf/models/novita.json:
    • Add "rerank": "openai/v1/rerank" to url_suffix.
    • Add baai/bge-reranker-v2-m3 to the default model entries so it appears in the model picker.
  • internal/entity/models/novita_test.go:
    • Extend newNovitaForTest to populate the Rerank URL suffix.
    • Drop the obsolete TestNovitaRerankReturnsNoSuchMethod stub assertion (and the already-stale TestNovitaEmbedReturnsNoSuchMethod left behind after Go: implement Embed (embeddings) in Novita driver #14895).
    • Add 8 unit tests using the existing newNovitaServer helper (Bearer + Content-Type + path assertions): happy-path reordering by index, RerankConfig.TopN forwarding, empty-documents short-circuit, missing api key, missing model name, out-of-range index, duplicate index, HTTP error surfacing, and missing-rerank-suffix safety check.

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0cf5e04-0340-4e18-aea7-354efa102780

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3b41e and 58d1b81.

📒 Files selected for processing (3)
  • conf/models/novita.json
  • internal/entity/models/novita.go
  • internal/entity/models/novita_test.go

📝 Walkthrough

Hidden review stack artifact

Walkthrough

This PR adds Novita rerank support: updates config with a rerank endpoint and model, implements (*NovitaModel).Rerank with request/response handling and index validation, and adds tests covering happy path and error/edge cases.

Changes

Novita Rerank Feature

Layer / File(s) Summary
Rerank Configuration
conf/models/novita.json
Extends url_suffix with rerank and adds reranker model entry (baai/bge-reranker-v2-m3) with max_tokens and model_types set to rerank.
Rerank Request/Response and Implementation
internal/entity/models/novita.go
Adds novitaRerankResult/novitaRerankResponse structs and implements (*NovitaModel).Rerank with input validation, request body construction, POST to configured rerank endpoint, response unmarshalling, index range/duplicate validation, and RerankResponse generation.
Test Setup and Rerank Test Suite
internal/entity/models/novita_test.go
Updates test driver URLSuffix to include Rerank and adds tests: happy path reordering by index, RerankConfig.TopN propagation, empty-doc short-circuit, API key/model validations, invalid/duplicate index rejection, HTTP error surface, and missing rerank suffix rejection.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant NovitaModel
  participant NovitaAPI as Novita API
  participant RerankResponse
  Caller->>NovitaModel: Rerank(model, query, documents, apiConfig, rerankConfig)
  NovitaModel->>NovitaModel: validate apiKey, modelName, documents
  NovitaModel->>NovitaModel: build URL using URLSuffix.Rerank
  NovitaModel->>NovitaAPI: POST {model, query, documents, top_n} (Bearer token)
  NovitaAPI-->>NovitaModel: JSON {results:[{index,relevance_score,...},...]}
  NovitaModel->>NovitaModel: unmarshal, validate indices (range + uniqueness)
  NovitaModel->>RerankResponse: build RerankResult entries
  RerankResponse-->>Caller: return *RerankResponse
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

  • infiniflow/ragflow#14850: Initial Novita provider implementation that established driver structure and stubbed Rerank.

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped to patch the Novita gate,
Sent queries, docs, and waited to rate.
Indices checked, duplicates shunned,
Scores returned and neatly run.
One rabbit, one API — rerank is great!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: implement Rerank in Novita driver' accurately summarizes the primary change of implementing the Rerank method in the Novita Go driver.
Description check ✅ Passed The PR description follows the template with both required sections completed: it clearly describes what problem it solves (Fixes #15012) and the detailed changes, and explicitly marks this as a 'New Feature'.
Linked Issues check ✅ Passed The implementation fully addresses all coding requirements from issue #15012: implements Rerank with Bearer auth, Cohere-compatible request body, per-call timeout, response parsing and validation, and updates conf/models/novita.json with rerank URL suffix and model entry.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the Rerank feature in the Novita driver and its tests, with no unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@RenzoMXD LGTM, thank you for your contribution. ❤

@Haruko386 Haruko386 added the ci Continue Integration label May 20, 2026
@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (4a91ca5) to head (58d1b81).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15014   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN

Copy link
Copy Markdown
Member

@RenzoMXD Since previous PR includes a binary file which is very big. So, I reset the head of main branch. Would you please re-submit the commit from current HEAD of main branch? Thank you very much.

@ai-mountain
ai-mountain force-pushed the feat/15012-novita-rerank branch from 565ed7e to 58d1b81 Compare May 20, 2026 12:29
JinHai-CN pushed a commit that referenced this pull request May 21, 2026
### What problem does this PR solve?

Fixes #14816

The Xinference Go driver landed chat in #14938 and Embed is in review in
#14932, but `Rerank` shipped as a stub that returns `"xinference, no
such method"`. Tenants who launch a rerank model with `--model-type
rerank` on their Xinference instance cannot route it through the Go API
server. This PR fills the gap.

Xinference exposes an OpenAI-compatible REST API. The rerank endpoint is
at `POST <base>/v1/rerank` and accepts the Cohere-shaped body `{model,
query, documents, top_n}`, returning `{results: [{index,
relevance_score}]}` — the same wire shape used by the merged NVIDIA
(#14778), Aliyun (#14676), Gitee (#14656), ZhipuAI (#14608), Novita
(#15014), and LocalAI (#14813) Rerank implementations. Documented in
[Xinference rerank
docs](https://inference.readthedocs.io/en/v1.6.1/models/model_abilities/rerank.html);
the [builtin rerank model
catalog](https://inference.readthedocs.io/en/stable/models/builtin/rerank/)
lists `bge-reranker-base`, `bge-reranker-large`, `bge-reranker-v2-m3`,
and others.
@JinHai-CN
JinHai-CN merged commit fec0b96 into infiniflow:main May 21, 2026
1 check passed
@ai-mountain
ai-mountain deleted the feat/15012-novita-rerank branch May 21, 2026 03:27
@ai-mountain

Copy link
Copy Markdown
Contributor Author

@Haruko386 @JinHai-CN
Thanks for merging this PR.
#14932 and #15024 is now ready to merge.
Please merge them if nothing else is needed to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement Rerank in the Novita Go driver

3 participants