{"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":666,"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":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/util/openai.go#L648-L684","documentation":"After a successful 200 response, Rerank unmarshals the body into rerankResponse and accepts results either at the top level or nested under Output.Results (OpenAI-style responses). If neither location contains results, it throws this error: the provider answered 200 but with a payload shape the parser does not recognize or an empty result set.","triggerScenarios":"A rerank provider returning 200 with a JSON shape lacking both `results` and `output.results` (different API schema), or a successful call that genuinely returned zero ranked results while documents were non-empty.","commonSituations":"Pointing SiYuan at a non-rerank endpoint (e.g. a chat completions URL); a provider changed its response schema; using a proxy that alters the payload; passing an empty or degenerate document list the provider answers with an empty body.","solutions":["Verify the configured endpoint actually implements the rerank API with a `results` (or `output.results`) response field","Log/inspect the raw 200 body to compare its schema against rerankResponse","Check for provider API version changes and update the endpoint or model configuration","Ensure the caller passes a non-empty documents slice so the provider can return rankings"],"exampleFix":"// before: pointing at a chat endpoint\nAPIBaseURL: \"https://api.openai.com/v1/chat/completions\"\n// after: use the rerank endpoint\nAPIBaseURL: \"https://api.openai.com/v1/rerank\"","handlingStrategy":"validation","validationCode":"var probe struct{ Results []json.RawMessage `json:\"results\"`; Output *struct{ Results []json.RawMessage `json:\"results\"` } `json:\"output\"` }\nif json.Unmarshal(sample200Body, &probe) != nil || (probe.Results == nil && (probe.Output == nil || probe.Output.Results == nil)) {\n    return errors.New(\"endpoint does not return a rerank-shaped 200 response\")\n}","typeGuard":null,"tryCatchPattern":"indices, err := Rerank(query, docs, opts)\nif errors.Is(err, errMissingResults) || strings.Contains(err.Error(), \"missing results\") {\n    log.Warnf(\"provider returned no rankings; falling back\")\n    return fallbackOrdering(docs)\n}","preventionTips":["Point only at endpoints documented to implement the rerank response schema","Pin/record the provider API version and review changelogs for response schema changes","Log the raw 200 body once during integration to confirm the shape","Never route rerank calls through rewriting proxies"],"tags":["api","rerank","response-shape","json"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}