{"record":{"id":"c8764d290c686b93","repo":"tirth8205/code-review-graph","slug":"voyage-api-returned-malformed-indices-got-indice","errorCode":null,"errorMessage":"Voyage API returned malformed indices (got {indices}, expected permutation of 0..{len(texts) - 1}) — refusing to misalign vectors.","messagePattern":"Voyage API returned malformed indices \\(got (.+?), expected permutation of 0\\.\\.(.+?)\\) — refusing to misalign vectors\\.","errorType":"http","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"code_review_graph/embeddings.py","lineNumber":756,"sourceCode":"\n                if \"error\" in response:\n                    err = response[\"error\"]\n                    msg = err.get(\"message\", \"unknown\") if isinstance(err, dict) else str(err)\n                    raise RuntimeError(f\"Voyage API error: {msg}\")\n\n                data = response.get(\"data\", [])\n                if not data:\n                    raise RuntimeError(\"Voyage API returned empty data\")\n\n                any_has_index = any(\"index\" in item for item in data)\n                all_int_index = all(\n                    isinstance(item.get(\"index\"), int) for item in data\n                )\n                if all_int_index:\n                    expected = set(range(len(texts)))\n                    indices = [int(item[\"index\"]) for item in data]\n                    if len(set(indices)) != len(indices) or set(indices) != expected:\n                        raise RuntimeError(\n                            \"Voyage API returned malformed indices \"\n                            f\"(got {indices}, expected permutation of \"\n                            f\"0..{len(texts) - 1}) — refusing to misalign vectors.\"\n                        )\n                    data = sorted(data, key=lambda item: int(item[\"index\"]))\n                elif not any_has_index:\n                    if len(data) != len(texts):\n                        raise RuntimeError(\n                            f\"Voyage API returned {len(data)} embeddings for \"\n                            f\"{len(texts)} inputs with no index field — \"\n                            \"refusing to misalign vectors.\"\n                        )\n                else:\n                    raise RuntimeError(\n                        \"Voyage API returned mixed indexed/unindexed data — \"\n                        \"refusing to misalign vectors.\"\n                    )\n","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/embeddings.py#L738-L774","documentation":"The Voyage response items all have integer 'index' fields, but they are not a permutation of 0..len(texts)-1 (duplicates or out-of-range values). The provider sorts vectors by index before returning; a bad permutation would silently misalign vectors with texts, so it aborts.","triggerScenarios":"Calling embed() with multiple texts where the API returns duplicate/missing/garbage index values, e.g. truncated batch responses or a non-compliant OpenAI-compatible proxy in front of Voyage.","commonSituations":"Using an OpenAI-compatible gateway that mangles the index field, partial responses after network interruptions, or API behavior changes after batching changes.","solutions":["Retry the embed call — usually transient corruption","If using a proxy at CRG_VOYAGE_BASE_URL, bypass it and call Voyage directly","Reduce batch size (fewer texts per call) to avoid truncation","Capture the failing request payload and report the mismatch"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"def is_index_misalignment(exc: RuntimeError) -> bool:\n    return \"refusing to misalign vectors\" in str(exc)","tryCatchPattern":"try:\n    vecs = provider.embed(texts)\nexcept RuntimeError as e:\n    if \"refusing to misalign vectors\" in str(e):\n        vecs = provider.embed(texts)  # retry once\n    else:\n        raise","preventionTips":["Avoid proxies that rewrite Voyage response bodies","Split large batches so responses stay small","Log and alert on any 'refusing to misalign' error — never ignore it"],"tags":["voyage","embeddings","data-integrity","index-mismatch"],"backgroundTag":"embedding-response-misalignment","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}