Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Ensure scores returned from scoring module are floats and not NumPy values, closes #933

davidmezzetti69145bf98ea9
diff --git a/src/python/txtai/scoring/sif.py b/src/python/txtai/scoring/sif.py
index adf5a52f..19cd307c 100644
--- a/src/python/txtai/scoring/sif.py
+++ b/src/python/txtai/scoring/sif.py
@@ -25,7 +25,7 @@ class SIF(TFIDF):
def score(self, freq, idf, length):
# Set freq to word frequencies across entire index when freq and idf shape don't match
- if isinstance(freq, np.ndarray) and freq.shape != idf.shape:
+ if isinstance(freq, np.ndarray) and freq.shape != np.array(idf).shape:
freq.fill(freq.sum())
# Calculate SIF score
diff --git a/src/python/txtai/scoring/tfidf.py b/src/python/txtai/scoring/tfidf.py
index ec3c81fe..83ab2163 100644
--- a/src/python/txtai/scoring/tfidf.py
+++ b/src/python/txtai/scoring/tfidf.py
@@ -113,10 +113,10 @@ class TFIDF(Scoring):
# Compute IDF scores
idfs = self.computeidf(np.array(list(self.docfreq.values())))
for x, word in enumerate(self.docfreq):
- self.idf[word] = idfs[x]
+ self.idf[word] = float(idfs[x])
# Average IDF score per token
- self.avgidf = np.mean(idfs)
+ self.avgidf = float(np.mean(idfs))
# Calculate average score across index
self.avgscore = self.score(self.avgfreq, self.avgidf, self.avgdl)