@@ -123,6 +123,64 @@ def test_basic_equality_id():
123123 assert doc1 != doc2
124124
125125
126+ def test_equality_float_precision_score ():
127+ doc1 = Document (content = "test text" , score = 0.123456782 , id = "1" )
128+ doc2 = Document (content = "test text" , score = 0.123456780 , id = "1" )
129+ assert doc1 == doc2
130+
131+ doc3 = Document (content = "test text" , score = 0.123456782 , id = "1" )
132+ doc4 = Document (content = "test text" , score = 0.234567890 , id = "1" )
133+ assert doc3 != doc4
134+
135+ doc5 = Document (content = "test text" , score = None , id = "1" )
136+ doc6 = Document (content = "test text" , score = 0.123456782 , id = "1" )
137+ assert doc5 != doc6
138+
139+
140+ def test_equality_float_precision_embedding ():
141+ doc1 = Document (content = "test text" , embedding = [0.123456782 , 0.987654321 ], id = "1" )
142+ doc2 = Document (content = "test text" , embedding = [0.123456780 , 0.987654320 ], id = "1" )
143+ assert doc1 == doc2
144+
145+ doc3 = Document (content = "test text" , embedding = [0.123456782 , 0.987654321 ], id = "1" )
146+ doc4 = Document (content = "test text" , embedding = [0.123456782 , 0.5 ], id = "1" )
147+ assert doc3 != doc4
148+
149+ doc5 = Document (content = "test text" , embedding = [0.123456782 ], id = "1" )
150+ doc6 = Document (content = "test text" , embedding = [0.123456782 , 0.987654321 ], id = "1" )
151+ assert doc5 != doc6
152+
153+ doc7 = Document (content = "test text" , embedding = None , id = "1" )
154+ doc8 = Document (content = "test text" , embedding = [0.123456782 ], id = "1" )
155+ assert doc7 != doc8
156+
157+
158+ def test_equality_float_precision_sparse_embedding ():
159+ from haystack .dataclasses .sparse_embedding import SparseEmbedding
160+
161+ se1 = SparseEmbedding (indices = [0 , 1 ], values = [0.123456782 , 0.987654321 ])
162+ se2 = SparseEmbedding (indices = [0 , 1 ], values = [0.123456780 , 0.987654320 ])
163+ doc1 = Document (content = "test text" , sparse_embedding = se1 , id = "1" )
164+ doc2 = Document (content = "test text" , sparse_embedding = se2 , id = "1" )
165+ assert doc1 == doc2
166+
167+ se3 = SparseEmbedding (indices = [0 , 1 ], values = [0.123456782 , 0.987654321 ])
168+ se4 = SparseEmbedding (indices = [0 , 1 ], values = [0.123456782 , 0.5 ])
169+ doc3 = Document (content = "test text" , sparse_embedding = se3 , id = "1" )
170+ doc4 = Document (content = "test text" , sparse_embedding = se4 , id = "1" )
171+ assert doc3 != doc4
172+
173+
174+ def test_equality_float_precision_nested_meta ():
175+ doc1 = Document (content = "test text" , meta = {"float_val" : 0.123456782 }, id = "1" )
176+ doc2 = Document (content = "test text" , meta = {"float_val" : 0.123456780 }, id = "1" )
177+ assert doc1 == doc2
178+
179+ doc3 = Document (content = "test text" , meta = {"float_val" : 0.123456782 }, id = "1" )
180+ doc4 = Document (content = "test text" , meta = {"float_val" : 0.5 }, id = "1" )
181+ assert doc3 != doc4
182+
183+
126184def test_to_dict ():
127185 doc = Document ()
128186 assert doc .to_dict () == {
0 commit comments