In-memory filter evaluation of 'in'/'not in' on list-valued meta fields diverges from OpenSearch/Elasticsearch terms semantics

オープン
#13,312 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #13313 @Naeemeh146 による — マージされずにクローズ

評価

この issue はまだ評価されていません。

説明

handled internally P3

Describe the bug

For a document whose meta field holds a list, the in-memory filter evaluation applies in as a Python membership test (the whole list must be an element of the filter values), while the OpenSearch and Elasticsearch integrations translate in to a terms query (match when any element of the field is in the filter values). The same filter returns opposite results depending on the document store, with no warning.

Reproduction

from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore

docs = [
    Document(id="1", content="a", meta={"tags": ["a"]}),
    Document(id="2", content="b", meta={"tags": ["z"]}),
]
store = InMemoryDocumentStore()
store.write_documents(docs)

print(store.filter_documents({"field": "tags", "operator": "in", "value": ["a", "b"]}))
# []  <- doc 1 not matched: ["a"] in ["a", "b"] is False in Python
print(store.filter_documents({"field": "tags", "operator": "not in", "value": ["a", "b"]}))
# [doc 1, doc 2]  <- the exact opposite of what terms semantics give

The OpenSearch integration converts the same filter to {"terms": {"tags": ["a", "b"]}} (haystack-core-integrations, opensearch/filters.py). Under OpenSearch terms semantics, doc 1 matches the in filter and is excluded by the not in filter - the inverse of the in-memory result. The Elasticsearch integration does the same.

Why this matters

A common workflow is to prototype a pipeline on InMemoryDocumentStore (or test components with the in-memory retriever) and then deploy against OpenSearch/Elasticsearch. A retrieval filter that excludes every document with multi-valued tags in testing starts returning them in production, and not in flips from keeping everything to dropping exactly the documents the prototype kept. Nothing in the filter or the logs hints at the change.

Possible directions

  • Evaluate in/not in as overlap (any element in common) for list-valued fields in document_matches_filter, aligning the in-memory reference implementation with the term-based stores, or
  • Raise a FilterError when in is used against a list-valued field so the divergence is loud instead of silent, or
  • Document the difference explicitly; the pgvector integration already exposes array_contains/array_overlaps as distinct operators, so an explicit overlap operator in core would also work.

Environment

  • haystack-ai 3.3.0
  • opensearch-haystack (filters.py in -> terms) checked from haystack-core-integrations main
  • Python 3.10

👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!

主要言語
Python
スター
27.2k
フォーク
3.5k
平均マージ
1日 18時間
マージ済み PR(30日)
254

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepset-ai/haystack のほかの issue

deepset-ai/haystack の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。