siyuan-note/siyuan · error

rerank response missing results

Error message

rerank response missing results

What it means

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.

Source

Thrown at kernel/util/openai.go:666

		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 8641553a1f)

Solutions

  1. Verify the configured endpoint actually implements the rerank API with a `results` (or `output.results`) response field
  2. Log/inspect the raw 200 body to compare its schema against rerankResponse
  3. Check for provider API version changes and update the endpoint or model configuration
  4. Ensure the caller passes a non-empty documents slice so the provider can return rankings

Example fix

// before: pointing at a chat endpoint
APIBaseURL: "https://api.openai.com/v1/chat/completions"
// after: use the rerank endpoint
APIBaseURL: "https://api.openai.com/v1/rerank"
Defensive patterns

Strategy: validation

Validate before calling

var probe struct{ Results []json.RawMessage `json:"results"`; Output *struct{ Results []json.RawMessage `json:"results"` } `json:"output"` }
if json.Unmarshal(sample200Body, &probe) != nil || (probe.Results == nil && (probe.Output == nil || probe.Output.Results == nil)) {
    return errors.New("endpoint does not return a rerank-shaped 200 response")
}

Try / catch

indices, err := Rerank(query, docs, opts)
if errors.Is(err, errMissingResults) || strings.Contains(err.Error(), "missing results") {
    log.Warnf("provider returned no rankings; falling back")
    return fallbackOrdering(docs)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/3dc42f6e3cabd9d0. Report an issue: GitHub.