WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Bug]: cohere-rerank 解包失败:SGLang /v1/rerank 返回裸数组而非 {"results":[...]},自托管 Qwen3-Reranker 无法接入

Open JSJ189 opened this issue 1 month ago • 0 comments

环境

  • WeKnora:v0.8.3+(本地部署,构建自 d185f1d9;已核对 GitHub main 最新代码,行为相同)
  • 重排服务:SGLang 部署 Qwen3-Reranker-0.6B,端点 http://<sglang-host>:6002/v1
  • 模型配置:重排协议 cohere-rerank(provider: generic)

问题描述

接入 SGLang 的 /v1/rerank 时连接测试失败:

重排测试失败: decode response: json: cannot unmarshal array into Go value of type cohererank.response

请求实际已成功,SGLang 正常返回了分数。失败在响应解包:SGLang 返回裸 JSON 数组,cohere-rerank 要求 {"results": [...]} 对象。

复现

  1. 用 SGLang 启动任一 Reranker(如 Qwen3-Reranker-0.6B)。
  2. WeKnora 模型管理里新建重排模型,base URL 指向 http://<sglang-host>:6002/v1,协议选 cohere / generic。
  3. 点「测试连接」。

实测 SGLang 响应(curl,请求体 {"model", "query", "documents", "top_n"} 均被接受):

[
  {"score": 0.0015978454940173438, "document": "doc one", "index": 0, "meta_info": null},
  {"score": 0.0011695108220694027, "document": "doc two", "index": 1, "meta_info": null}
]

WeKnora 期望的形状(internal/models/api/cohererank/client.go):

type response struct {
    Results []result `json:"results"`
}

把数组灌进该对象即报 cannot unmarshal array into Go value of type cohererank.response,与报错逐字一致。

影响

  • 自托管 SGLang 无法接入重排。SGLang 是 Qwen3-Reranker 的常用部署方式之一。
  • 现有协议全部对不上:
    • cohere-rerank:请求同形(model / query / documents / top_n),响应外壳不同形(裸数组 vs results 包装)。
    • tei-rerank:响应虽是裸数组,但请求发 texts,SGLang 要求 documents,实测 400 Field required: documents;且 teirank 期望 {index, score, text},SGLang 的字段是 {index, score, document}。
  • 报错是一句 Go 内部 decode 错误,看不出协议不匹配,用户无从判断该换协议还是换服务。

与 #3512 的出入

#3512 的「不需要新协议」一节写:「Xinference /v1/rerank、Infinity /v1/rerank、vLLM /v1/rerank 和 generic / GPUStack 同形,指对 URL 就能打」。至少 SGLang 的 /v1/rerank 不是 Cohere 同形(响应是裸数组)。建议复核该清单时把 SGLang 纳入,并逐个实测响应样本而不是只对文档。

建议

  1. cohererank 的 post() 解对象失败时回退解析裸数组 []result。result 已兼容 score 字段与字符串 document,加回退后 SGLang 可直接工作,generic 即可覆盖。
  2. 或新增「裸数组响应 + documents 请求」的协议包,覆盖 SGLang 这类运行时。
  3. 改善报错:响应解包失败时提示协议不匹配,并附响应前若干字节,避免只抛 Go 类型错误。

JSJ189 avatar Oct 20 '26 09:10 JSJ189