{"record":{"id":"58fa32455e00028f","repo":"continuedev/continue","slug":"query-and-chunks-must-not-be-empty-58fa32","errorCode":null,"errorMessage":"Query and chunks must not be empty","messagePattern":"Query and chunks must not be empty","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/openai-adapters/src/apis/Bedrock.ts","lineNumber":669,"sourceCode":"        }),\n      );\n    } else {\n      throw new Error(`Unsupported model: ${body.model}`);\n    }\n\n    return embedding({\n      data: embeddings,\n      model: body.model,\n      usage: {\n        prompt_tokens: 0,\n        total_tokens: 0,\n      },\n    });\n  }\n\n  async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {\n    if (!body.query || !body.documents.length) {\n      throw new Error(\"Query and chunks must not be empty\");\n    }\n\n    // Base payload for both models\n    const payload: any = {\n      query: body.query,\n      documents: body.documents,\n      top_n: body.top_k ?? body.documents.length,\n    };\n\n    // Add api_version for Cohere model\n    if (body.model.startsWith(\"cohere.rerank\")) {\n      payload.api_version = 2;\n    }\n\n    try {\n      const responseBody = await this.getInvokeModelResponseBody(\n        body.model,\n        payload,","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/packages/openai-adapters/src/apis/Bedrock.ts#L651-L687","documentation":"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.","triggerScenarios":"Calling rerank({query: '', documents: [...]}) or rerank({query: 'q', documents: []}) or omitting either field; also when documents is undefined and .length access would otherwise fail.","commonSituations":"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.","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."],"exampleFix":"// before\nawait reranker.rerank({ query, documents });\n// after\nif (!query.trim() || documents.length === 0) return results;\nawait reranker.rerank({ query, documents });","handlingStrategy":"validation","validationCode":"if (!body.query?.trim() || !body.documents?.length) throw new Error('skip rerank: empty input');","typeGuard":"const isRerankable = (b: RerankCreateParams): boolean => Boolean(b?.query?.trim()) && Array.isArray(b?.documents) && b.documents.length > 0;","tryCatchPattern":null,"preventionTips":["Skip reranking when the retriever returns zero chunks.","Validate query is non-empty before building the request."],"tags":["bedrock","rerank","validation","input-validation"],"backgroundTag":"empty-request-body","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}