{"record":{"id":"4519ef6081983faa","repo":"microsoft/semantic-kernel","slug":"operator-type-operator-node-name-is-only","errorCode":null,"errorMessage":"Operator '{type(operator_node).__name__}' is only allowed for numeric values in filter expressions.","messagePattern":"Operator '(.+?)' is only allowed for numeric values in filter expressions\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":382,"sourceCode":"        \"\"\"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,\n        operation: Callable[[float | int, float | int], Any],\n    ) -> Any:\n        \"\"\"Safely evaluate a numeric binary operation.\"\"\"\n        if not isinstance(left, (int, float)) or not isinstance(right, (int, float)):\n            raise VectorStoreOperationException(\n                f\"Operator '{type(operator_node).__name__}' is only allowed for numeric values in filter expressions.\"\n            )\n        return operation(left, right)\n\n    def _ensure_literal_collection_size(self, size: int) -> None:\n        \"\"\"Reject excessively large literal collections.\"\"\"\n        if size > self._max_literal_collection_size:\n            raise VectorStoreOperationException(\n                \"Collection literals in filter expressions exceed the maximum allowed size.\"\n            )\n\n    def _ensure_sequence_result_size(\n        self,\n        left: str | list[Any] | tuple[Any, ...],\n        right: str | list[Any] | tuple[Any, ...],\n        operation: Callable[[Any, Any], Any],\n    ) -> Any:\n        \"\"\"Reject oversized sequence concatenation results.\"\"\"","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L364-L400","documentation":"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.","triggerScenarios":"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`.","commonSituations":"Assuming subtraction/division/modulo coerce automatically; field type mismatches.","solutions":["Ensure both operands of -, /, %, // are int or float.","Cast operands with int()/float() before the operation.","Confirm field types in the data model."],"exampleFix":"# before\nVectorSearchOptions(filter=\"lambda x: x.count / x.divisor == 2\")  # divisor may be str\n# after\nVectorSearchOptions(filter=\"lambda x: x.count / float(x.divisor) == 2\")","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":["Reserve -, /, %, // for numeric fields.","Cast uncertain operands to float()/int() before dividing."],"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"}