siyuan-note/siyuan · warning

rerank returned duplicate index %d

Error message

rerank returned duplicate index %d

What it means

TestRerankModel's dedup check requires every returned index to be unique. A repeated index means the rerank response is malformed/non-conformant, so the probe rejects the provider.

Source

Thrown at kernel/util/openai.go:611

	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")
	}
	if maxBytes > 0 && len(data) > maxBytes {
		return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
	}
	mimeType := mimetype.Detect(data).String()
	if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Use a standards-conformant rerank provider (Jina, Cohere).
  2. If you wrote a shim/wrapper, ensure unique 0-based indices.
  3. Fall back to no reranking in search when the probe fails.
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := util.TestRerankModel(key, endpoint, model, 30); err != nil {
    log.Warnf("rerank provider rejected: %s; disabling rerank", err)
    disableRerank()
}

Prevention

When it happens

Trigger: Rerank provider returning the same index for multiple results (e.g. always 0, or echoing the query index); a custom rerank shim with an off-by-one bug.

Common situations: Broken or alpha-stage rerank services; providers that return a single repeated result; middleware that flattens results incorrectly.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/a967b98df84da096. Report an issue: GitHub.