FAISS: filtered search misses matching documents outside the first top_k * 10 neighbours

Aperta
#4,322 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@davidsbatista ci sta già lavorando.

Dal 24/11/2026.

  • #4323 di @astroknot-sheep — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Describe the bug
FAISSDocumentStore.search() with filters (and so FAISSEmbeddingRetriever) only looks at the first min(ntotal, top_k * 10) nearest neighbours and filters those. If the matching documents are further away than that, the search returns fewer than top_k results, or nothing at all, even though filter_documents() finds them.

To Reproduce

from haystack import Document
from haystack_integrations.document_stores.faiss import FAISSDocumentStore
from haystack_integrations.components.retrievers.faiss import FAISSEmbeddingRetriever

s = FAISSDocumentStore(embedding_dim=2)
docs = [Document(content=f"en{i}", meta={"lang": "en"}, embedding=[1.0, i / 1000]) for i in range(50)]
docs.append(Document(content="de", meta={"lang": "de"}, embedding=[-1.0, 0.0]))
s.write_documents(docs)
f = {"field": "meta.lang", "operator": "==", "value": "de"}

print([d.content for d in s.filter_documents(f)])                         # ['de']
print([d.content for d in s.search([1.0, 0.0], top_k=3, filters=f)])      # []
r = FAISSEmbeddingRetriever(document_store=s, top_k=3)
print([d.content for d in r.run(query_embedding=[1.0, 0.0], filters=f)["documents"]])  # []

Expected behavior
['de'] from both search() and the retriever. A filtered search should return up to top_k matching documents whenever the store has them, as the other document stores do.

Additional context
Seen on main (07a6e48), Python 3.13. A small fix is to search again with a larger k (doubling, up to ntotal) when the filters leave fewer than top_k results, so unfiltered searches and the common case don't change. I have a fix with a test ready and will open a PR.

Lingua principale
Python
Stelle
212
Fork
396
Merge medio
2g 9h
PR unite (30g)
95

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepset-ai/haystack-core-integrations

Tutte le issue di deepset-ai/haystack-core-integrations

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.