deepset-ai / deepset-ai/haystack

Update Document.__eq__ to intelligently compare floats

Open
#8,412 5 comments 1 reaction 1 assignee View on GitHub

@sjrl is already working on this.

Since Jun 30, 2026.

P3
Dominant language
Python
Stars
26.6k
Forks
3.2k
Avg merge
1d 3h
Merged PRs (30d)
194

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.