microsoft/semantic-kernel · error · VectorStoreOperationException

Sequence repetition in filter expressions exceeds the…

Error message

Sequence repetition in filter expressions exceeds the maximum allowed size.

What it means

Thrown by _safe_repeat (in_memory.py:367-370) when `seq * n` would exceed the cap: len(seq) > max_filter_sequence_repeat_size // n. Default cap is 1024. This prevents memory-exhaustion via repetition in filter expressions; the bound depends on actual runtime value lengths so it cannot be fully checked at parse time.

Solutions

  1. Reduce the repetition count or the source sequence length.
  2. Raise max_filter_sequence_repeat_size on the collection instance if the repetition is legitimate.
  3. Avoid repetition in filters entirely; precompute and compare against a stored field instead.

Example fix

# before
collection.max_filter_sequence_repeat_size = 1024  # default
VectorSearchOptions(filter="lambda x: x.name * 10000 == x.target")
# after
collection.max_filter_sequence_repeat_size = 50_000
# or avoid repetition:
VectorSearchOptions(filter="lambda x: x.name == x.target[:len(x.name)]")
Defensive patterns

Strategy: validation

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.name * 1000` where name is a non-empty string, or `lambda x: x.tags * 500` with a sizable list, producing a result larger than 1024 elements.

Common situations: Building large padded strings/lists inside a filter; legitimate but oversized repetition needs.

Related errors


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

Appendix: source

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

    def _safe_mult(self, left: Any, right: Any) -> Any:
        """Safely evaluate multiplication."""
        if isinstance(left, (int, float)) and isinstance(right, (int, float)):
            return left * right
        if isinstance(left, int) and isinstance(right, (str, list, tuple)):
            return self._safe_repeat(right, left)
        if isinstance(right, int) and isinstance(left, (str, list, tuple)):
            return self._safe_repeat(left, right)
        raise VectorStoreOperationException(
            "Multiplication in filter expressions is only allowed for numeric values and bounded sequence repetition."
        )

    def _safe_repeat(self, value: str | list[Any] | tuple[Any, ...], repeat_count: int) -> Any:
        """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)

View on GitHub (pinned to c028a0c7dc)