microsoft/semantic-kernel · error · VectorStoreOperationException

Operator '{type(operator_node).__name__}' is only allowed fo

Error message

Operator '{type(operator_node).__name__}' is only allowed for numeric values in filter expressions.

What it means

Thrown by _safe_numeric_operation (in_memory.py:381-383) for subtraction, division, modulo, and floor-division when either operand is not int/float. Parse-time admits the BinOp node; operand value types are checked at evaluation, so `x.name - 'x'`, `x.tags / 2`, or `x.count % x.tags` fail here.

Source

Thrown at python/semantic_kernel/connectors/in_memory.py:382

        """Safely repeat a sequence."""
        if repeat_count <= 0 or len(value) == 0:
            return value * repeat_count
        if len(value) > self._max_sequence_repeat_size // repeat_count:
            raise VectorStoreOperationException(
                "Sequence repetition in filter expressions exceeds the maximum allowed size."
            )
        return value * repeat_count

    def _safe_numeric_operation(
        self,
        operator_node: ast.AST,
        left: Any,
        right: Any,
        operation: Callable[[float | int, float | int], Any],
    ) -> Any:
        """Safely evaluate a numeric binary operation."""
        if not isinstance(left, (int, float)) or not isinstance(right, (int, float)):
            raise VectorStoreOperationException(
                f"Operator '{type(operator_node).__name__}' is only allowed for numeric values in filter expressions."
            )
        return operation(left, right)

    def _ensure_literal_collection_size(self, size: int) -> None:
        """Reject excessively large literal collections."""
        if size > self._max_literal_collection_size:
            raise VectorStoreOperationException(
                "Collection literals in filter expressions exceed the maximum allowed size."
            )

    def _ensure_sequence_result_size(
        self,
        left: str | list[Any] | tuple[Any, ...],
        right: str | list[Any] | tuple[Any, ...],
        operation: Callable[[Any, Any], Any],
    ) -> Any:
        """Reject oversized sequence concatenation results."""

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure both operands of -, /, %, // are int or float.
  2. Cast operands with int()/float() before the operation.
  3. Confirm field types in the data model.

Example fix

# before
VectorSearchOptions(filter="lambda x: x.count / x.divisor == 2")  # divisor may be str
# after
VectorSearchOptions(filter="lambda x: x.count / float(x.divisor) == 2")
Defensive patterns

Strategy: try-catch

Try / catch

try:
    results = await collection.search(search_type=SearchType.VECTOR, options=opts)
except VectorStoreOperationException as e:
    logger.warning("filter rejected: %s", e.__cause__ or e)
    results = None

Prevention

When it happens

Trigger: A filter like `lambda x: x.count - x.suffix` (int - str), `lambda x: x.tags / 2` (list / int), or `lambda x: x.price % x.category`.

Common situations: Assuming subtraction/division/modulo coerce automatically; field type mismatches.

Related errors


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