{"record":{"id":"fd28fcc1b2033548","repo":"alibaba/spring-ai-alibaba","slug":"rerank-response-is-null","errorCode":null,"errorMessage":"rerank response is null.","messagePattern":"rerank response is null\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/model/reranker/dashscope/DashscopeReranker.java","lineNumber":103,"sourceCode":"\t */\n\t@NotNull\n\t@Override\n\tpublic List<Document> process(@NotNull Query query, @NotNull List<Document> documents) {\n\t\tif (CollectionUtils.isEmpty(documents)) {\n\t\t\treturn documents;\n\t\t}\n\n\t\tAssert.notNull(query, \"query must not be null\");\n\t\tAssert.notNull(documents, \"documents must not be null\");\n\n\t\tDashScopeApi.RerankRequest rerankRequest = createRequest(query, documents, options);\n\n\t\tResponseEntity<DashScopeApi.RerankResponse> responseEntity = this.retryTemplate\n\t\t\t.execute(ctx -> this.dashscopeApi.rerankEntity(rerankRequest));\n\n\t\tvar response = responseEntity.getBody();\n\t\tif (response == null) {\n\t\t\tthrow new RuntimeException(\"rerank response is null.\");\n\t\t}\n\n\t\treturn response.output().results().stream().map(data -> {\n\t\t\tvar doc = documents.get(data.index());\n\t\t\treturn Document.builder()\n\t\t\t\t.score(data.relevanceScore())\n\t\t\t\t.id(doc.getId())\n\t\t\t\t.text(doc.getText())\n\t\t\t\t.metadata(doc.getMetadata())\n\t\t\t\t.media(doc.getMedia())\n\t\t\t\t.build();\n\t\t}).toList();\n\t}\n\n\t/**\n\t * Creates a rerank request for the DashScope API.\n\t * @param query The search query\n\t * @param documents List of documents to rerank","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/model/reranker/dashscope/DashscopeReranker.java#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar response = responseEntity.getBody();\nif (response == null) {\n    throw new RuntimeException(\"rerank response is null.\");\n}\n// after\nvar response = responseEntity.getBody();\nif (response == null) {\n    throw new BizException(ErrorCode.UPSTREAM_ERROR.toError(\"rerank response is null, status=\" + responseEntity.getStatusCode()));\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    List<Document> ranked = reranker.process(query, documents, topK);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"rerank response is null\")) {\n        // fall back to original document order\n        return documents;\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["rerank","dashscope","http","null-response"],"backgroundTag":"empty-response-body","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}