CherryHQ/cherry-studio · error · Error
Rerank response results must reference a valid document inde
Error message
Rerank response results must reference a valid document index
What it means
Re-thrown during Vertex AI model listing when options.throwOnError is set and at least one publisher group failed (returned null). `firstPublisherError` is captured as `unknown` from the per-publisher catch; if it is not an Error instance but is defined (e.g. a thrown string, a fetch rejection wrapping a non-Error), it is stringified and re-wrapped so the original value reaches the caller as a message. This branch only runs when the underlying thrown value was a non-Error.
Source
Thrown at packages/ai-sdk-provider/src/openai-compatible-reranking-model.ts:101
}
function parseRerankResponse(body: unknown, documentCount: number): RerankRanking {
const results = (body as OpenAICompatibleRerankResponse).results
if (!Array.isArray(results)) {
throw new Error('Rerank response must contain a results array')
}
return results.map((result) => {
if (typeof result !== 'object' || result === null) {
throw new Error('Rerank response results must be objects')
}
if (typeof result.index !== 'number' || typeof result.relevance_score !== 'number') {
throw new Error('Rerank response results must contain numeric index and relevance_score')
}
if (!Number.isInteger(result.index) || result.index < 0 || result.index >= documentCount) {
throw new Error('Rerank response results must reference a valid document index')
}
return { index: result.index, relevanceScore: result.relevance_score }
})
}
export function createOpenAICompatibleRerankingModel(
modelId: string,
settings: OpenAICompatibleRerankingModelSettings
): RerankingModelV3 {
const baseURL = withoutTrailingSlash(settings.baseURL)
if (!baseURL) {
throw new Error('OpenAI-compatible reranking model requires baseURL')
}
return new OpenAICompatibleRerankingModel(modelId, {
provider: `${settings.name}.rerank`,
url: ({ path }) => {View on GitHub (pinned to 726446b54c)
Solutions
- The stringified message is the underlying failure — read it: it usually names the auth or HTTP cause.
- Verify the Vertex provider is configured with valid iam-gcp credentials (service account JSON + project + region).
- Confirm the service account has the Vertex AI User / Model Garden access IAM role.
- Retry once for transient 5xx; if one publisher consistently fails, note that non-throwOnError mode would skip it and list the rest.
- Run the listing without throwOnError to see which publishers succeed and which fail individually in the warn logs.
Example fix
// before: caller passes throwOnError and gets an opaque String(...) message
await listModels(provider, signal, { throwOnError: true })
// after: list permissively, then inspect warn logs to find the failing publisher, fix its auth/region, then re-enable strict mode
const models = await listModels(provider, signal) // throwOnError defaults off; failures degrade to 'no models from this publisher'
// ... fix the failing publisher's config ...
await listModels(provider, signal, { throwOnError: true }) Defensive patterns
Strategy: validation
Validate before calling
// Validate Vertex auth before requesting a strict (throwOnError) listing.
const auth = providerService.getAuthConfig(provider.id)
if (auth?.type !== 'iam-gcp' || !auth.serviceAccountJson) {
throw new Error('Vertex provider must use iam-gcp auth with a service account JSON')
}
await listModels(provider, signal, { throwOnError: true }) Try / catch
try {
await listModels(provider, signal, { throwOnError: true })
} catch (e) {
// the message stringifies the original (non-Error) cause; surface it, do not blanket-retry
logger.error('Vertex listing failed', { providerId: provider.id, cause: e instanceof Error ? e.message : String(e) })
// fall back to non-strict listing to still surface working publishers
await listModels(provider, signal)
} Prevention
- Run the first Vertex listing without throwOnError to see which publishers fail and why in the warn logs.
- Keep the service account JSON and IAM roles current; rotate and re-test after changes.
- Prefer the Error-typed branch by ensuring upstream fetchers reject with Error instances so the cause is preserved.
When it happens
Trigger: A per-publisher Vertex request (`publishers/{publisher}/models`) threw something that is not an Error instance — e.g. a raw string, a Response object, or a library that rejects with a plain object — and throwOnError propagated it. The real failure is upstream (auth, network, 403); this error is just the re-wrapping.
Common situations: Vertex service account JSON invalid or expired (GCE/gcloud auth); the configured region does not serve a publisher (e.g. Model Garden model unavailable in region); IAM permissions lacking `aiplatform.models.list`; a dependency rejecting with a non-Error value; transient 5xx from the Vertex endpoint.
Related errors
- Provider extension "${id}" not found. Did you forget to regi
- VertexAI requires iam-gcp auth configuration.
- OpenAI-compatible reranking model requires baseURL
- Private key must be a non-empty string
- Invalid PEM format: missing BEGIN/END markers or key content
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/298a8e30631e26c7.
Report an issue: GitHub.