💡 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
Add additional tests
davidmezzetticbba20adb433
diff --git a/src/python/txtai/embeddings/base.py b/src/python/txtai/embeddings/base.pyindex 6b57aacd..3e575d32 100644--- a/src/python/txtai/embeddings/base.py+++ b/src/python/txtai/embeddings/base.py@@ -283,7 +283,8 @@ class Embeddings:list of (id, score) for ann search, list of dict for an ann+database search"""- return self.batchsearch([query], limit)[0]+ results = self.batchsearch([query], limit)+ return results[0] if results else resultsdef batchsearch(self, queries, limit=3):"""diff --git a/test/python/testdatabase/testembeddings.py b/test/python/testdatabase/testembeddings.pyindex 152e6d53..cf7df2b4 100644--- a/test/python/testdatabase/testembeddings.py+++ b/test/python/testdatabase/testembeddings.py@@ -124,6 +124,14 @@ class TestEmbeddings(unittest.TestCase):self.assertEqual(self.embeddings.count(), 5)self.assertEqual(result["text"], self.data[5])+ def testEmpty(self):+ """+ Test empty index+ """++ embeddings = Embeddings({"path": "sentence-transformers/nli-mpnet-base-v2", "content": True})+ self.assertEqual(embeddings.search("test"), [])+def testGenerator(self):"""Test index with a generatordiff --git a/test/python/testembeddings.py b/test/python/testembeddings.pyindex 004fd80e..be0753f4 100644--- a/test/python/testembeddings.py+++ b/test/python/testembeddings.py@@ -65,6 +65,14 @@ class TestEmbeddings(unittest.TestCase):self.assertEqual(self.embeddings.count(), 5)self.assertEqual(uid, 5)+ def testEmpty(self):+ """+ Test empty index+ """++ embeddings = Embeddings()+ self.assertEqual(embeddings.search("test"), [])+def testExternal(self):"""Test embeddings backed by external vectorsdiff --git a/test/python/testworkflow.py b/test/python/testworkflow.pyindex 0b22b610..b3769401 100644--- a/test/python/testworkflow.py+++ b/test/python/testworkflow.py@@ -7,6 +7,7 @@ import globimport ioimport osimport tempfile+import sysimport unittestimport numpy as np@@ -410,6 +411,27 @@ class TestWorkflow(unittest.TestCase):results = np.array([x.numpy() for x in workflow(torch.tensor([2, 4, 6]))])self.assertTrue(np.array_equal(np.array(results), np.array([[4, 16, 36], [8, 64, 216]])))+ def testYamlFunctionWorkflow(self):+ """+ Tests YAML workflow with a function action+ """++ # Create function and add to module+ def action(elements):+ return [x * 2 for x in elements]++ sys.modules[__name__].action = action++ workflow = """+ workflow:+ run:+ tasks:+ - testworkflow.action+ """++ app = API(workflow)+ self.assertEqual(list(app.workflow("run", [1, 2])), [2, 4])+def testYamlIndexWorkflow(self):"""Tests reading a YAML index workflow in Python.