{"record":{"id":"ff06b794f05b84b4","repo":"microsoft/semantic-kernel","slug":"error-evaluating-subscript-access-e","errorCode":null,"errorMessage":"Error evaluating subscript access: {e}","messagePattern":"Error evaluating subscript access: (.+?)","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":179,"sourceCode":"            raise VectorStoreOperationException(\n                f\"Access to attribute '{node.attr}' is not allowed in filter expressions.\"\n            )\n        value = self.evaluate(node.value, context)\n        try:\n            return ReadOnlyAttributeDict._wrap_value(getattr(value, node.attr))\n        except AttributeError as e:\n            raise VectorStoreOperationException(\n                f\"Attribute '{node.attr}' is not available in filter expressions.\"\n            ) from e\n\n    def _eval_Subscript(self, node: ast.Subscript, context: Mapping[str, Any]) -> Any:\n        \"\"\"Evaluate an index or slice operation.\"\"\"\n        value = self.evaluate(node.value, context)\n        slice_value = self.evaluate(node.slice, context)\n        try:\n            return ReadOnlyAttributeDict._wrap_value(value[slice_value])\n        except Exception as e:\n            raise VectorStoreOperationException(f\"Error evaluating subscript access: {e}\") from e\n\n    def _eval_Slice(self, node: ast.Slice, context: Mapping[str, Any]) -> slice:\n        \"\"\"Evaluate a slice node.\"\"\"\n        lower = self._evaluate_optional(node.lower, context)\n        upper = self._evaluate_optional(node.upper, context)\n        step = self._evaluate_optional(node.step, context)\n        return slice(lower, upper, step)\n\n    def _eval_List(self, node: ast.List, context: Mapping[str, Any]) -> list[Any]:\n        \"\"\"Evaluate a list literal.\"\"\"\n        self._ensure_literal_collection_size(len(node.elts))\n        return [self.evaluate(element, context) for element in node.elts]\n\n    def _eval_Tuple(self, node: ast.Tuple, context: Mapping[str, Any]) -> tuple[Any, ...]:\n        \"\"\"Evaluate a tuple literal.\"\"\"\n        self._ensure_literal_collection_size(len(node.elts))\n        return tuple(self.evaluate(element, context) for element in node.elts)\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L161-L197","documentation":"_eval_Subscript evaluates value[slice_value]; if that indexing raises (KeyError, IndexError, TypeError) it is caught and re-raised as VectorStoreOperationException with the original message embedded. This covers dict lookups by a missing key, indexing a non-indexable value, or invalid slice operands.","triggerScenarios":"A filter like lambda x: x['missing'] == 1; subscripting a scalar (lambda x: x.count[0]); a slice on a non-sliceable value; a key whose type does not match the dict's key type.","commonSituations":"Dict-style access with the wrong key; mixing attribute and subscript styles; expecting a list where the field is a scalar; inconsistent field types across records.","solutions":["Use a valid key that exists on the record, or switch to attribute access (x.field).","Guard with x.get('key') or 'key' in x before subscripting.","Confirm the field's runtime type matches what the subscript assumes."],"exampleFix":"# before\nawait collection.search(vector=[...], options=VectorSearchOptions(filter=lambda x: x['nope'] == 1))  # -> [1312]\n\n# after\nawait collection.search(vector=[...], options=VectorSearchOptions(filter=lambda x: x.get('real_key') == 1))","handlingStrategy":"validation","validationCode":"def prefer_safe_subscript(filter_str: str) -> None:\n    import ast\n    for node in ast.walk(ast.parse(filter_str, mode='eval')):\n        if isinstance(node, ast.Subscript):\n            raise ValueError(\"prefer x.get('key') over x['key'] in filters to avoid missing-key errors\")","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreOperationException\ntry:\n    await collection.search(vector=[...], options=opts)\nexcept VectorStoreOperationException as ex:\n    if 'Error evaluating subscript access' in str(ex):\n        opts.filter = \"lambda x: x.get('key') == value\"\n        await collection.search(vector=[...], options=opts)\n    else:\n        raise","preventionTips":["Use x.get('key') for dict-style access in filters.","Confirm the field's runtime type before subscripting or slicing."],"tags":["in-memory","filter","subscript"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}