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

Abierto
#13,312 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #13313 de @Naeemeh146 — cerrado sin fusionar

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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!

Lenguaje dominante
Python
Estrellas
27.2k
Forks
3.5k
Merge medio
1 d 18 h
PR fusionados (30 d)
254

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de deepset-ai/haystack

Todos los issues de deepset-ai/haystack

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.