chroma-core/chroma · error · TypeError

Select key must be a string, got

Error message

Select key must be a string, got {type(k).__name__}

What it means

Raised during Select construction (from_dict or __init__) when an individual key element is not a string or Key instance — e.g. an integer or None appeared inside the keys collection. Every selected field must be a string name or a Key constant.

Solutions

  1. Use string key names such as '#id', '#document', '#embedding', '#metadata', '#score', or a metadata field name
  2. Convert Key objects to their .name strings if mixing types
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at chromadb/execution/expression/operator.py:1298 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/5f573822e74d6e9e. Report an issue: GitHub.

Appendix: source

Thrown at chromadb/execution/expression/operator.py:1298

        Examples:
        - {"keys": ["#document", "#score"]} -> Select(keys={Key.DOCUMENT, Key.SCORE})
        - {"keys": ["title", "author"]} -> Select(keys={"title", "author"})
        """
        if not isinstance(data, dict):
            raise TypeError(f"Expected dict for Select, got {type(data).__name__}")

        keys = data.get("keys", [])
        if not isinstance(keys, (list, tuple, set)):
            raise TypeError(
                f"Select keys must be a list/tuple/set, got {type(keys).__name__}"
            )

        # Validate and convert each key
        key_list = []
        for k in keys:
            if not isinstance(k, str):
                raise TypeError(f"Select key must be a string, got {type(k).__name__}")

            # Map special keys to Key instances
            if k == "#id":
                key_list.append(Key.ID)
            elif k == "#document":
                key_list.append(Key.DOCUMENT)
            elif k == "#embedding":
                key_list.append(Key.EMBEDDING)
            elif k == "#metadata":
                key_list.append(Key.METADATA)
            elif k == "#score":
                key_list.append(Key.SCORE)
            else:
                # Regular metadata field
                key_list.append(Key(k))

        # Check for unexpected keys in dict
        allowed_keys = {"keys"}

View on GitHub (pinned to aecdd12c8a)