tirth8205/code-review-graph · critical · RuntimeError
Voyage API returned malformed indices (got {indices}, expect
Error message
Voyage API returned malformed indices (got {indices}, expected permutation of 0..{len(texts) - 1}) — refusing to misalign vectors. What it means
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.
Source
Thrown at code_review_graph/embeddings.py:756
if "error" in response:
err = response["error"]
msg = err.get("message", "unknown") if isinstance(err, dict) else str(err)
raise RuntimeError(f"Voyage API error: {msg}")
data = response.get("data", [])
if not data:
raise RuntimeError("Voyage API returned empty data")
any_has_index = any("index" in item for item in data)
all_int_index = all(
isinstance(item.get("index"), int) for item in data
)
if all_int_index:
expected = set(range(len(texts)))
indices = [int(item["index"]) for item in data]
if len(set(indices)) != len(indices) or set(indices) != expected:
raise RuntimeError(
"Voyage API returned malformed indices "
f"(got {indices}, expected permutation of "
f"0..{len(texts) - 1}) — refusing to misalign vectors."
)
data = sorted(data, key=lambda item: int(item["index"]))
elif not any_has_index:
if len(data) != len(texts):
raise RuntimeError(
f"Voyage API returned {len(data)} embeddings for "
f"{len(texts)} inputs with no index field — "
"refusing to misalign vectors."
)
else:
raise RuntimeError(
"Voyage API returned mixed indexed/unindexed data — "
"refusing to misalign vectors."
)
View on GitHub (pinned to b58668751a)
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
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
def is_index_misalignment(exc: RuntimeError) -> bool:
return "refusing to misalign vectors" in str(exc) Try / catch
try:
vecs = provider.embed(texts)
except RuntimeError as e:
if "refusing to misalign vectors" in str(e):
vecs = provider.embed(texts) # retry once
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: Using an OpenAI-compatible gateway that mangles the index field, partial responses after network interruptions, or API behavior changes after batching changes.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Voyage API returned {len(data)} embeddings for {len(texts)}
- Voyage API returned mixed indexed/unindexed data — refusing
- Voyage API HTTP {http_err.code}: {err_msg}
- Voyage API error: {msg}
- Voyage API returned empty data
AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28).
Data as JSON: /api/errors/c8764d290c686b93.
Report an issue: GitHub.