{"record":{"id":"7f31de395634c625","repo":"siyuan-note/siyuan","slug":"rerank-http-d-s","errorCode":null,"errorMessage":"rerank HTTP %d: %s","messagePattern":"rerank HTTP (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":675,"sourceCode":"\treq.Header.Set(\"Authorization\", \"Bearer \"+options.APIKey)\n\n\tctx, cancel := context.WithTimeout(context.Background(), time.Duration(options.Timeout)*time.Second)\n\tdefer cancel()\n\treq = req.WithContext(ctx)\n\n\tresp, err := getRerankHTTPClient().Do(req)\n\tif nil != err {\n\t\tlogging.LogErrorf(\"rerank request failed: %s\", err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\trespBody, err := io.ReadAll(resp.Body)\n\tif nil != err {\n\t\treturn\n\t}\n\tif http.StatusOK != resp.StatusCode {\n\t\terr = fmt.Errorf(\"rerank HTTP %d: %s\", resp.StatusCode, string(respBody))\n\t\tlogging.LogErrorf(\"rerank failed: %s\", err)\n\t\treturn\n\t}\n\n\tvar rr rerankResponse\n\tif err = json.Unmarshal(respBody, &rr); nil != err {\n\t\treturn\n\t}\n\n\tresults := rr.Results\n\tif nil == results && nil != rr.Output {\n\t\tresults = rr.Output.Results\n\t}\n\tif nil == results {\n\t\terr = errors.New(\"rerank response missing results\")\n\t\treturn\n\t}\n","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L657-L693","documentation":"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.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","solutions":["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","Confirm the configured rerank model ID is offered by the provider (e.g. a Cohere/Jina-style rerank model name)","Verify the rerank endpoint URL separately from the chat/models base URL — many providers host rerank on a different path","Check provider quota/billing if the body reports quota or limit errors"],"exampleFix":"// before\nmodel := \"rerank-v2\" // model not offered by this provider\n// after\nmodel := \"rerank-v3.5\" // a model ID the provider's rerank endpoint actually serves","handlingStrategy":"try-catch","validationCode":"// ping the rerank endpoint with a 2-document probe before real use\nprobe := []string{\"a\", \"b\"}\n_, _, err := Rerank(\"probe\", probe, options)\nif err != nil { disableRerankFor(err) }","typeGuard":null,"tryCatchPattern":"indices, _, err := Rerank(query, docs, opts)\nif err != nil {\n    log.Printf(\"rerank unavailable, falling back to unranked: %v\", err)\n    return docs // graceful degradation\n}","preventionTips":["Validate the rerank model ID against the provider's model list at config time","Keep rerank endpoint URL separate from the chat base URL in configuration","Implement a fallback to unranked (FTS-only) results when rerank errors occur"],"tags":["http","rerank","ai-provider"],"backgroundTag":"api-error-response","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}