siyuan-note/siyuan · error

rerank HTTP %d: %s

Error message

rerank HTTP %d: %s

What it means

Rerank surfaces any non-200 response from the rerank endpoint with this status+body message so the user sees the provider's actual error. Rerank endpoint paths are provider-specific (Jina /v1/rerank, Cohere /v1/rerank, Aliyun compatible-api/v1/reranks), so misconfiguration is the most common cause.

Source

Thrown at kernel/util/openai.go:568

	req.Header.Set("Authorization", "Bearer "+apiKey)

	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
	defer cancel()
	req = req.WithContext(ctx)

	resp, err := getRerankHTTPClient().Do(req)
	if nil != err {
		logging.LogErrorf("rerank request failed: %s", err)
		return
	}
	defer resp.Body.Close()

	respBody, err := io.ReadAll(resp.Body)
	if nil != err {
		return
	}
	if http.StatusOK != resp.StatusCode {
		err = fmt.Errorf("rerank HTTP %d: %s", resp.StatusCode, string(respBody))
		logging.LogErrorf("rerank failed: %s", err)
		return
	}

	var rr rerankResponse
	if err = json.Unmarshal(respBody, &rr); nil != err {
		return
	}

	for _, r := range rr.Results {
		if r.Index < 0 || r.Index >= len(documents) {
			continue
		}
		indices = append(indices, r.Index)
		scores = append(scores, r.RelevanceScore)
	}
	return
}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Set the rerank endpoint to the provider's FULL rerank path per their docs, not just the base.
  2. Use an API key authorized for rerank models.
  3. Verify the model name against the provider's catalog.
  4. Read the body in the message; it states the upstream reason.

Example fix

# before: endpoint = https://api.jina.ai/v1        -> rerank HTTP 404
# after:  endpoint = https://api.jina.ai/v1/rerank
Defensive patterns

Strategy: try-catch

Try / catch

if _, _, err := util.Rerank(q, docs, key, endpoint, model, 0, 30); err != nil {
    return fmt.Errorf("rerank provider error: %w", err) // err already has status+body
}

Prevention

When it happens

Trigger: Wrong rerank endpoint URL (base instead of full path); 401 API key not authorized for rerank; 404 model not found; 422 malformed request; 429 rate limit; 5xx provider error.

Common situations: Endpoint field filled with only the base URL; API key issued for chat but not rerank; model name typo; provider does not expose rerank at all.

Related errors


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