💡 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 test method docs for consistency
davidmezzettib14d8769dd32
diff --git a/test/python/testann.py b/test/python/testann.pyindex 6540253e..71f42fd7 100644--- a/test/python/testann.py+++ b/test/python/testann.py@@ -13,7 +13,7 @@ from txtai.ann import ANNFactory, ANNclass TestANN(unittest.TestCase):"""- ANN tests+ ANN tests."""def testAnnoy(self):@@ -124,7 +124,7 @@ class TestANN(unittest.TestCase):def append(self, name, params=None, length=500):"""- Appends new data to index+ Appends new data to index.Args:name: backend namediff --git a/test/python/testapi/testcluster.py b/test/python/testapi/testcluster.pyindex 1151c247..9fc3f7bc 100644--- a/test/python/testapi/testcluster.py+++ b/test/python/testapi/testcluster.py@@ -26,7 +26,7 @@ cluster:class RequestHandler(BaseHTTPRequestHandler):"""- Test HTTP handler+ Test HTTP handler."""def do_GET(self):diff --git a/test/python/testapi/testembeddings.py b/test/python/testapi/testembeddings.pyindex 038dd717..426a5d70 100644--- a/test/python/testapi/testembeddings.py+++ b/test/python/testapi/testembeddings.py@@ -41,7 +41,7 @@ writable: Falseclass TestEmbeddings(unittest.TestCase):"""- API tests for embeddings indices+ API tests for embeddings indices."""@staticmethoddiff --git a/test/python/testapi/testextension.py b/test/python/testapi/testextension.pyindex 33ad71b0..04f3f906 100644--- a/test/python/testapi/testextension.py+++ b/test/python/testapi/testextension.py@@ -22,7 +22,7 @@ testapi.testextension.SamplePipeline:class SampleRouter:"""- Sample API router+ Sample API router."""router = APIRouter()@@ -45,7 +45,7 @@ class SampleRouter:class SampleExtension(Extension):"""- Sample API extension+ Sample API extension."""def __call__(self, app):@@ -54,7 +54,7 @@ class SampleExtension(Extension):class SamplePipeline(Pipeline):"""- Sample pipeline+ Sample pipeline."""def __call__(self, text):@@ -63,7 +63,7 @@ class SamplePipeline(Pipeline):class TestExtension(unittest.TestCase):"""- API tests for extensions+ API tests for extensions."""@staticmethod@@ -100,7 +100,7 @@ class TestExtension(unittest.TestCase):def testEmpty(self):"""- Tests an empty extension.+ Tests an empty extension"""extension = Extension()@@ -108,7 +108,7 @@ class TestExtension(unittest.TestCase):def testExtension(self):"""- Tests a pipeline extension.+ Tests a pipeline extension"""text = self.client.get("sample?text=Test%20String").json()diff --git a/test/python/testapi/testpipelines.py b/test/python/testapi/testpipelines.pyindex 8b6e85d4..01bfc6fe 100644--- a/test/python/testapi/testpipelines.py+++ b/test/python/testapi/testpipelines.py@@ -56,7 +56,7 @@ translation:# pylint: disable=R0904class TestPipelines(unittest.TestCase):"""- API tests for pipelines+ API tests for pipelines."""@staticmethoddiff --git a/test/python/testapi/testworkflow.py b/test/python/testapi/testworkflow.pyindex 897305ba..3cef7a44 100644--- a/test/python/testapi/testworkflow.py+++ b/test/python/testapi/testworkflow.py@@ -81,7 +81,7 @@ workflow:class RequestHandler(BaseHTTPRequestHandler):"""- Test HTTP handler+ Test HTTP handler."""def do_GET(self):@@ -126,7 +126,7 @@ class RequestHandler(BaseHTTPRequestHandler):class TestWorkflow(unittest.TestCase):"""- API tests for workflows+ API tests for workflows."""@staticmethod@@ -170,7 +170,7 @@ class TestWorkflow(unittest.TestCase):def testServiceGet(self):"""- Test workflow with ServiceTask GET via API.+ Test workflow with ServiceTask GET via API"""text = "This is a test sentence. And another sentence to split."@@ -181,7 +181,7 @@ class TestWorkflow(unittest.TestCase):def testServicePost(self):"""- Test workflow with ServiceTask POST via API.+ Test workflow with ServiceTask POST via API"""text = "This is a test sentence. And another sentence to split."@@ -192,7 +192,7 @@ class TestWorkflow(unittest.TestCase):def testServiceXml(self):"""- Test workflow with ServiceTask GET via API and XML response.+ Test workflow with ServiceTask GET via API and XML response"""text = "This is a test sentence. And another sentence to split."@@ -203,7 +203,7 @@ class TestWorkflow(unittest.TestCase):def testWorkflowLabels(self):"""- Test workflow with labels via API.+ Test workflow with labels via API"""text = "This is the best"@@ -216,7 +216,7 @@ class TestWorkflow(unittest.TestCase):def testWorkflowSegment(self):"""- Test workflow with segmentation via API.+ Test workflow with segmentation via API"""text = "This is a test sentence. And another sentence to split."diff --git a/test/python/testdatabase/testembeddings.py b/test/python/testdatabase/testembeddings.pyindex b0e46485..bdf425f4 100644--- a/test/python/testdatabase/testembeddings.py+++ b/test/python/testdatabase/testembeddings.py@@ -2,6 +2,8 @@Embeddings+database module tests"""+import contextlib+import ioimport osimport tempfileimport unittest@@ -12,7 +14,7 @@ from txtai.database import Database, SQLExceptionclass TestEmbeddings(unittest.TestCase):"""- Embeddings with a database tests+ Embeddings with a database tests."""@classmethod@@ -139,6 +141,20 @@ class TestEmbeddings(unittest.TestCase):self.assertEqual(result["text"], self.data[4])+ def testInfo(self):+ """+ Test info+ """++ # Create an index for the list of text+ self.embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])++ output = io.StringIO()+ with contextlib.redirect_stdout(output):+ self.embeddings.info()++ self.assertTrue("txtai" in output.getvalue())+def testMultiSave(self):"""Tests multiple successive savesdiff --git a/test/python/testdatabase/testencoder.py b/test/python/testdatabase/testencoder.pynew file mode 100644index 00000000..f28a575e--- /dev/null+++ b/test/python/testdatabase/testencoder.py@@ -0,0 +1,101 @@+"""+Tests encoding/decoding database objects+"""++import glob+import unittest++from PIL import Image++from txtai.embeddings import Embeddings++# pylint: disable = C0411+from utils import Utils+++class TestEncoder(unittest.TestCase):+ """+ Encoder tests.+ """++ @classmethod+ def setUpClass(cls):+ """+ Initialize test data.+ """++ cls.data = []+ for path in glob.glob(Utils.PATH + "/*jpg"):+ cls.data.append((path, {"object": Image.open(path)}, None))++ # Create embeddings model, backed by sentence-transformers & transformers+ cls.embeddings = Embeddings(+ {"method": "sentence-transformers", "path": "sentence-transformers/clip-ViT-B-32", "content": True, "objects": "image"}+ )++ def testDefault(self):+ """+ Tests an index with default encoder+ """++ try:+ # Change to use default encoder+ self.embeddings.config["objects"] = True+ data = [(0, {"object": bytearray([1, 2, 3]), "text": "default test"}, None)]++ # Create an index for the list of images+ self.embeddings.index(data)++ result = self.embeddings.search("select object from txtai limit 1")[0]++ self.assertEqual(result["object"].getvalue(), bytearray([1, 2, 3]))+ finally:+ self.embeddings.config["objects"] = "image"++ def testImages(self):+ """+ Tests an index with image encoder+ """++ # Create an index for the list of images+ self.embeddings.index(self.data)++ result = self.embeddings.search("select id, object from txtai where similar('universe') limit 1")[0]++ self.assertTrue(result["id"].endswith("stars.jpg"))+ self.assertTrue(isinstance(result["object"], Image.Image))++ def testPickle(self):+ """+ Tests an index with pickle encoder+ """++ try:+ # Change to use default encoder+ self.embeddings.config["objects"] = "pickle"+ data = [(0, {"object": [1, 2, 3, 4, 5], "text": "default test"}, None)]++ # Create an index for the list of images+ self.embeddings.index(data)++ result = self.embeddings.search("select object from txtai limit 1")[0]++ self.assertEqual(result["object"], [1, 2, 3, 4, 5])+ finally:+ self.embeddings.config["objects"] = "image"++ def testReindex(self):+ """+ Tests reindex with objects+ """++ # Create an index for the list of images+ self.embeddings.index(self.data)++ # Reindex images+ self.embeddings.reindex({"method": "sentence-transformers", "path": "sentence-transformers/clip-ViT-B-32"})++ result = self.embeddings.search("select id, object from txtai where similar('universe') limit 1")[0]++ self.assertTrue(result["id"].endswith("stars.jpg"))+ self.assertTrue(isinstance(result["object"], Image.Image))diff --git a/test/python/testdatabase/testsql.py b/test/python/testdatabase/testsql.pyindex 19a18dc0..94596b8f 100644--- a/test/python/testdatabase/testsql.py+++ b/test/python/testdatabase/testsql.py@@ -169,7 +169,7 @@ class TestSQL(unittest.TestCase):def assertSql(self, clause, query, expected):"""- Helper method to assert a query clause is as expected+ Helper method to assert a query clause is as expected.Args:clause: clause to selectdiff --git a/test/python/testembeddings.py b/test/python/testembeddings.pyindex 0982425b..4be52409 100644--- a/test/python/testembeddings.py+++ b/test/python/testembeddings.py@@ -12,7 +12,7 @@ from txtai.vectors import WordVectorsclass TestEmbeddings(unittest.TestCase):"""- Embeddings tests+ Embeddings tests."""@classmethoddiff --git a/test/python/testoptional.py b/test/python/testoptional.pyindex 426bb592..76df4a39 100644--- a/test/python/testoptional.py+++ b/test/python/testoptional.py@@ -58,7 +58,7 @@ class TestOptional(unittest.TestCase):@classmethoddef tearDownClass(cls):"""- Resets modules environment back to initial state+ Resets modules environment back to initial state."""# Reset replaced modules in setup@@ -68,28 +68,25 @@ class TestOptional(unittest.TestCase):else:del sys.modules[key]- def testAnn(self):+ def testApi(self):"""- Test missing ann dependencies+ Test missing api dependencies"""- from txtai.ann import ANNFactory-- with self.assertRaises(ImportError):- ANNFactory.create({"backend": "annoy"})-with self.assertRaises(ImportError):- ANNFactory.create({"backend": "hnsw"})+ import txtai.api- def testApi(self):+ def testDatabase(self):"""- Test missing api dependencies+ Test missing database dependencies"""+ from txtai.database import ImageEncoder+with self.assertRaises(ImportError):- import txtai.api+ ImageEncoder()- def testModels(self):+ def testModel(self):"""Test missing model dependencies"""@@ -137,13 +134,20 @@ class TestOptional(unittest.TestCase):with self.assertRaises(ImportError):Translation().detect(["test"])- def testVectors(self):+ def testSimilarity(self):"""- Test missing vectors dependencies+ Test missing similarity dependencies"""+ from txtai.ann import ANNFactoryfrom txtai.vectors import VectorsFactory+ with self.assertRaises(ImportError):+ ANNFactory.create({"backend": "annoy"})++ with self.assertRaises(ImportError):+ ANNFactory.create({"backend": "hnsw"})+with self.assertRaises(ImportError):VectorsFactory.create({"method": "words"}, None)diff --git a/test/python/testpipeline/__init__.py b/test/python/testpipeline/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/test/python/testcaption.py b/test/python/testpipeline/testcaption.pysimilarity index 95%rename from test/python/testcaption.pyrename to test/python/testpipeline/testcaption.pyindex 6cacb9e9..a75f44bc 100644--- a/test/python/testcaption.py+++ b/test/python/testpipeline/testcaption.py@@ -14,7 +14,7 @@ from utils import Utilsclass TestCaption(unittest.TestCase):"""- Caption tests+ Caption tests."""def testCaption(self):diff --git a/test/python/testextractor.py b/test/python/testpipeline/testextractor.pysimilarity index 98%rename from test/python/testextractor.pyrename to test/python/testpipeline/testextractor.pyindex 6f81e34f..448f5814 100644--- a/test/python/testextractor.py+++ b/test/python/testpipeline/testextractor.py@@ -11,7 +11,7 @@ from txtai.pipeline import Extractor, Similarityclass TestExtractor(unittest.TestCase):"""- Extractor tests+ Extractor tests."""@classmethod@@ -62,7 +62,7 @@ class TestExtractor(unittest.TestCase):def testEmptyQuery(self):"""- Tests an empty extractor queries list.+ Tests an empty extractor queries list"""self.assertEqual(self.extractor.query(None, None), [])diff --git a/test/python/testlabels.py b/test/python/testpipeline/testlabels.pysimilarity index 99%rename from test/python/testlabels.pyrename to test/python/testpipeline/testlabels.pyindex 7dc77332..cb46599b 100644--- a/test/python/testlabels.py+++ b/test/python/testpipeline/testlabels.py@@ -9,7 +9,7 @@ from txtai.pipeline import Labels, Similarityclass TestLabels(unittest.TestCase):"""- Labels tests+ Labels tests."""@classmethoddiff --git a/test/python/testobjects.py b/test/python/testpipeline/testobjects.pysimilarity index 97%rename from test/python/testobjects.pyrename to test/python/testpipeline/testobjects.pyindex b91321a0..3d78ba75 100644--- a/test/python/testobjects.py+++ b/test/python/testpipeline/testobjects.py@@ -12,7 +12,7 @@ from utils import Utilsclass TestObjects(unittest.TestCase):"""- Object detection tests+ Object detection tests."""def testClassification(self):diff --git a/test/python/testonnx.py b/test/python/testpipeline/testonnx.pysimilarity index 98%rename from test/python/testonnx.pyrename to test/python/testpipeline/testonnx.pyindex bf5c5a9c..c72f5410 100644--- a/test/python/testonnx.py+++ b/test/python/testpipeline/testonnx.py@@ -16,13 +16,13 @@ from txtai.pipeline import HFOnnx, HFTrainer, Labels, MLOnnx, Questionsclass TestOnnx(unittest.TestCase):"""- ONNX tests+ ONNX tests."""@classmethoddef setUpClass(cls):"""- Create default datasets+ Create default datasets."""cls.data = [{"text": "Dogs", "label": 0}, {"text": "dog", "label": 0}, {"text": "Cats", "label": 1}, {"text": "cat", "label": 1}] * 100diff --git a/test/python/testquantization.py b/test/python/testpipeline/testquantization.pysimilarity index 97%rename from test/python/testquantization.pyrename to test/python/testpipeline/testquantization.pyindex 7289ee50..c65c1fc3 100644--- a/test/python/testquantization.py+++ b/test/python/testpipeline/testquantization.py@@ -12,7 +12,7 @@ from txtai.pipeline import HFModel, HFPipelineclass TestQuantization(unittest.TestCase):"""- Quantization tests+ Quantization tests."""@unittest.skipIf(platform.system() == "Darwin", "Quantized models not supported on macOS")diff --git a/test/python/testsummary.py b/test/python/testpipeline/testsummary.pysimilarity index 98%rename from test/python/testsummary.pyrename to test/python/testpipeline/testsummary.pyindex b2d08f97..8d51f88d 100644--- a/test/python/testsummary.py+++ b/test/python/testpipeline/testsummary.py@@ -9,7 +9,7 @@ from txtai.pipeline import Summaryclass TestSummary(unittest.TestCase):"""- Summary tests+ Summary tests."""@classmethoddiff --git a/test/python/testtabular.py b/test/python/testpipeline/testtabular.pysimilarity index 99%rename from test/python/testtabular.pyrename to test/python/testpipeline/testtabular.pyindex 0d9d88e8..973e86ef 100644--- a/test/python/testtabular.py+++ b/test/python/testpipeline/testtabular.py@@ -12,7 +12,7 @@ from utils import Utilsclass TestTabular(unittest.TestCase):"""- Tabular tests+ Tabular tests."""@classmethoddiff --git a/test/python/testtextractor.py b/test/python/testpipeline/testtextractor.pysimilarity index 98%rename from test/python/testtextractor.pyrename to test/python/testpipeline/testtextractor.pyindex f283ee9a..c6569056 100644--- a/test/python/testtextractor.py+++ b/test/python/testpipeline/testtextractor.py@@ -12,7 +12,7 @@ from utils import Utilsclass TestTextractor(unittest.TestCase):"""- Textractor tests+ Textractor tests."""def testBeautifulSoup(self):diff --git a/test/python/testtokenizer.py b/test/python/testpipeline/testtokenizer.pysimilarity index 94%rename from test/python/testtokenizer.pyrename to test/python/testpipeline/testtokenizer.pyindex 9924a635..bfb10093 100644--- a/test/python/testtokenizer.py+++ b/test/python/testpipeline/testtokenizer.py@@ -9,7 +9,7 @@ from txtai.pipeline import Tokenizerclass TestTokenizer(unittest.TestCase):"""- Tokenizer tests+ Tokenizer tests."""def testTokenize(self):diff --git a/test/python/testtrainer.py b/test/python/testpipeline/testtrainer.pysimilarity index 97%rename from test/python/testtrainer.pyrename to test/python/testpipeline/testtrainer.pyindex 6c8d7840..ee106575 100644--- a/test/python/testtrainer.py+++ b/test/python/testpipeline/testtrainer.py@@ -16,13 +16,13 @@ from txtai.pipeline import HFTrainer, Labels, Questionsclass TestTrainer(unittest.TestCase):"""- Trainer tests+ Trainer tests."""@classmethoddef setUpClass(cls):"""- Create default datasets+ Create default datasets."""cls.data = [{"text": "Dogs", "label": 0}, {"text": "dog", "label": 0}, {"text": "Cats", "label": 1}, {"text": "cat", "label": 1}] * 100@@ -134,14 +134,14 @@ class TestTrainer(unittest.TestCase):def testEmpty(self):"""- Tests an empty training data object.+ Tests an empty training data object"""self.assertIsNone(Data(None, None, None).process(None))def testQA(self):"""- Tests training a QA model.+ Tests training a QA model"""# Training data@@ -163,7 +163,7 @@ class TestTrainer(unittest.TestCase):def testRegression(self):"""- Tests training a model with a regression (continuous) output.+ Tests training a model with a regression (continuous) output"""data = []diff --git a/test/python/testtranscription.py b/test/python/testpipeline/testtranscription.pysimilarity index 95%rename from test/python/testtranscription.pyrename to test/python/testpipeline/testtranscription.pyindex 3efb0ba4..641f12a1 100644--- a/test/python/testtranscription.py+++ b/test/python/testpipeline/testtranscription.py@@ -12,7 +12,7 @@ from utils import Utilsclass TestTranscription(unittest.TestCase):"""- Transcription tests+ Transcription tests."""def testTranscription(self):diff --git a/test/python/testtranslation.py b/test/python/testpipeline/testtranslation.pysimilarity index 92%rename from test/python/testtranslation.pyrename to test/python/testpipeline/testtranslation.pyindex f8da8b29..f301e8e7 100644--- a/test/python/testtranslation.py+++ b/test/python/testpipeline/testtranslation.py@@ -10,12 +10,12 @@ from txtai.pipeline import Translationclass TestTranslation(unittest.TestCase):"""- Translation tests+ Translation tests."""def testLongTranslation(self):"""- Tests a translation longer than max tokenization length.+ Tests a translation longer than max tokenization length"""translate = Translation()@@ -58,7 +58,7 @@ class TestTranslation(unittest.TestCase):def testNoLang(self):"""- Test no matching language id.+ Test no matching language id"""translate = Translation()@@ -66,7 +66,7 @@ class TestTranslation(unittest.TestCase):def testNoModel(self):"""- Tests no known available model found.+ Tests no known available model found"""translate = Translation()diff --git a/test/python/testscoring.py b/test/python/testscoring.pyindex 2185947a..c1cadc8e 100644--- a/test/python/testscoring.py+++ b/test/python/testscoring.py@@ -11,7 +11,7 @@ from txtai.scoring import ScoringFactoryclass TestScoring(unittest.TestCase):"""- Scoring tests+ Scoring tests."""@classmethoddiff --git a/test/python/testvectors/__init__.py b/test/python/testvectors/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/test/python/testtransformers.py b/test/python/testvectors/testtransformers.pysimilarity index 87%rename from test/python/testtransformers.pyrename to test/python/testvectors/testtransformers.pyindex 9400f71c..05223ef7 100644--- a/test/python/testtransformers.py+++ b/test/python/testvectors/testtransformers.py@@ -51,12 +51,12 @@ class TestTransformersVectors(unittest.TestCase):"""self.model.tokenize = True- self.assertEqual(self.model.text("Y 123 This is a test!"), "test")- self.assertEqual(self.model.text(["This", "is", "a", "test"]), "This is a test")+ self.assertEqual(self.model.prepare("Y 123 This is a test!"), "test")+ self.assertEqual(self.model.prepare(["This", "is", "a", "test"]), "This is a test")self.model.tokenize = False- self.assertEqual(self.model.text("Y 123 This is a test!"), "Y 123 This is a test!")- self.assertEqual(self.model.text(["This", "is", "a", "test"]), "This is a test")+ self.assertEqual(self.model.prepare("Y 123 This is a test!"), "Y 123 This is a test!")+ self.assertEqual(self.model.prepare(["This", "is", "a", "test"]), "This is a test")def testTransform(self):"""diff --git a/test/python/testvectors.py b/test/python/testvectors/testvectors.pysimilarity index 96%rename from test/python/testvectors.pyrename to test/python/testvectors/testvectors.pyindex d754463c..6b62d8aa 100644--- a/test/python/testvectors.py+++ b/test/python/testvectors/testvectors.py@@ -9,7 +9,7 @@ from txtai.vectors import Vectorsclass TestVectors(unittest.TestCase):"""- Vectors tests+ Vectors tests."""def testNotImplemented(self):diff --git a/test/python/testwordvectors.py b/test/python/testvectors/testwordvectors.pysimilarity index 99%rename from test/python/testwordvectors.pyrename to test/python/testvectors/testwordvectors.pyindex ef8d6f46..2255ffd2 100644--- a/test/python/testwordvectors.py+++ b/test/python/testvectors/testwordvectors.py@@ -11,7 +11,7 @@ from txtai.vectors import WordVectors, VectorsFactoryclass TestWordVectors(unittest.TestCase):"""- Vectors tests+ Vectors tests."""@classmethoddiff --git a/test/python/testworkflow.py b/test/python/testworkflow.pyindex d0663a14..661c80af 100644--- a/test/python/testworkflow.py+++ b/test/python/testworkflow.py@@ -20,7 +20,7 @@ from utils import Utilsclass TestWorkflow(unittest.TestCase):"""- Workflow tests+ Workflow tests."""def testBaseWorkflow(self):