continuedev/continue · error · Error
Query and chunks must not be empty
Error message
Query and chunks must not be empty
What it means
Thrown by BedrockReranker.rerank when the rerank request has a falsy query or an empty documents array. It is a client-side guard that runs before any AWS call, so it indicates malformed caller input rather than a Bedrock problem.
Source
Thrown at packages/openai-adapters/src/apis/Bedrock.ts:669
}),
);
} else {
throw new Error(`Unsupported model: ${body.model}`);
}
return embedding({
data: embeddings,
model: body.model,
usage: {
prompt_tokens: 0,
total_tokens: 0,
},
});
}
async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {
if (!body.query || !body.documents.length) {
throw new Error("Query and chunks must not be empty");
}
// Base payload for both models
const payload: any = {
query: body.query,
documents: body.documents,
top_n: body.top_k ?? body.documents.length,
};
// Add api_version for Cohere model
if (body.model.startsWith("cohere.rerank")) {
payload.api_version = 2;
}
try {
const responseBody = await this.getInvokeModelResponseBody(
body.model,
payload,View on GitHub (pinned to 5522c6f44c)
Solutions
- Ensure documents array is non-empty before calling rerank; skip reranking when retrieval returned 0 chunks.
- Trim/validate the query string and reject empty queries upstream.
- Default the top_n or pass-through fields only after the guard passes.
Example fix
// before
await reranker.rerank({ query, documents });
// after
if (!query.trim() || documents.length === 0) return results;
await reranker.rerank({ query, documents }); Defensive patterns
Strategy: validation
Validate before calling
if (!body.query?.trim() || !body.documents?.length) throw new Error('skip rerank: empty input'); Type guard
const isRerankable = (b: RerankCreateParams): boolean => Boolean(b?.query?.trim()) && Array.isArray(b?.documents) && b.documents.length > 0;
Prevention
- Skip reranking when the retriever returns zero chunks.
- Validate query is non-empty before building the request.
When it happens
Trigger: Calling rerank({query: '', documents: [...]}) or rerank({query: 'q', documents: []}) or omitting either field; also when documents is undefined and .length access would otherwise fail.
Common situations: Retrieval pipelines where the chunker produced zero chunks for a document, or the query string was stripped/emptied by upstream sanitization before hitting the reranker.
Related errors
- AWS Bedrock rerank error (${(error as any).code}): ${error.m
- Error in BedrockReranker.rerank: ${error.message}
- Error in BedrockReranker.rerank: Unknown error occurred
- Unsupported tool type in Bedrock: ${tool.type}
- Unsupported embeddings type received: number[][]
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/58fa32455e00028f.
Report an issue: GitHub.