{"record":{"id":"017fd1b657a0eea3","repo":"microsoft/semantic-kernel","slug":"multiplication-in-filter-expressions-is-only-allow","errorCode":null,"errorMessage":"Multiplication in filter expressions is only allowed for numeric values and bounded sequence repetition.","messagePattern":"Multiplication in filter expressions is only allowed for numeric values and bounded sequence repetition\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":359,"sourceCode":"        if isinstance(left, str) and isinstance(right, str):\n            return self._ensure_sequence_result_size(left, right, lambda a, b: a + b)\n        if isinstance(left, list) and isinstance(right, list):\n            return self._ensure_sequence_result_size(left, right, lambda a, b: a + b)\n        if isinstance(left, tuple) and isinstance(right, tuple):\n            return self._ensure_sequence_result_size(left, right, lambda a, b: a + b)\n        raise VectorStoreOperationException(\n            \"Addition in filter expressions is only allowed for numeric values and same-type sequences.\"\n        )\n\n    def _safe_mult(self, left: Any, right: Any) -> Any:\n        \"\"\"Safely evaluate multiplication.\"\"\"\n        if isinstance(left, (int, float)) and isinstance(right, (int, float)):\n            return left * right\n        if isinstance(left, int) and isinstance(right, (str, list, tuple)):\n            return self._safe_repeat(right, left)\n        if isinstance(right, int) and isinstance(left, (str, list, tuple)):\n            return self._safe_repeat(left, right)\n        raise VectorStoreOperationException(\n            \"Multiplication in filter expressions is only allowed for numeric values and bounded sequence repetition.\"\n        )\n\n    def _safe_repeat(self, value: str | list[Any] | tuple[Any, ...], repeat_count: int) -> Any:\n        \"\"\"Safely repeat a sequence.\"\"\"\n        if repeat_count <= 0 or len(value) == 0:\n            return value * repeat_count\n        if len(value) > self._max_sequence_repeat_size // repeat_count:\n            raise VectorStoreOperationException(\n                \"Sequence repetition in filter expressions exceeds the maximum allowed size.\"\n            )\n        return value * repeat_count\n\n    def _safe_numeric_operation(\n        self,\n        operator_node: ast.AST,\n        left: Any,\n        right: Any,","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L341-L377","documentation":"Thrown by _safe_mult (in_memory.py:359-360) when `*` is not numeric*numeric and not (int * sequence). Examples: `2.5 * 'x'` (float * str), `'a' * 'b'` (str * str), `x.weight * x.tags` (float * list).","triggerScenarios":"A filter like `lambda x: x.scale * x.name` (float * str) or `lambda x: x.tags * x.weight` (list * float).","commonSituations":"Using a floating-point repeat factor; multiplying two sequences; assuming * works like SQL concatenation.","solutions":["Use an integer repeat count with sequences (int * str/list/tuple).","Keep multiplication numeric (int/float * int/float) when you mean arithmetic.","Cast the repeat operand to int()."],"exampleFix":"# before\nVectorSearchOptions(filter=\"lambda x: x.scale * x.tags\")  # float * list\n# after\nVectorSearchOptions(filter=\"lambda x: int(x.scale) * x.tags\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    results = await collection.search(search_type=SearchType.VECTOR, options=opts)\nexcept VectorStoreOperationException as e:\n    logger.warning(\"filter rejected: %s\", e.__cause__ or e)\n    results = None","preventionTips":["Only repeat sequences with integer counts.","Reserve * for numeric arithmetic unless you explicitly repeat."],"tags":["filter","in-memory","semantic-kernel","evaluation","arithmetic"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}