Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add test for bb25

davidmezzetti371d5d8a191a
diff --git a/src/python/txtai/scoring/normalize.py b/src/python/txtai/scoring/normalize.py
index 573f3daf..e19e3a0b 100644
--- a/src/python/txtai/scoring/normalize.py
+++ b/src/python/txtai/scoring/normalize.py
@@ -31,9 +31,7 @@ class Normalize:
# Bayesian settings
self.alpha = float(self.config.get("alpha", 1.0))
self.beta = self.config.get("beta")
-
- if self.beta is not None:
- self.beta = float(self.beta)
+ self.beta = float(self.beta) if self.beta is not None else self.beta
def __call__(self, scores, avgscore):
"""
diff --git a/test/python/testscoring/testkeyword.py b/test/python/testscoring/testkeyword.py
index 9955afef..e44d3125 100644
--- a/test/python/testscoring/testkeyword.py
+++ b/test/python/testscoring/testkeyword.py
@@ -356,6 +356,10 @@ class TestKeyword(unittest.TestCase):
self.assertGreater(scores[1][1], 0.0)
self.assertGreater(scores[2][1], scores[1][1])
+ # Test negative scores
+ scores = normalizer([(0, -100.0)], scoring.avgscore)
+ self.assertEqual(scores[0][1], 0.0)
+
# Bayesian normalization with custom parameters
config = {**config, **{"terms": True, "normalize": {"method": "bayes", "alpha": 2.0}}}
scoring = ScoringFactory.create(config)