siyuan-note/siyuan · error

rerank HTTP

Error message

rerank HTTP %d: %s

What it means

Rerank in kernel/util/openai.go returns this error when the rerank endpoint responds with a status other than exactly 200 OK, including the raw response body. It is the rerank counterpart of the models-list HTTP error and reports the provider's own rejection payload. Callers such as rerankSqlBlocks and the rerank tests see the provider's status plus body text.

Solutions

  1. Parse the status and body in the error: fix credentials for 401, fix the rerank URL/model for 404/400, back off for 429/5xx
  2. Confirm the configured rerank model ID is offered by the provider (e.g. a Cohere/Jina-style rerank model name)
  3. Verify the rerank endpoint URL separately from the chat/models base URL — many providers host rerank on a different path
  4. Check provider quota/billing if the body reports quota or limit errors

Example fix

// before
model := "rerank-v2" // model not offered by this provider
// after
model := "rerank-v3.5" // a model ID the provider's rerank endpoint actually serves
Defensive patterns

Strategy: try-catch

Validate before calling

// ping the rerank endpoint with a 2-document probe before real use
probe := []string{"a", "b"}
_, _, err := Rerank("probe", probe, options)
if err != nil { disableRerankFor(err) }

Try / catch

indices, _, err := Rerank(query, docs, opts)
if err != nil {
    log.Printf("rerank unavailable, falling back to unranked: %v", err)
    return docs // graceful degradation
}

Prevention

When it happens

Trigger: Calling Rerank (via rerank SQL-block search or tests) where the rerank API returns e.g. 400 for an unsupported model name, 401 for bad credentials, 404 for a wrong rerank URL, or 429/5xx for throttling/outage.

Common situations: See trigger scenarios.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/7f31de395634c625. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai.go:675

	req.Header.Set("Authorization", "Bearer "+options.APIKey)

	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(options.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
	}

	results := rr.Results
	if nil == results && nil != rr.Output {
		results = rr.Output.Results
	}
	if nil == results {
		err = errors.New("rerank response missing results")
		return
	}

View on GitHub (pinned to 9f775e8a12)