microsoft/semantic-kernel · warning · VectorStoreOperationException
String literals in filter expressions exceed the maximum all
Error message
String literals in filter expressions exceed the maximum allowed size.
What it means
When _eval_Constant evaluates a string literal whose length exceeds the evaluator's max_literal_collection_size (default 256), it raises VectorStoreOperationException. This mirrors the same check performed during static parsing, so in normal use the static check fires first; the evaluator check is a defense-in-depth net that triggers when the evaluator instance was configured with a smaller cap than the parser.
Source
Thrown at python/semantic_kernel/connectors/in_memory.py:147
self._direct_call_functions = direct_call_functions
self._blocked_attributes = blocked_attributes
self._max_literal_collection_size = max_literal_collection_size
self._max_sequence_repeat_size = max_sequence_repeat_size
def evaluate(self, node: ast.AST, context: Mapping[str, Any]) -> Any:
"""Evaluate a supported AST node."""
evaluator = getattr(self, f"_eval_{type(node).__name__}", None)
if evaluator is None:
raise VectorStoreOperationException(
f"AST node type '{type(node).__name__}' is not supported during filter evaluation."
)
return evaluator(node, context)
def _eval_Constant(self, node: ast.Constant, context: Mapping[str, Any]) -> Any:
"""Evaluate a constant literal."""
del context
if isinstance(node.value, str) and len(node.value) > self._max_literal_collection_size:
raise VectorStoreOperationException(
"String literals in filter expressions exceed the maximum allowed size."
)
return node.value
def _eval_Name(self, node: ast.Name, context: Mapping[str, Any]) -> Any:
"""Evaluate a variable reference."""
if node.id not in context:
raise VectorStoreOperationException(f"Use of name '{node.id}' is not allowed in filter expressions.")
return context[node.id]
def _eval_Attribute(self, node: ast.Attribute, context: Mapping[str, Any]) -> Any:
"""Evaluate an attribute access."""
if node.attr in self._blocked_attributes:
raise VectorStoreOperationException(
f"Access to attribute '{node.attr}' is not allowed in filter expressions."
)
value = self.evaluate(node.value, context)
try:View on GitHub (pinned to c028a0c7dc)
Solutions
- Shorten the literal, or compare against a field value rather than a giant inline constant.
- Raise max_filter_literal_collection_size on the collection instance so the parser and evaluator share the larger limit.
- Pre-filter large values in application code instead of inside the filter expression.
Example fix
# before
collection = MyCollection(...)
await collection.search(vector=[...], options=VectorSearchOptions(
filter=lambda x: x.text == 'A' * 1000)) # -> [1308]
# after
collection.max_filter_literal_collection_size = 4096
# or shorten / pre-filter the value before building the filter Defensive patterns
Strategy: validation
Validate before calling
def check_string_literals(filter_str: str, limit: int) -> None:
import ast
for node in ast.walk(ast.parse(filter_str, mode='eval')):
if isinstance(node, ast.Constant) and isinstance(node.value, str) and len(node.value) > limit:
raise ValueError(f"string literal exceeds limit {limit}: {len(node.value)} chars") Try / catch
from semantic_kernel.exceptions import VectorStoreOperationException
try:
await collection.search(vector=[...], options=opts)
except VectorStoreOperationException as ex:
if 'exceed the maximum allowed size' in str(ex):
collection.max_filter_literal_collection_size = 4096
await collection.search(vector=[...], options=opts)
else:
raise Prevention
- Keep inline string literals short; move large values out of the filter.
- If large literals are legitimate, raise max_filter_literal_collection_size on the collection.
When it happens
Trigger: A string filter lambda containing a literal longer than 256 chars, e.g. lambda x: x.desc == '<very long string>', especially when the literal is built dynamically from user input.
Common situations: Embedding a large blob/document text into a filter; comparing against a long URL or payload; generating filters from unbounded user input.
Related errors
- AST node type '{type(node).__name__}' is not supported durin
- Use of name '{node.id}' is not allowed in filter expressions
- Access to attribute '{node.attr}' is not allowed in filter e
- Attribute '{node.attr}' is not available in filter expressio
- Error evaluating subscript access: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/8fce65d9082ec3a8.
Report an issue: GitHub.