Repository navigation
Go: implement Rerank in Novita driver - #15014
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughHidden review stack artifactWalkthroughThis 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. ChangesNovita Rerank Feature
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
Haruko386
left a comment
There was a problem hiding this comment.
@RenzoMXD LGTM, thank you for your contribution. ❤
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@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. |
565ed7e to
58d1b81
Compare
### 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.
|
@Haruko386 @JinHai-CN |
What problem does this PR solve?
Fixes #15012
The Novita Go driver landed in #14850 and shipped a stub
Rerankmethod 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/rerankthat accepts the Cohere-compatible request shape ({model, query, documents, top_n}) withAuthorization: Bearer <api_key>.baai/bge-reranker-v2-m3is documented in Novita's model library with a 1024-token limit.Changes
internal/entity/models/novita.go: implementNovitaModel.Rerank.baseURLForRegionhelper.URLSuffix.Rerank.{model, query, documents, top_n}POST body, defaultingtop_ntolen(documents)so every input gets scored, and honoringRerankConfig.TopNwhen set.{results: [{index, relevance_score}]}and emit oneRerankResultper response item in the API's ranking order, rejecting out-of-range indices and duplicates so the output always lines up with the input. Same shape as the merged NVIDIA (Go: implement Rerank in NVIDIA driver #14778), Aliyun (Go: implement Rerank in Aliyun driver #14676), Gitee (Go: implement Rerank in Gitee AI driver #14656), and ZhipuAI (Go: implement Rerank in ZhipuAI driver #14608) Rerank implementations.conf/models/novita.json:"rerank": "openai/v1/rerank"tourl_suffix.baai/bge-reranker-v2-m3to the default model entries so it appears in the model picker.internal/entity/models/novita_test.go:newNovitaForTestto populate the Rerank URL suffix.TestNovitaRerankReturnsNoSuchMethodstub assertion (and the already-staleTestNovitaEmbedReturnsNoSuchMethodleft behind after Go: implement Embed (embeddings) in Novita driver #14895).newNovitaServerhelper (Bearer + Content-Type + path assertions): happy-path reordering by index,RerankConfig.TopNforwarding, 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