siyuan-note/siyuan · error
rerank response missing results
Error message
rerank response missing results
What it means
Rerank validates that the provider response contains a results array, either at the top level (rr.Results) or nested under an alternate output shape (rr.Output.Results). If neither is present the response is unusable and this error is returned. It protects callers from nil-result panics when a provider returns a 200 body with an unexpected shape.
Solutions
- Log/inspect the raw 200 body returned by the provider to see the actual schema
- Verify the endpoint is a rerank endpoint, not a chat or completion endpoint
- Check the provider API version — switch to a version whose response includes 'results' (or 'output.results')
- If the provider uses a different field name, update the rerankResponse struct to match it
Example fix
// before: response shape mismatch
endpoint := baseURL + "/chat/completions" // wrong endpoint, no results field
// after
endpoint := baseURL + "/rerank" // returns {"results":[{"index":0,...}]} Defensive patterns
Strategy: validation
Validate before calling
// inspect a sample 200 body once before trusting the provider
var probe map[string]any
if json.Unmarshal(rawBody, &probe) == nil {
if _, ok := probe["results"]; !ok && probe["output"] == nil {
return errors.New("provider rerank schema lacks results")
}
} Type guard
func hasRerankResults(body []byte) bool {
var rr struct {
Results []json.RawMessage `json:"results"`
Output *struct {
Results []json.RawMessage `json:"results"`
} `json:"output"`
}
return json.Unmarshal(body, &rr) == nil && (rr.Results != nil || (rr.Output != nil && rr.Output.Results != nil))
} Try / catch
if err != nil && strings.Contains(err.Error(), "missing results") {
log.Printf("unexpected rerank schema, fallback: %v", err)
return unrankedResults
} Prevention
- Confirm the endpoint URL is a rerank endpoint, not chat/completions
- Pin the provider API version and re-test response shape after upgrades
- Add an integration test asserting 'results' exists for your configured provider
When it happens
Trigger: The rerank endpoint returns HTTP 200 but the JSON body has no 'results' field and no 'output.results' field — e.g. an error object, a different schema, or an empty malformed response.
Common situations: Pointing Rerank at a chat/completions endpoint instead of a rerank endpoint; provider changed or versioned its response schema; provider returns 200 with an embedded error for partial failures; proxy rewriting the body.
Related errors
- rerank HTTP
- rerank returned indices for documents
- rerank returned duplicate index
- invalid AI provider HTTP headers
- list models HTTP
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/3dc42f6e3cabd9d0.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/openai.go:690
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
}
for _, r := range results {
if r.Index < 0 || r.Index >= len(documents) {
continue
}
indices = append(indices, r.Index)
scores = append(scores, r.RelevanceScore)
}
return
}
func marshalRerankRequest(query string, documents []string, options RerankOptions) ([]byte, error) {
if RerankRequestFormatDashScope == options.RequestFormat {
request := rerankDashScopeRequest{
Model: options.Model,
Input: rerankDashScopeInput{View on GitHub (pinned to 9f775e8a12)