siyuan-note/siyuan · warning
rerank returned %d indices for %d documents
Error message
rerank returned %d indices for %d documents
What it means
TestRerankModel sends two trivial documents and expects exactly two indices back. If the count differs, the provider is applying a default top_n (returning fewer), returning scores without indices, or returning out-of-range indices that Rerank's loop filters out. The probe treats such a provider as non-conformant for the connectivity test.
Source
Thrown at kernel/util/openai.go:605
func truncateRerankDocument(document string) string {
runes := []rune(document)
if len(runes) > rerankDocTextMaxRunes {
return string(runes[:rerankDocTextMaxRunes])
}
return document
}
// TestRerankModel 测试重排模型可用性,用极简 query+documents 发一次重排请求验证连通性与鉴权。
// 返回值:matched 表示是否连通成功,err 为请求错误(鉴权失败、网络异常、模型不存在等,原样返回便于调用方展示原因)。
func TestRerankModel(apiKey, apiBaseURL, model string, timeout int) (matched bool, err error) {
documents := []string{"a", "b"}
indices, _, err := Rerank("1", documents, apiKey, apiBaseURL, model, len(documents), timeout)
if nil != err {
return
}
if len(indices) != len(documents) {
err = fmt.Errorf("rerank returned %d indices for %d documents", len(indices), len(documents))
return
}
seen := make(map[int]bool, len(indices))
for _, index := range indices {
if seen[index] {
err = fmt.Errorf("rerank returned duplicate index %d", index)
return
}
seen[index] = true
}
matched = true
return
}
// PrepareModelImage 校验并按需缩放图片,尽量保留多模态模型支持的原始格式和图片质量。
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
if len(data) == 0 {
return PreparedImage{}, errors.New("image data is empty")View on GitHub (pinned to 251596fc0d)
Solutions
- Confirm the provider implements the standard {results:[{index,relevance_score}]} schema with 0-based indices.
- Inspect the raw rerank response to see whether indices are 0-based and complete.
- Verify the model name actually supports rerank.
- If non-conformant, use a different provider or configure rerank manually without relying on the probe.
Defensive patterns
Strategy: try-catch
Try / catch
if ok, err := util.TestRerankModel(key, endpoint, model, 30); err != nil || !ok {
log.Warnf("rerank provider may be non-conformant: %s; falling back to no rerank", err)
} Prevention
- Prefer providers that return all documents with 0-based indices
- Inspect the rerank response schema before adopting a provider
- Treat rerank as optional and degrade to original ranking on failure
When it happens
Trigger: Rerank provider that caps results at a default top_n=1; provider returning scores without an index field; provider returning 1-based indices (filtered out as out-of-range for a 2-doc input).
Common situations: Provider whose default top_n is 1 and ignores the top_n=len(docs) hint; non-standard response schema; provider that omits low-relevance documents.
Related errors
- rerank returned duplicate index %d
- rerank HTTP %d: %s
- image data is empty
- invalid frontend capability ID: %s
- frontend capability description is required: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/f28ad574b03a93db.
Report an issue: GitHub.