Skip to content

fix: Update Document.__eq__ to intelligently compare floats#11828

Open
nigamgauri wants to merge 1 commit into
deepset-ai:mainfrom
nigamgauri:fix-document-eq-float-comparison
Open

fix: Update Document.__eq__ to intelligently compare floats#11828
nigamgauri wants to merge 1 commit into
deepset-ai:mainfrom
nigamgauri:fix-document-eq-float-comparison

Conversation

@nigamgauri

Copy link
Copy Markdown

Related Issues

Proposed Changes:

Document.__eq__ performed strict dictionary equality comparison (self.to_dict() == other.to_dict()) on the serialized representation of two documents. This caused equality checks to fail when float fields (such as score, embedding values, sparse_embedding values, or nested floats in meta) differed very slightly due to floating-point imprecision.

This PR replaces the strict comparison in Document.__eq__ with a recursive structure comparison helper (_recursive_is_close) that uses math.isclose (with a relative/absolute tolerance of 1e-7) when encountering floating-point numbers.

How did you test it?

  • Added four new unit tests in test/dataclasses/test_document.py verifying float comparisons for score, embedding, sparse_embedding, and nested meta fields.
  • Verified that all unit tests, format/lint checks (hatch run fmt), and type checks (hatch run test:types) pass successfully.
@nigamgauri nigamgauri requested a review from a team as a code owner June 30, 2026 09:44
@nigamgauri nigamgauri requested review from sjrl and removed request for a team June 30, 2026 09:44
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


gauri nigam seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sjrl

sjrl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Hey @nigamgauri please sign the CLA agreement #11828 (comment) otherwise we can't accept your contribution.

I'll proceed with a review once it's signed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants