💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
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.pyindex 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 scorediff --git a/src/python/txtai/scoring/tfidf.py b/src/python/txtai/scoring/tfidf.pyindex 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 scoresidfs = 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 indexself.avgscore = self.score(self.avgfreq, self.avgidf, self.avgdl)