#7284·chroma

[BUG](embedding-functions): KeyError in CloudflareWorkersAIEmbeddingFunction when API response missing 'result' key

Author: rtmalikianCreated Jun 19, 2026Updated Sep 24, 2026

Problem

In chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py line 101, the error-handling guard uses and instead of or:

python
if "result" not in resp and "data" not in resp["result"]:
    raise RuntimeError(resp.get("detail", "Unknown error"))

When the Cloudflare Workers AI API returns an error response without a "result" key (e.g., {"detail": "Unauthorized"}), the first condition "result" not in resp evaluates to True, and Python then evaluates the second condition "data" not in resp["result"] — which raises an unhandled KeyError instead of the intended RuntimeError.

Expected Behavior

The code should raise RuntimeError with the API error detail message.

Actual Behavior

An unhandled KeyError: result is raised, giving users no useful context about what went wrong.

Fix

Change and to or:

python
if "result" not in resp or "data" not in resp["result"]:

This short-circuits correctly: if "result" is missing, it raises RuntimeError immediately without trying to access resp["result"].

Affected File

  • chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py:101