Repository navigation
Go: implement Rerank in vLLM driver (#14878) - #14880
Conversation
Replace the VllmModel.Rerank stub with a real implementation against vLLM's Jina/Cohere-compatible /v1/rerank endpoint (stable since v0.7). Mirrors the NVIDIA driver shape (infiniflow#14778) with two vLLM-specific adjustments: - documents is sent as a flat []string rather than [{text: "..."}] - Authorization header is set only when APIConfig.ApiKey is non-empty, matching the local-deploy semantics of the existing Embed/ListModels paths in this file Defaults top_n to len(documents) so callers get a score per input; honors RerankConfig.TopN only when 0 < TopN < len(documents). Bounds- checks response indices against the input slice. No interface change, no DDL, no frontend change. Wires "rerank": "rerank" into conf/models/vllm.json url_suffix so the existing baseURL join used by Embed/ListModels reaches /v1/rerank. Adds vllm_rerank_test.go covering happy path, top_n clamp, empty documents, missing model name, optional-API-key (vLLM-specific), HTTP error propagation, and out-of-range index rejection.
📝 WalkthroughWalkthroughThis PR implements vLLM reranking support by adding the ChangesvLLM Rerank Feature
Sequence DiagramsequenceDiagram
participant Caller
participant VllmModel
participant vLLMAPI as vLLM API
Caller->>VllmModel: Rerank(modelName, query, documents)
VllmModel->>VllmModel: Validate inputs and region
VllmModel->>vLLMAPI: POST /v1/rerank with model, query, documents, top_n
note over vLLMAPI: Authorization header<br/>set only if ApiKey present
vLLMAPI-->>VllmModel: {results: [{index, relevance_score}]}
VllmModel->>VllmModel: Validate returned indices within bounds
VllmModel-->>Caller: RerankResponse{Data: []RerankResult}
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 |
|
Hi, @wangq8 , |
|
Hi, @JinHai-CN , |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14880 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi, @JinHai-CN , |
What problem does this PR solve?
Closes #14878.
VllmModel.Rerank()in internal/entity/models/vllm.go:551 is currently a stub returningnil, fmt.Errorf("%s, Rerank not implemented", z.Name()), and conf/models/vllm.json is missing arerankentry inurl_suffix. Chat (long-standing) and embeddings (#14688) already work, so rerank is the last missing leg of the retrieval pipeline for operators running everything on a single self-hosted vLLM server — today they have to point rerank at a different provider, which defeats the point of a fully local deployment.Upstream vLLM has supported a Jina/Cohere-compatible
POST /v1/rerankendpoint since v0.7 (vllm-project/vllm#12376). The request/response shape is essentially identical to the NVIDIA driver landed in #14778, so this PR mirrors that structure with two vLLM-specific adjustments.This PR replaces the stub with a real implementation against vLLM's
/v1/rerank:POST {baseURL}/rerank{"model": "<modelName>", "query": "<query>", "documents": [...], "top_n": <int>}— documents are a flat[]string, not wrapped as{text: "..."}like NVIDIA's/ranking.{"results": [{"index": int, "relevance_score": float}, ...]}(Jina-compatible; the optionaldocumentfield is ignored since callers reconstruct text viaIndex).Authorization: Bearer <ApiKey>is set only whenAPIConfig.ApiKeyis non-empty, matching the existingEmbed/ListModelsbehaviour in this file. vLLM is a local driver and can be deployed without an API key.The return shape matches the existing
*RerankResponsecontract used by the NVIDIA (nvidia.go:461), Aliyun (aliyun.go:507), and ZhipuAI (zhipu-ai.go:554) drivers, i.e.Data []RerankResultcarrying{Index, RelevanceScore}in the API's ranking order. Callers that need original-input order sort byIndex.Behaviour requirements from the issue, all covered:
documents→ returns&RerankResponse{}without an HTTP call.modelName→"model name is required"validation error.rerankConfig.TopNhonored when0 < TopN < len(documents); otherwisetop_ndefaults tolen(documents)so callers get a score per input."vLLM rerank API error: <status>, body: <body>").indexvalues are bounds-checked againstlen(documents).Scope:
Rerankstub at line 551 with a real implementation; addsvllmRerankRequest/vllmRerankResponsetypes for the slim subset of the payload we need. Region/baseURL resolution, 30s context timeout, conditional bearer header, and error wrapping all follow the existing patterns in this file."rerank": "rerank"tourl_suffix, joined to the operator-configured vLLM base URL the same way the NVIDIA driver joins at nvidia.go:485.httptest-backed tests mirroringnvidia_rerank_test.go: happy path (out-of-order ranking → Index preservation),top_nclamp toRerankConfig.TopN, empty-documents short-circuit, missing-model-name validation, HTTP error propagation, out-of-range index rejection, and a vLLM-specificTestVllmRerankWithoutAPIKeylocking in the optional-auth behaviour that distinguishes this driver from NVIDIA.Out of scope: no interface change, no DDL, no frontend change. Chat, embeddings, and balance paths are untouched. No new user-facing docs required beyond the existing rerank model setup page — vLLM joins the list of providers whose rerank model can be selected once
/v1/rerankis exposed by the server.Type of change