💡 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
Travis build script update
davidmezzetti6e03c5d878b2
diff --git a/.travis.yml b/.travis.ymlindex 2d5004aa..928371b9 100644--- a/.travis.yml+++ b/.travis.yml@@ -1,15 +1,13 @@# Travis CI build script - test on all supported platforms-language: python-os: linuxmatrix:include:+ - name: "Linux"+ os: linux+ language: python- name: "macOS"os: osxosx_image: xcode9.4language: shell- before_install:- - pip3 install -U pip- - python --version- name: "Windows"os: windowslanguage: shell@@ -17,9 +15,8 @@ matrix:- choco install python --version 3.6.8- python --version- python -m pip install --upgrade pip+ - python -m pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.htmlenv: PATH=/c/Python36:/c/Python36/Scripts:$PATH- script:- - pip install txtai -f https://download.pytorch.org/whl/torch_stable.htmlbefore_install:- pip install -U pip- python --versiondiff --git a/Makefile b/Makefilenew file mode 100644index 00000000..c30afd89--- /dev/null+++ b/Makefile@@ -0,0 +1,12 @@+# Project utility scripts+.PHONY: test++# Setup environment+export SRC_DIR := ./src/python+export TEST_DIR := ./test/python+export PYTHONPATH := ${SRC_DIR}:${TEST_DIR}:${PYTHONPATH}+export PATH := ${TEST_DIR}:${PATH}++# Unit tests+test:+ python -W ignore::DeprecationWarning -m unittest discover -v -s ${TEST_DIR}diff --git a/test/python/testann.py b/test/python/testann.pynew file mode 100644index 00000000..153ac006--- /dev/null+++ b/test/python/testann.py@@ -0,0 +1,23 @@+"""+Embeddings module tests+"""++import tempfile+import unittest++import numpy as np++from txtai.ann import ANN++class TestEmbeddings(unittest.TestCase):+ """+ Embeddings tests+ """++ def setUp(self):+ """+ Initialize test data.+ """++ # Generate random embeddings+ # np.random.rand(x, y)diff --git a/test/python/testembeddings.py b/test/python/testembeddings.pynew file mode 100644index 00000000..54eb380a--- /dev/null+++ b/test/python/testembeddings.py@@ -0,0 +1,73 @@+"""+Embeddings module tests+"""++import tempfile+import unittest++import numpy as np++from txtai.embeddings import Embeddings++class TestEmbeddings(unittest.TestCase):+ """+ Embeddings tests+ """++ def setUp(self):+ """+ Initialize test data.+ """++ self.data = ["US tops 5 million confirmed virus cases",+ "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",+ "Beijing mobilises invasion craft along coast as Taiwan tensions escalate",+ "The National Park Service warns against sacrificing slower friends in a bear attack",+ "Maine man wins $1M from $25 lottery ticket",+ "Make huge profits without work, earn up to $100,000 a day"]++ # Create embeddings model, backed by sentence-transformers & transformers+ self.embeddings = Embeddings({"method": "transformers",+ "path": "sentence-transformers/bert-base-nli-mean-tokens"})++ def testIndex(self):+ """+ Test embeddings.index+ """++ # Create an index for the list of sections+ self.embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])++ # Search for best match+ uid = self.embeddings.search("feel good story", 1)[0][0]++ self.assertEqual(self.data[uid], self.data[4])++ def testSave(self):+ """+ Test embeddings.save+ """++ # Create an index for the list of sections+ self.embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])++ with tempfile.NamedTemporaryFile(mode="wb") as output:+ index = output.name++ self.embeddings.save(index)+ self.embeddings.load(index)++ # Search for best match+ uid = self.embeddings.search("feel good story", 1)[0][0]++ self.assertEqual(self.data[uid], self.data[4])++ def testSimilarity(self):+ """+ Test embeddings.similarity+ """++ # Get best matching id+ uid = np.argmax(self.embeddings.similarity("feel good story", self.data))++ self.assertEqual(self.data[uid], self.data[4])diff --git a/test/python/testtokenizer.py b/test/python/testtokenizer.pynew file mode 100644index 00000000..82a509bd--- /dev/null+++ b/test/python/testtokenizer.py@@ -0,0 +1,21 @@+"""+Tokenizer module tests+"""++import unittest+++from txtai.tokenizer import Tokenizer++class TestTokenizer(unittest.TestCase):+ """+ Tokenizer tests+ """++ def testTokenize(self):+ """+ Test Tokenizer.tokenize+ """++ self.assertEqual(Tokenizer.tokenize("this is a test"), ["test"])+ self.assertEqual(Tokenizer.tokenize("abc123 abc 123"), ["abc123", "abc"])