def test_score_modifier_with_negative_value(self):
        """Test behavior when a score modifier has a negative value"""
        for index_name in [self.structured_index_name, self.unstructured_index_name]:
            with self.subTest(index_name=index_name):
                docs = [
                    {"_id": "1", "text_field": "test", "double_score_mods": -1.0},
                    {"_id": "2", "text_field": "test", "double_score_mods": 1.0},
                ]
                tensor_fields = ["text_field"] if "unstr" in index_name else None
                self.client.index(index_name).add_documents(documents=docs, tensor_fields=tensor_fields)

                res = self.client.index(index_name).search(
                    q="",
                    score_modifiers={
                        "add_to_score": [{"field_name": "double_score_mods", "weight": 1}]
                    }
                )

                # Expected score calculation:
                # Doc 1: base_score + (-1.0 * 1) = base_score - 1
                # Doc 2: base_score + (1.0 * 1) = base_score + 1
                base_score = 0.845687427
                expected_score_doc1 = base_score - 1
                expected_score_doc2 = base_score + 1

                self.assertAlmostEqual(res["hits"][0]["_score"], expected_score_doc2, places=2)
                self.assertAlmostEqual(res["hits"][1]["_score"], expected_score_doc1, places=2)
                self.assertGreater(res["hits"][0]["_score"], res["hits"][1]["_score"])
Test behavior when a score modifier has a negative value
tests/api_tests/v1/tests/api_tests/test_dict_score_modifiers.py