Skip to content

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

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

PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 3 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
Contributor

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.

…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.
@eavanvalkenburg

Copy link
Copy Markdown
Member

Approved the reviewed head, but GitHub rejected merge-queue entry because this PR now has merge conflicts. Please rebase onto the current main branch, preserving the filter and apostrophe regressions, and rerun CI. It has not been added to the queue.

@VANDRANKI

Copy link
Copy Markdown
Contributor Author

I updated this branch with current main (df1cb33). I merged main in instead of force pushing, so the new head 146d59c is a normal merge commit.

Main changed the same spot in two test files. #14560 added the apostrophe tests in test_chroma.py and test_weaviate_collection.py, and that conflicted with my list tests. I kept both sets of tests. The source changes in chroma.py, mongodb.py, pinecone.py and weaviate.py merged with no conflicts and are identical to the head you approved.

On the pushed tree I ran test_chroma.py, test_pinecone.py, test_weaviate_collection.py and test_mongodb_atlas_collection.py: 72 passed. With those four connector files taken back to the main version, 11 of the new list tests fail (3 Chroma, 4 Pinecone, 2 Weaviate, 2 MongoDB) and the other 61 pass. I did not run the rest of the memory test folders.

The new workflow runs for 146d59c show action_required, so a maintainer needs to approve them before they start.

This branch was previously deployed

1 inactive deployment
github-app-auth — 146d59c2 Deployed Nov 6, 2026 by VANDRANKI via add_label #29610
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)

3 participants