Python: Bug: vector store filters fail when the constant is on the left, including chained comparisons

未关闭
#14,779 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@wasim-builds 已经在做这个了。

开始于 2026年11月11日。

  • #14781 来自 @wasim-builds —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

Start in Python’s VectorSearch._build_filter and read _FoldUnaryNumericConstants from the referenced change #14572; compare it with the filter parsers for Qdrant and Chroma. The issue proposes normalizing reversed and chained comparisons before connector parsing. Done means the three examples return the expected records on Qdrant and Chroma while existing field-left filters continue to work; an open linked pull request (#14781) indicates work is already underway.

由索引模型根据 Issue 内容生成。

描述

python triage

Describe the bug

Vector store filters fail when the constant is on the left of a comparison, and that includes Python's chained range comparison. QdrantCollection and ChromaCollection raise for all three of these, while InMemoryCollection and FaissCollection return the expected records:

await collection.search(vector=[1.0, 1.0], filter="lambda x: 2 < x.num")       # expected num 3, 4, 5
await collection.search(vector=[1.0, 1.0], filter="lambda x: 3 == x.num")      # expected num 3
await collection.search(vector=[1.0, 1.0], filter="lambda x: 1 <= x.num < 4")  # expected num 1, 2, 3

Qdrant fails with a pydantic ValidationError (FieldCondition gets key=3, or Range gets lt="num"). Chroma fails with Expected where key to be a str, got 2.

The chained form is the one users are most likely to write. QdrantCollection._lambda_parser already splits chains into an AND (the comment there gives 1 < x < 3 as the example), but the first pair of a chain always has the constant on the left, so that path can't succeed today.

To Reproduce

A record type with an int data field num, six records with num 0 to 5, then the searches above on QdrantCollection(location=":memory:") and an ephemeral ChromaCollection. Rewriting each filter with the field on the left (x.num > 2, x.num >= 1 and x.num < 4) works on both.

Expected behavior

The same records as the field-on-the-left form, as InMemoryCollection returns today.

Additional context

Checked by running: Qdrant and Chroma fail. In-memory and FAISS work.

Read in the code but not run: the Weaviate, Pinecone, MongoDB and Azure Cosmos DB parsers also take the left operand as the field name and have no case for a constant there. Redis and Azure AI Search handle the reversed form explicitly. The SQL-based connectors may work by accident, since 2 < num is valid SQL.

Suggested fix: Normalize the tree once in VectorSearch._build_filter, next to _FoldUnaryNumericConstants from #14572, so the connector parsers stay unchanged:

  • rewrite Constant op Field as Field op' Constant, flipping </> and <=/>= and keeping ==/!=
  • split a chained comparison a < b < c into a < b and b < c

in and not in with the constant on the left mean "the list field contains the value", which is a different operation, so I'd leave them as they are.

I'm happy to open a PR for this if the approach sounds right.

Platform

  • Language: Python
  • Source: main at b714e97
  • Python 3.12, qdrant-client 1.20.0, chromadb 1.5.9

AI disclosure: found with Claude Code while comparing filter results across the Python connectors.

主要语言
C#
星标
28.8k
派生
4.9k
平均合并
2 天 17 小时
30 天内合并 PR
48

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/semantic-kernel 的其他 Issue

查看 microsoft/semantic-kernel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。