💡 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
Apply the API limit default and bounds to batchsearch, closes #1509
Fahmid Arman16a8a38063c0
diff --git a/src/python/txtai/api/base.py b/src/python/txtai/api/base.pyindex 3798dda6..16c37896 100644--- a/src/python/txtai/api/base.py+++ b/src/python/txtai/api/base.py@@ -43,8 +43,10 @@ class API(Application):return super().search(query, limit, weights, index, parameters, graph)def batchsearch(self, queries, limit=None, weights=None, index=None, parameters=None, graph=False):+ limit = self.limit(limit)+if self.cluster:- return self.cluster.batchsearch(queries, self.limit(limit), weights, index, parameters, graph)+ return self.cluster.batchsearch(queries, limit, weights, index, parameters, graph)return super().batchsearch(queries, limit, weights, index, parameters, graph)diff --git a/test/python/testapi/testapiembeddings.py b/test/python/testapi/testapiembeddings.pyindex b050eb5c..91e2884c 100644--- a/test/python/testapi/testapiembeddings.py+++ b/test/python/testapi/testapiembeddings.py@@ -320,6 +320,19 @@ class TestEmbeddings(unittest.TestCase):uids = [result[0]["id"] for result in results]self.assertEqual(uids, [4, 1])+ def testSearchBatchLimit(self):+ """+ Test batch search applies the same default and bounds to limit as search+ """++ api = API({"writable": True, "embeddings": {"keyword": True, "content": True}})+ api.add([{"id": x, "text": f"apple {x}"} for x in range(300)])+ api.index()++ self.assertEqual(len(api.search("apple")), 10)+ self.assertEqual([len(x) for x in api.batchsearch(["apple", "apple"])], [10, 10])+ self.assertEqual([len(x) for x in api.batchsearch(["apple"], 1000)], [250])+def testSimilarity(self):"""Test similarity via API