💡 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
Update scoring models to be consistent with embeddings patterns
davidmezzetti9441fa85a057
diff --git a/src/python/txtai/scoring/base.py b/src/python/txtai/scoring/base.pyindex 09333ac9..cf8c6c8a 100644--- a/src/python/txtai/scoring/base.py+++ b/src/python/txtai/scoring/base.py@@ -42,7 +42,7 @@ class Scoring:Indexes a collection of documents using a scoring method.Args:- documents: list of (id, text|tokens, tags)+ documents: list of (id, dict|text|tokens, tags)"""# Calculate word frequency, total tokens and total documents@@ -75,7 +75,7 @@ class Scoring:# Compute IDF scoresfor word, freq in self.docfreq.items():- self.idf[word] = self.computeIDF(freq)+ self.idf[word] = self.computeidf(freq)# Average IDF score per tokenself.avgidf = sum(self.idf.values()) / len(self.idf)@@ -130,7 +130,7 @@ class Scoring:path: directory path to load model"""- with open(f"{path}/scoring", "rb") as handle:+ with open(path, "rb") as handle:self.__dict__.update(pickle.load(handle))def save(self, path):@@ -141,10 +141,10 @@ class Scoring:path: directory path to save model"""- with open(f"{path}/scoring", "wb") as handle:+ with open(path, "wb") as handle:pickle.dump(self.__dict__, handle, protocol=pickle.HIGHEST_PROTOCOL)- def computeIDF(self, freq):+ def computeidf(self, freq):"""Computes an idf score for word frequency.diff --git a/src/python/txtai/scoring/bm25.py b/src/python/txtai/scoring/bm25.pyindex b5ba668e..3fca5f01 100644--- a/src/python/txtai/scoring/bm25.py+++ b/src/python/txtai/scoring/bm25.py@@ -20,7 +20,7 @@ class BM25(Scoring):self.k1 = k1self.b = b- def computeIDF(self, freq):+ def computeidf(self, freq):# Calculate BM25 IDF scorereturn math.log(1 + (self.total - freq + 0.5) / (freq + 0.5))