Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Code cleanup

davidmezzetti262b03027edd
diff --git a/src/python/txtai/graph/topics.py b/src/python/txtai/graph/topics.py
index 9cf3073f..1ed83f14 100644
--- a/src/python/txtai/graph/topics.py
+++ b/src/python/txtai/graph/topics.py
@@ -82,10 +82,7 @@ class Topics:
# Get topn terms
terms = self.topn(idf, topn)
- # Sort community by score descending. Term search only returns nodes with a
- # positive score, so nodes matching none of the topic terms come back empty.
- # Keep them, ranked last by centrality, otherwise they are dropped from the
- # topic and lose their topic/topicrank attributes entirely.
+ # Sort community by score descending. Ensure both scored and unscored nodes are kept in community.
ranked = [uid for uid, _ in scoring.search(terms, len(community))]
unranked = sorted(set(community) - set(ranked), key=lambda x: centrality[x], reverse=True)
community = ranked + unranked
diff --git a/test/python/testann/testsparse.py b/test/python/testann/testsparse.py
index e12212d8..f95d2736 100644
--- a/test/python/testann/testsparse.py
+++ b/test/python/testann/testsparse.py
@@ -181,19 +181,19 @@ class TestSparse(unittest.TestCase):
features = []
fit = MiniBatchKMeans.fit
- def spy(self, x, *args, **kwargs):
+ def logfit(self, x, *args, **kwargs):
features.append(x.shape[1])
return fit(self, x, *args, **kwargs)
# nfeatures unset trains on the full feature space
ann = SparseANNFactory.create({"backend": "ivfsparse", "ivfsparse": {"nlist": 2}})
- with patch("txtai.ann.sparse.ivfsparse.MiniBatchKMeans.fit", spy):
+ with patch("txtai.ann.sparse.ivfsparse.MiniBatchKMeans.fit", logfit):
ann.index(data)
ann.close()
# nfeatures limits training to the top n features
ann = SparseANNFactory.create({"backend": "ivfsparse", "ivfsparse": {"nlist": 2, "nfeatures": 10}})
- with patch("txtai.ann.sparse.ivfsparse.MiniBatchKMeans.fit", spy):
+ with patch("txtai.ann.sparse.ivfsparse.MiniBatchKMeans.fit", logfit):
ann.index(data)
ann.close()