alibaba/spring-ai-alibaba · error · RuntimeException
rerank response is null.
Error message
rerank response is null.
What it means
DashscopeReranker.process calls the DashScope rerank endpoint through a RetryTemplate; if the HTTP response entity has a null body, it throws a plain RuntimeException "rerank response is null.". This indicates the rerank API returned no payload despite (apparently) completing, so no relevance scores can be computed.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/model/reranker/dashscope/DashscopeReranker.java:103
*/
@NotNull
@Override
public List<Document> process(@NotNull Query query, @NotNull List<Document> documents) {
if (CollectionUtils.isEmpty(documents)) {
return documents;
}
Assert.notNull(query, "query must not be null");
Assert.notNull(documents, "documents must not be null");
DashScopeApi.RerankRequest rerankRequest = createRequest(query, documents, options);
ResponseEntity<DashScopeApi.RerankResponse> responseEntity = this.retryTemplate
.execute(ctx -> this.dashscopeApi.rerankEntity(rerankRequest));
var response = responseEntity.getBody();
if (response == null) {
throw new RuntimeException("rerank response is null.");
}
return response.output().results().stream().map(data -> {
var doc = documents.get(data.index());
return Document.builder()
.score(data.relevanceScore())
.id(doc.getId())
.text(doc.getText())
.metadata(doc.getMetadata())
.media(doc.getMedia())
.build();
}).toList();
}
/**
* Creates a rerank request for the DashScope API.
* @param query The search query
* @param documents List of documents to rerankView on GitHub (pinned to f82da0b50f)
Solutions
- Log the HTTP status code of responseEntity when body is null to identify the root cause (401/429/5xx).
- Verify the DashScope API key and rerank model name are valid; fix credentials if the endpoint is rejecting the request.
- Retry the request or add a fallback that returns the original document order when reranking fails.
- Upgrade/patch the client to throw a typed exception (e.g. BizException with http-error-response) instead of a bare RuntimeException.
Example fix
// before
var response = responseEntity.getBody();
if (response == null) {
throw new RuntimeException("rerank response is null.");
}
// after
var response = responseEntity.getBody();
if (response == null) {
throw new BizException(ErrorCode.UPSTREAM_ERROR.toError("rerank response is null, status=" + responseEntity.getStatusCode()));
} Defensive patterns
Strategy: try-catch
Try / catch
try {
List<Document> ranked = reranker.process(query, documents, topK);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("rerank response is null")) {
// fall back to original document order
return documents;
}
throw e;
} Prevention
- Log HTTP status alongside the null-body condition for diagnosis.
- Configure the RetryTemplate with a sane backoff for transient DashScope failures.
- Monitor DashScope service status and quota before large rerank jobs.
- Provide a fallback ordering when reranking is unavailable.
When it happens
Trigger: dashscopeApi.rerankEntity(rerankRequest) returns a ResponseEntity whose getBody() is null — e.g. a 204/empty-body response, a transport-level failure not retried, or an error response that is not converted to an exception before body access.
Common situations: DashScope service degradation or throttling returning empty bodies; invalid API key producing an error body the client doesn't deserialize; network proxy stripping response bodies; model name for rerank misconfigured so the service returns nothing.
Related errors
- Oauth2CallError
- InvalidParameter
- NotSupportOperation Only Support post/get
- WORKFLOW_EXECUTE_ERROR
- MISSING_PARAMS
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/fd28fcc1b2033548.
Report an issue: GitHub.