Skip to content

Python: Support list literals in Chroma, MongoDB, Pinecone and Weaviate filters - #14558

Open
PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 2 commits into
microsoft:mainfrom
VANDRANKI:fix/vector-filter-list-literals
Open

PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 2 commits into
microsoft:mainfrom
VANDRANKI:fix/vector-filter-list-literals

Conversation

@VANDRANKI

@VANDRANKI PRABHU KIRAN VANDRANKI (VANDRANKI) commented Oct 6, 2026 •

Copy link
Copy Markdown

Motivation and Context

Filter lambdas that use in or not in with a list literal always fail on the Chroma, MongoDB Atlas, Pinecone and Weaviate collections with NotImplementedError: Unsupported AST node: <class 'ast.List'>. Their _lambda_parser implementations already handle ast.In and ast.NotIn, but none of them parse the list on the right-hand side. Qdrant already does.

Pinecone also computes $nin for not (x in [...]) with next(operand.values()), which raises TypeError: 'dict_values' object is not an iterator for every not filter.

Fixes #14557

Description

  • Add case ast.List(): return [self._lambda_parser(elt) for elt in node.elts] to _lambda_parser in mongodb.py and pinecone.py, the same way qdrant.py does it.
  • Add an ast.List case to _lambda_parser in chroma.py and weaviate.py too. There, string and bytes elements are passed through as written instead of through the scalar string branch, which doubles apostrophes (x.content in ["O'Reilly"] would otherwise filter on O''Reilly). The scalar case is fixed separately in Python: Stop doubling apostrophes in Chroma and Weaviate filter values #14560.
  • In pinecone.py, replace the next(operand.values()) calls with next(iter(operand.items())). not (x in [...]) now becomes $nin, and any other not raises the documented NotImplementedError instead of a TypeError.
  • Widen the Chroma _lambda_parser return annotation to include list[Any].
  • Redis is not changed. RedisVL Text and Num filters reject a list on the right side, so it needs a separate decision.

Tests added for each connector, including an apostrophe case for Chroma and Weaviate. They fail on main and pass with this change. tests/unit/data and the Chroma, Pinecone, MongoDB, Weaviate and Redis unit tests pass, and ruff and mypy report nothing new for the changed lines.

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings October 6, 2026 17:24
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Chroma and Weaviate currently alter apostrophes in list values, causing valid membership filters to miss matching records.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds list-literal support to vector-store filter parsers and fixes Pinecone negation handling.

Changes:

  • Parses list literals for Chroma, MongoDB Atlas, Pinecone, and Weaviate.
  • Correctly converts Pinecone not (... in [...]) to $nin.
  • Adds connector-specific unit coverage.
File Description
python/​semantic_kernel/​connectors/​chroma.py Adds list parsing and updates return typing.
python/​semantic_kernel/​connectors/​mongodb.py Adds list parsing.
python/​semantic_kernel/​connectors/​pinecone.py Adds list parsing and repairs negation handling.
python/​semantic_kernel/​connectors/​weaviate.py Adds list parsing for contains_any.
python/​tests/​unit/​connectors/​memory/​test_chroma.py Tests $in and $nin lists.
python/​tests/​unit/​connectors/​memory/​mongodb_atlas/​test_mongodb_atlas_collection.py Tests MongoDB list filters.
python/​tests/​unit/​connectors/​memory/​test_pinecone.py Tests list and negated filters.
python/​tests/​unit/​connectors/​memory/​weaviate/​test_weaviate_collection.py Tests contains_any translation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return value
raise VectorStoreOperationException(f"Unsupported constant type: {type(value)}")
case ast.List():
return [self._lambda_parser(elt) for elt in node.elts]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. The list branch went through the string constant branch, so x.content in ["O'Reilly"] became {"content": {"$in": ["O''Reilly"]}}.

Fixed in 89346f5. List elements that are str or bytes constants are now passed through unchanged. test_chroma_collection_build_filter_in_list_keeps_apostrophes fails on the previous head and passes now. This does not depend on #14560, which fixes the same doubling for scalar values like x.content == "O'Brien".

return value
raise VectorStoreOperationException(f"Unsupported constant type: {type(value)}")
case ast.List():
return [self._lambda_parser(elt) for elt in node.elts] # type: ignore

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. contains_any received ["O''Reilly", "b"] for x.content in ["O'Reilly", 'b'], because list elements were parsed through the string constant branch.

Fixed in 89346f5. List elements that are str or bytes constants now keep their value as written. test_weaviate_collection_build_filter_in_list_keeps_apostrophes fails on the previous head (["O''Reilly", 'b']) and passes now. The scalar case is handled separately in #14560.

…tten

List elements were parsed through the string constant branch, which doubles apostrophes, so x.content in ["O'Reilly"] filtered on O''Reilly. List elements now pass string and bytes constants through unchanged.

This branch was successfully deployed

1 active deployment
github-app-auth — 89346f50 Deployed Oct 6, 2026 by VANDRANKI via add_label #29284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Chroma, MongoDB, Pinecone and Weaviate filters raise NotImplementedError for 'in' with a list literal (and Pinecone 'not' raises TypeError)

2 participants