{"record":{"id":"3dc42f6e3cabd9d0","repo":"siyuan-note/siyuan","slug":"rerank-response-missing-results","errorCode":null,"errorMessage":"rerank response missing results","messagePattern":"rerank response missing results","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":690,"sourceCode":"\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\n\tfor _, r := range results {\n\t\tif r.Index < 0 || r.Index >= len(documents) {\n\t\t\tcontinue\n\t\t}\n\t\tindices = append(indices, r.Index)\n\t\tscores = append(scores, r.RelevanceScore)\n\t}\n\treturn\n}\n\nfunc marshalRerankRequest(query string, documents []string, options RerankOptions) ([]byte, error) {\n\tif RerankRequestFormatDashScope == options.RequestFormat {\n\t\trequest := rerankDashScopeRequest{\n\t\t\tModel: options.Model,\n\t\t\tInput: rerankDashScopeInput{","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L672-L708","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: response shape mismatch\nendpoint := baseURL + \"/chat/completions\" // wrong endpoint, no results field\n// after\nendpoint := baseURL + \"/rerank\" // returns {\"results\":[{\"index\":0,...}]}","handlingStrategy":"validation","validationCode":"// inspect a sample 200 body once before trusting the provider\nvar probe map[string]any\nif json.Unmarshal(rawBody, &probe) == nil {\n    if _, ok := probe[\"results\"]; !ok && probe[\"output\"] == nil {\n        return errors.New(\"provider rerank schema lacks results\")\n    }\n}","typeGuard":"func hasRerankResults(body []byte) bool {\n    var rr struct {\n        Results []json.RawMessage `json:\"results\"`\n        Output  *struct {\n            Results []json.RawMessage `json:\"results\"`\n        } `json:\"output\"`\n    }\n    return json.Unmarshal(body, &rr) == nil && (rr.Results != nil || (rr.Output != nil && rr.Output.Results != nil))\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"missing results\") {\n    log.Printf(\"unexpected rerank schema, fallback: %v\", err)\n    return unrankedResults\n}","preventionTips":["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"],"tags":["rerank","response-parsing","ai-provider"],"backgroundTag":"unexpected-response-shape","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"}