Skip to content

Update Document.__eq__ to intelligently compare floats #8412

Description

@sjrl

Unsure if this would classify as a bug or a feature, but the Document equality method does a direct dict comparison between two documents.

I think this is potentially sub-optimal in regards to when the score value is set in the Document. It's possible that all other aspects of two Documents match except the score value could differ only slightly due to float imprecision. For example,

from haystack import Document
doc1 = Document(content="doc1", id="1", score=0.123456782)
doc2 = Document(content="doc1", id="1", score=0.12345678)
doc1 == doc2
# False

To me this feels misleading since I'd normally say these two Documents should be considered the same.

Metadata

Metadata

Assignees

Labels

P3Low priority, leave it in the backlog

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions