💡 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
Test updates
davidmezzetti86af7ec344b9
diff --git a/test/python/testann/testdense.py b/test/python/testann/testdense.pyindex 11b6e3d2..14e5cfa1 100644--- a/test/python/testann/testdense.py+++ b/test/python/testann/testdense.py@@ -196,21 +196,6 @@ class TestDense(unittest.TestCase):# Test with custom settingsself.runTests("hnsw", {"hnsw": {"efconstruction": 100, "m": 4, "randomseed": 0, "efsearch": 5}})- def testHnswSearchLimitExceedsCount(self):- """- Test Hnswlib backend search when limit exceeds the indexed element count- """-- data = np.random.rand(3, 240).astype(np.float32)- self.normalize(data)-- ann = ANNFactory.create({"backend": "hnsw", "dimensions": 240})- ann.index(data)-- # Query limit (10) exceeds the number of indexed elements (3), previously raised a RuntimeError- results = ann.search(data[0:1], 10)- self.assertEqual(len(results[0]), 3)-@unittest.skipIf(os.name == "nt", "Skip Milvus on Windows")def testMilvus(self):"""@@ -475,6 +460,7 @@ class TestDense(unittest.TestCase):self.assertEqual(self.delete(name, params, [100000]).count(), 10000)self.assertGreater(self.search(name, params), 0)+ self.assertGreater(self.limit(name, params), 0)def backend(self, name, params=None, length=10000):"""@@ -593,6 +579,28 @@ class TestDense(unittest.TestCase):# Ensure top result has similarity > 0return model.search(np.array([query]), 1)[0][0][1]+ def limit(self, name, params=None):+ """+ Test ANN limit search.++ Args:+ name: backend name+ params: additional config parameters++ Returns:+ search results+ """++ # Generate ANN index+ model = self.backend(name, params, 50)++ # Generate query vector+ query = np.random.rand(240).astype(np.float32)+ self.normalize(query)++ # Ensure limit being > count doesn't throw an error+ return model.search(np.array([query]), 100)[0][0][1]+def normalize(self, embeddings):"""Normalizes embeddings using L2 normalization. Operation applied directly on array.diff --git a/test/python/testapi/testauthorization.py b/test/python/testapi/testauthorization.pyindex 7be9b144..927f6461 100644--- a/test/python/testapi/testauthorization.py+++ b/test/python/testapi/testauthorization.py@@ -24,7 +24,6 @@ class TestAuthorization(unittest.TestCase):os.environ,{"CONFIG": os.path.join(tempfile.gettempdir(), "testapi.yml"),- "DEPENDENCIES": "txtai.api.Authorization","TOKEN": hashlib.sha256("token".encode("utf-8")).hexdigest(),},)diff --git a/test/python/testapi/testdependency.py b/test/python/testapi/testdependency.pynew file mode 100644index 00000000..4d7348b4--- /dev/null+++ b/test/python/testapi/testdependency.py@@ -0,0 +1,66 @@+"""+Dependency module tests+"""++import os+import tempfile+import unittest++from unittest.mock import patch++from fastapi.testclient import TestClient++from txtai.api import application+++class SampleDependency:+ """+ Sample dependency+ """++ def __call__(self):+ raise NotImplementedError("Dependency test")+++class TestDependency(unittest.TestCase):+ """+ API tests for dependency injection+ """++ @staticmethod+ @patch.dict(+ os.environ,+ {"CONFIG": os.path.join(tempfile.gettempdir(), "testapi.yml"), "DEPENDENCIES": "testapi.testdependency.SampleDependency"},+ )+ def start():+ """+ Starts a mock FastAPI client.+ """++ config = os.path.join(tempfile.gettempdir(), "testapi.yml")++ with open(config, "w", encoding="utf-8") as output:+ output.write("embeddings:\n")++ # Create new application and set on client+ application.app = application.create()+ client = TestClient(application.app)+ application.start()++ return client++ @classmethod+ def setUpClass(cls):+ """+ Create API client on creation of class.+ """++ cls.client = TestDependency.start()++ def testDependency(self):+ """+ Test dependency included+ """++ with self.assertRaises(NotImplementedError):+ self.client.get("search?query=test")