{"record":{"id":"5d91bae1f69f84ae","repo":"microsoft/semantic-kernel","slug":"method-contains-expects-exactly-one-argument","errorCode":null,"errorMessage":"Method 'contains' expects exactly one argument.","messagePattern":"Method 'contains' expects exactly one argument\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":291,"sourceCode":"\n    def _eval_Call(self, node: ast.Call, context: Mapping[str, Any]) -> Any:\n        \"\"\"Evaluate a function or method call.\"\"\"\n        args = [self.evaluate(arg, context) for arg in node.args]\n\n        if isinstance(node.func, ast.Name):\n            try:\n                func = self._direct_call_functions[node.func.id]\n            except KeyError as e:\n                raise VectorStoreOperationException(\n                    f\"Function '{node.func.id}' is only supported as a method call in filter expressions.\"\n                ) from e\n            return func(*args)\n\n        if isinstance(node.func, ast.Attribute):\n            target = self.evaluate(node.func.value, context)\n            if node.func.attr == \"contains\":\n                if len(args) != 1:\n                    raise VectorStoreOperationException(\"Method 'contains' expects exactly one argument.\")\n                return args[0] in target\n\n            try:\n                func = getattr(target, node.func.attr)\n            except AttributeError as e:\n                raise VectorStoreOperationException(\n                    f\"Method '{node.func.attr}' is not available in filter expressions.\"\n                ) from e\n\n            if not callable(func):\n                raise VectorStoreOperationException(\n                    f\"Attribute '{node.func.attr}' is not callable in filter expressions.\"\n                )\n            return func(*args)\n\n        raise VectorStoreOperationException(\n            f\"Call target node type '{type(node.func).__name__}' is not allowed in filter expressions.\"\n        )","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L273-L309","documentation":"The contains method is special-cased in _eval_Call to perform 'args[0] in target'. It must be called with exactly one argument; zero or more than one raises VectorStoreOperationException.","triggerScenarios":"Calling contains with the wrong arity, e.g. lambda x: x.tags.contains('a', 'b') or lambda x: x.tags.contains().","commonSituations":"Misunderstanding contains as a multi-argument matcher; copy-paste from a different API; expecting SQL-style IN(list).","solutions":["Call contains with exactly one argument: lambda x: x.tags.contains('a').","Prefer the Python 'in' operator: lambda x: 'a' in x.tags.","For multi-value membership, chain: lambda x: 'a' in x.tags and 'b' in x.tags."],"exampleFix":"# before\nVectorSearchOptions(filter=lambda x: x.tags.contains('a', 'b'))  # -> [1318]\n\n# after\nVectorSearchOptions(filter=lambda x: 'a' in x.tags and 'b' in x.tags)","handlingStrategy":"validation","validationCode":"import ast\n\ndef contains_has_one_arg(filter_str: str) -> None:\n    for node in ast.walk(ast.parse(filter_str, mode='eval')):\n        if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == 'contains':\n            if len(node.args) != 1:\n                raise ValueError(\"contains() expects exactly one argument; use 'a in x.f' for membership\")","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreOperationException\ntry:\n    await collection.search(vector=[...], options=opts)\nexcept VectorStoreOperationException as ex:\n    if \"expects exactly one argument\" in str(ex):\n        opts.filter = \"lambda x: 'a' in x.tags\"\n        await collection.search(vector=[...], options=opts)\n    else:\n        raise","preventionTips":["Call contains with exactly one argument, or prefer the 'in' operator.","Chain multiple membership checks rather than passing multiple args."],"tags":["in-memory","filter"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}