MemPalace/mempalace · error · EmbeddingAPIError

Embedding API at {self._url} returned non-object rows: {e}

Error message

Embedding API at {self._url} returned non-object rows: {e}

What it means

Raised by _vectors_from_response when sorting the 'data' rows by their 'index' key raises AttributeError — i.e. one or more rows are not dicts (a string, number, null, or list), so d.get('index') fails. This catches structurally malformed row entries before any positional alignment is attempted, and the original AttributeError is chained for the exact row access that broke.

Source

Thrown at mempalace/embedding.py:600

            )
        rows = data.get("data")
        if not isinstance(rows, list):
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned no 'data' array: {data.get('error', data)}"
            )
        if len(rows) != n:
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned {len(rows)} embeddings for {n} inputs"
            )
        # The endpoint may return rows out of order — sort by index, then
        # require the indices to be exactly 0..n-1 so positional alignment is
        # provably correct (a server using absolute or duplicate indices would
        # otherwise pass the count check yet map vectors to the wrong texts).
        try:
            rows = sorted(rows, key=lambda d: d.get("index", -1))
            indices = [r.get("index") for r in rows]
        except AttributeError as e:
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned non-object rows: {e}"
            ) from e
        if indices != list(range(n)):
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned non-contiguous or duplicate "
                f"'index' values; cannot align embeddings with inputs"
            )
        try:
            arr = np.asarray([r["embedding"] for r in rows], dtype=np.float32)
        except (KeyError, TypeError, ValueError) as e:
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned malformed embeddings: {e}"
            ) from e
        if arr.ndim != 2:
            raise EmbeddingAPIError(
                f"Embedding API at {self._url} returned non-vector embeddings (shape {arr.shape})"
            )
        # L2-normalize so cosine == dot product (collection uses

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Curl the endpoint and inspect each element of 'data' — every element must be an object with 'index' and 'embedding' keys
  2. Fix the server or stub to emit row objects: {"index": i, "embedding": [...]}
  3. If using a third-party proxy that flattens rows, bypass it for the embeddings route
  4. Verify no null/NaN JSON entries are injected by server-side serialization bugs

Example fix

# stub — before
return {"data": [[0.1, 0.2], [0.3, 0.4]]}
# after
return {"data": [
    {"index": 0, "embedding": [0.1, 0.2]},
    {"index": 1, "embedding": [0.3, 0.4]},
]}
Defensive patterns

Strategy: type-guard

Validate before calling

rows = resp.get("data", [])
assert all(isinstance(r, dict) for r in rows), "data rows must be objects"

Type guard

def rows_are_objects(data) -> bool:
    rows = data.get("data") if isinstance(data, dict) else None
    return isinstance(rows, list) and bool(rows) and all(isinstance(r, dict) for r in rows)

Try / catch

try:
    vecs = ef(texts)
except EmbeddingAPIError as e:
    if "non-object rows" in str(e):
        fix_stub_server_row_shape()  # structural bug — no point retrying

Prevention

When it happens

Trigger: A server whose data array contains non-object entries, e.g. "data": ["ok"] or "data": [null, {...}], or a hand-written stub returning bare vectors ([0.1, 0.2]) instead of {"index": i, "embedding": [...]} objects.

Common situations: Custom in-house embedding microservices that predate the OpenAI response schema; partially migrated servers; test fixtures with sloppy JSON; servers that append a trailing metadata element to the data array.

Related errors


AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15). Data as JSON: /api/errors/1a3053bedb01aa09. Report an issue: GitHub.