Skip to content

MetaFieldRanker ignores missing_meta="drop" when meta values can't be sorted #13230

Closed

Description

@yuv009

Describe the bug
MetaFieldRanker with missing_meta="drop" still returns documents that don't have the meta field, if the other documents have values that can't be sorted together.

Error message
No error. The ranker logs these warnings and then returns the document anyway:

... the Documents with IDs 3 don't have this meta key.
Because the parameter <missing_meta> is set to 'drop', these Documents will be removed from the list of retrieved Documents.

Tried to sort Documents with IDs 1,2, but got TypeError with the message: '<' not supported between instances of 'int' and 'str'

Expected behavior
Documents without the meta field are dropped. The example below should print ['1', '2'].

Additional context
When sorting fails, run() returns deduplicated_documents[:top_k], which includes the documents without the field:

return {"documents": deduplicated_documents[:top_k]}

This is not the case from #12952 (no document has the field), which is fixed. Here some documents have the field, but their values can't be sorted together.

To Reproduce

from haystack import Document
from haystack.components.rankers import MetaFieldRanker

ranker = MetaFieldRanker(meta_field="rating", missing_meta="drop")
docs = [
    Document(id="1", meta={"rating": 1}),
    Document(id="2", meta={"rating": "x"}),
    Document(id="3"),
]
print([d.id for d in ranker.run(documents=docs)["documents"]])
# ['1', '2', '3']

FAQ Check

System:

  • OS: Windows 11
  • Haystack version: main (3.4.0-rc0)

Activity

  1. added theissue type on Oct 12, 2026
  2. aawhan0 commented on Oct 12, 2026

    @aawhan0

    Hi! I'd like to help with this issue if it hasn't been picked up yet.

    My plan is to reproduce the behavior, add regression tests for missing metadata combined with incomparable metadata values, and then make the smallest change needed to ensure missing_meta="drop" is respected.

    Would this be a suitable contribution to take up? Please let me know if there's a preferred approach. Thanks!

  3. yuv009 commented on Oct 12, 2026

    @yuv009
    ContributorAuthor

    Hi @aawhan0, I've already opened #13231 for this.

  4. added
    P2Medium priority, add to the next sprint if no P1 available
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Medium priority, add to the next sprint if no P1 available

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions