microsoft/semantic-kernel · error · VectorStoreOperationException

Unsupported constant type: {type(value)}

Error message

Unsupported constant type: {type(value)}

What it means

A VectorStoreOperationException raised by _lambda_parser for an ast.Constant whose value is not str, bytes, int, float, bool, or None. The translator only knows how to emit these primitive types into a Chroma where-filter; any other constant (e.g. a tuple, list, dict, frozenset, complex, or a custom object literal) is rejected.

Source

Thrown at python/semantic_kernel/connectors/chroma.py:432

                        f"Field '{node.attr}' not in data model (storage property names are used)."
                    )
                return node.attr
            case ast.Name():
                # Only allow names that are in the data model
                if node.id not in self.definition.storage_names:
                    raise VectorStoreOperationException(
                        f"Field '{node.id}' not in data model (storage property names are used)."
                    )
                return node.id
            case ast.Constant():
                value = node.value
                if isinstance(value, str):
                    return value.replace("'", "''")
                if isinstance(value, bytes):
                    return value.decode("utf-8").replace("'", "''")
                if isinstance(value, (int, float, bool)) or value is None:
                    return value
                raise VectorStoreOperationException(f"Unsupported constant type: {type(value)}")
        raise NotImplementedError(f"Unsupported AST node: {type(node)}")


@release_candidate
class ChromaStore(VectorStore):
    """Chroma vector store."""

    client: ClientAPI

    def __init__(
        self,
        persist_directory: str | None = None,
        client_settings: "Settings | None" = None,
        client: ClientAPI | None = None,
        embedding_generator: EmbeddingGeneratorBase | None = None,
        **kwargs: Any,
    ):
        """Initialize the Chroma vector store."""

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Compare against a primitive scalar (str/int/float/bool/None).
  2. For multi-value matching, expand to ORed equality checks (one comparison per value), since Chroma where-filters are scalar-based.

Example fix

// before
lambda x: x.tag == ["a", "b"]
// after
lambda x: (x.tag == "a") or (x.tag == "b")
Defensive patterns

Strategy: type-guard

Validate before calling

import ast
ALLOWED_CONST = (str, bytes, int, float, bool, type(None))
tree = ast.parse(filter_lambda_src, mode="eval")
consts = [n.value for n in ast.walk(tree) if isinstance(n, ast.Constant)]
assert all(isinstance(c, ALLOWED_CONST) for c in consts), "Filter constants must be str/bytes/int/float/bool/None"

Type guard

ALLOWED_CONST = (str, bytes, int, float, bool, type(None))

def is_supported_filter_constant(value) -> bool:
    return isinstance(value, ALLOWED_CONST)

Try / catch

from semantic_kernel.exceptions.vector_store_exceptions import VectorStoreOperationException
try:
    results = await collection.vectorized_search(vector=v, options=opts)
except VectorStoreOperationException as e:
    if "Unsupported constant type" in str(e):
        # replace list/tuple literals with ORed scalar comparisons
        ...

Prevention

When it happens

Trigger: Using a list/tuple/set/dict literal directly in a filter comparison, e.g. lambda x: x.tag == ["a","b"] or lambda x: x.val == (1,2). Complex numbers or other non-primitive literals also trigger it.

Common situations: Attempting membership/multi-value equality with a list literal (unsupported — see also error 1286 for 'in'); embedding a dataclass/tuple as a comparison value.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/eebfe43ba298e528. Report an issue: GitHub.