Repository navigation
Go: implement Rerank in Xinference driver - #15032
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)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds Xinference ChangesXinference rerank support
Sequence DiagramsequenceDiagram
participant Caller
participant XinferenceModel
participant HTTPClient
participant XinferenceAPI
Caller->>XinferenceModel: Rerank(modelName, query, documents)
alt empty documents
XinferenceModel-->>Caller: empty RerankResponse
else missing model name
XinferenceModel-->>Caller: error "model name is required"
else missing rerank suffix
XinferenceModel-->>Caller: error "no rerank URL suffix configured"
else valid input
XinferenceModel->>HTTPClient: POST /v1/rerank (model, query, documents, top_n)
HTTPClient->>XinferenceAPI: request body
XinferenceAPI-->>HTTPClient: {results: [{index, relevance_score}]}
HTTPClient-->>XinferenceModel: response body
XinferenceModel->>XinferenceModel: validate indices (in-range, unique)
alt invalid indices
XinferenceModel-->>Caller: error "invalid index"
else valid indices
XinferenceModel-->>Caller: RerankResponse with reordered Data
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
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 for your contribution
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15032 +/- ##
=======================================
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. |
80c72e8 to
bd2fea9
Compare
|
@JinHai-CN |
What problem does this PR solve?
Fixes #14816
The Xinference Go driver landed chat in #14938 and Embed is in review in #14932, but
Rerankshipped as a stub that returns"xinference, no such method". Tenants who launch a rerank model with--model-type rerankon 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/rerankand 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; the builtin rerank model catalog listsbge-reranker-base,bge-reranker-large,bge-reranker-v2-m3, and others.Changes
internal/entity/models/xinference.go: implementXinferenceModel.Rerank.baseURLForRegion(xinferenceRegion(...)), which normalizes bothhttp://host:9997andhttp://host:9997/v1to the same root before appendingURLSuffix.Rerank. This matches the chat/ListModels code paths.{model, query, documents, top_n}POST body, defaultingtop_ntolen(documents)and honoringRerankConfig.TopNwhen set.setXinferenceAuthhelper — only setsAuthorization: Bearer <api_key>when a non-empty key is configured, since default Xinference deployments run without auth.nonStreamCallTimeout, matching the chat / ListModels code paths.{results: [{index, relevance_score}]}and emit oneRerankResultper scored document in the API's ranking order, rejecting out-of-range indices and duplicates the same way the merged Novita (Go: implement Rerank in Novita driver #15014) and NVIDIA (Go: implement Rerank in NVIDIA driver #14778) Rerank implementations do.conf/models/xinference.json: add"rerank": "v1/rerank"tourl_suffix.internal/entity/models/xinference_test.go: extendnewXinferenceForTestwith the rerank URL suffix; drop the now-obsoleteRerank → no such methodassertion inTestXinferenceUnsupportedMethodsReturnNoSuchMethod; add 9 new Rerank unit tests covering happy-path index reordering,/v1base-URL normalization,RerankConfig.TopNforwarding, empty-documents short-circuit, missing model name, out-of-range index, duplicate index, HTTP error surfacing, and missing-rerank-suffix safety check.Type of change
Test plan
gofmt -l internal/entity/models/xinference.go internal/entity/models/xinference_test.go— cleanpython3 -c "import json; json.load(open('conf/models/xinference.json'))"— JSON validgo build ./internal/entity/models/...— succeedsgo test -run TestXinference ./internal/entity/models/...— 19/19 PASS (10 existing + 9 new Rerank)xprobe/xinference:latest-cpuDocker container:Rerankdriver call with a not-yet-loaded model correctly surfaces the upstream 404 (Xinference rerank API error: 404 Not Found, body: {"detail":"Model not found...uid: bge-reranker-base..."}); the/v1-in-base-URL variant produces the same 404, provingnormalizeXinferenceBaseURLstrips and re-appends correctly.Notes for reviewers
rag/llm/rerank_model.py:77XInferenceRerankalready POSTs to<base>/v1/rerankwith a similar payload. The Go implementation sends only the documented Cohere fields (model,query,documents,top_n); Python'sreturn_documents/return_lenextras are omitted to keep parity with the rest of the Go rerank cluster.